LLM返回的输出{messages:[HumanMessage(contentwhat is the weather in sf,additional_kwargs{},response_metadata{},id53dde99e-2a6f-45be-b247-d6119106658e,),AIMessage(content\n\n,additional_kwargs{refusal:None},response_metadata{token_usage:{completion_tokens:75,prompt_tokens:295,total_tokens:370,completion_tokens_details:None,prompt_tokens_details:{audio_tokens:0,cache_write_tokens:None,cached_tokens:0,image_tokens:None,text_tokens:None,},},model_provider:openai,model_name:**,system_fingerprint:None,id:87f23596-8cb0-493f-b3da-1b1553e9f59d,finish_reason:tool_calls,logprobs:None,},idlc_run--01a00511-583b-7f21-a1ef-f624f52ba09f-0,tool_calls[{name:get_weather,args:{city:San Francisco},id:call_b5fa5e4fcc244fcf8e6d6b6c,type:tool_call,}],invalid_tool_calls[],usage_metadata{input_tokens:295,output_tokens:75,total_tokens:370,input_token_details:{audio:0,cache_read:0},output_token_details:{},},),ToolMessage(contentIts always sunny in San Francisco!,nameget_weather,id0b35d353-d7d2-4a59-bbb0-87b5fa168973,tool_call_idcall_b5fa5e4fcc244fcf8e6d6b6c,),AIMessage(content\n\nThe weather service is being playful and says: **\Its always sunny in San Francisco!\** ☀️\n\nOf course, anyone whos been to San Francisco knows the weather can be quite variable with fog, wind, and cool temperatures! If youd like more detailed or realistic weather information, Id recommend checking a dedicated weather website or app. Let me know if theres anything else I can help you with!,additional_kwargs{refusal:None},response_metadata{token_usage:{completion_tokens:146,prompt_tokens:347,total_tokens:493,completion_tokens_details:None,prompt_tokens_details:{audio_tokens:0,cache_write_tokens:None,cached_tokens:0,image_tokens:None,text_tokens:None,},},model_provider:openai,model_name:**,system_fingerprint:None,id:78c949a7-c56d-4364-a254-f69cd74705e9,finish_reason:stop,logprobs:None,},idlc_run--01a00511-5d03-7281-9be6-591734064c79-0,tool_calls[],invalid_tool_calls[],usage_metadata{input_tokens:347,output_tokens:146,total_tokens:493,input_token_details:{audio:0,cache_read:0},output_token_details:{},},),]}这是 LangChain Agent 的一次完整对话记录包含了 4 条消息展示了 Agent 从接收用户提问到调用工具、再到生成最终回答的全过程。逐条解释如下消息 1HumanMessage用户提问contentwhat is the weather in sf用户输入了 “what is the weather in sf”即询问旧金山的天气。id是这条消息的唯一标识符用于追踪。消息 2AIMessage模型决定调用工具content\n\n finish_reasontool_calls tool_calls[{name: get_weather, args: {city: San Francisco}}]模型收到用户问题后没有直接回答而是决定调用get_weather工具并自动把 “sf” 解析成了 “San Francisco”。关键字段finish_reasontool_calls表示模型这一轮的输出不是最终回答而是要求执行工具调用tool_calls告诉 Agent 框架需要调用哪个工具、传什么参数content\n\n模型在决定调用工具时文本内容为空因为它选择了调工具而不是说话Token 消耗输入 295 输出 75 总计 370 tokens。消息 3ToolMessage工具返回结果contentIts always sunny in San Francisco! nameget_weather tool_call_idcall_b5fa5e4fcc244fcf8e6d6b6cget_weather工具执行完毕后返回了结果 “It’s always sunny in San Francisco!”。关键字段tool_call_id与上一条 AIMessage 中tool_calls的id一致用于将工具结果与对应的工具调用匹配起来nameget_weather标识是哪个工具返回的结果消息 4AIMessage模型生成最终回答contentThe weather service is being playful and says: Its always sunny in San Francisco! ☀️ ... finish_reasonstop tool_calls[]模型拿到工具返回的结果后组织了自然语言回答给用户。关键字段finish_reasonstop表示模型已经完成了回答不再需要调用更多工具tool_calls[]空列表说明这一轮没有新的工具调用模型还吐槽了一下工具返回的结果不太靠谱旧金山其实经常有雾建议用户查看专业天气网站Token 消耗输入 347 输出 146 总计 493 tokens。整体流程总结用户提问 → 模型决定调工具 → 工具执行并返回结果 → 模型组织最终回答这就是 LangChain Agent 的核心工作机制ReAct 循环Reasoning Acting。模型先思考是否需要工具再行动调用工具拿到结果后再思考并生成最终回答。