1️⃣ System Prompt(系统提示)
作用:
2️⃣ Tools / Functions Schema(工具或函数描述模块)
作用:
告诉模型当前可用的工具和如何调用
通常包含:
工具名称
工具用途描述(对模型而非用户)
参数名称、类型、含义(JSON Schema)
在LangGraph / LangChain智能体中,每次推理都需要注入,以便大模型调用合适工具。
3️⃣ Chat History(对话历史)
作用:
在LangChain/LangGraph中使用:MessagesPlaceholder(variable_name="chat_history")
来动态注入完整或摘要化的对话历史。
4️⃣ User Input(用户输入)
作用:
本次用户真实问题 / 指令
用于让大模型根据当前输入做推理
在提示词模板中通常占位为:{user_input}或使用:HumanMessagePromptTemplate.from_template(human_prompt)
5️⃣ Output Format Constraints(输出格式约束)
作用:
指定输出的格式结构,方便解析和自动处理。
可包含:
严格要求输出 JSON / Markdown
限制字段名、字段顺序
示例输出
在生成结构化数据、SQL、工单时非常关键,常结合StructuredOutputParser或ResponseSchema使用。
✅ 汇总结构(记忆示范)
【智能体提示词典型结构】1️⃣SystemPrompt-定义角色、风格、目标-限制行为2️⃣Tools/FunctionsSchema-工具名称、描述-JSONSchema参数定义3️⃣ChatHistory-注入多轮对话历史或摘要4️⃣UserInput-用户本轮输入5️⃣OutputFormatConstraints-明确格式要求-示例结果
✅ 在 LangGraph / LangChain 中如何组织?
fromlangchain.promptsimportChatPromptTemplate,SystemMessagePromptTemplate,HumanMessagePromptTemplate,MessagesPlaceholdersystem_prompt="你是一个项目智能工单生成智能体..."human_prompt="{user_input}"prompt=ChatPromptTemplate.from_messages([SystemMessagePromptTemplate.from_template(system_prompt),MessagesPlaceholder(variable_name="chat_history"),HumanMessagePromptTemplate.from_template(human_prompt)])并通过:
✅StructuredOutputParser确保输出结构
✅ 工具描述在 Agent 初始化时注入
实现完整提示词编排,让智能体稳定且可解析。
✅ 是否需要全部模块?
不同场景可裁剪: