请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

使用langgraph的create_rect_agent创建的智能体怎么绑定提示词

用langgraph创建的智能体怎么绑定提示词
chat_prompt_template = ChatPromptTemplate.from_messages([
(‘system’, ‘’’
- 你是一个数学方面的专家,擅长使用工具解决各种数学计算问题
- 只要是数学计算问题,必须全部使用工具完成计算
- 如果是综合算式需要你先进行按照计算优先级的规则进行拆分一步一步的使用工具完成计算
’’’),
(‘human’, ‘{question}’)
])
#创建智能体
agent = create_react_agent(
model=llm,
tools=tools,
checkpointer=memory,
debug=False
)
chain=chat_prompt_template|agent
如上使用流式方式绑定了提示词但是后面在使用chain.invoke的方法的时候怎么把question传递进去

正在回答 回答被采纳积分+3

1回答

Sam 2025-07-11 20:31:31

需要在调用 invoke 方法时传入 input 参数,完整源码如下:

chat_prompt_template = ChatPromptTemplate.from_messages([
('system', '''
- 你是一个数学方面的专家,擅长使用工具解决各种数学计算问题
- 只要是数学计算问题,必须全部使用工具完成计算
- 如果是综合算式需要你先进行按照计算优先级的规则进行拆分一步一步的使用工具完成计算
'''),
('human', '{question}')
])

tools = file_tools
memory = MemorySaver()

#创建智能体
agent = create_react_agent(
    model=llm_qwen,
    tools=tools,
    checkpointer=memory,
    debug=False
)

chain = chat_prompt_template | agent

config = RunnableConfig(configurable={"thread_id": 1})
res = chain.invoke(input={"question": "100*100=?"}, config=config)
print(res)

关键方法是:

res = chain.invoke(input={"question": "100*100=?"}, config=config)


0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号