大模型AI Agent开发框架LangChain1.0
LangChain 在 1.0 版本中,将所有 Agent 的创建方式统一为了一个入口——create_agent()。它取代了旧版本中的 create_react_agent、create_json_agent、create_tool_calling_agent 等多种分支函数,真正让开发者用一行代码即可创建任何类型的智能体。在 LangChain 0.x 时代,框架内的 Agent 系统经历了
更多大模型课程资料,打开文章第一行:
LangChain1.0基本使用方法与LangChain很类似,最大的变化就是推出了全新的Agent API:create_agent。至此,LangChain Agent就已经不再是早期那种“带点魔法味的模型调用器”,它正式被定义为:一个可感知上下文、具备行动能力、可扩展、可插拔的智能运行体(Intelligent Runtime Unit)。简单来说,Agent 不再只是“用大模型回答问题”,而是能根据任务动态调用工具、推理决策、规划步骤,并与外部世界进行交互的 自治式执行体。
1、agent框架介绍
LangChain 在 1.0 版本中,将所有 Agent 的创建方式统一为了一个入口——create_agent()。它取代了旧版本中的 create_react_agent、create_json_agent、create_tool_calling_agent 等多种分支函数,真正让开发者用一行代码即可创建任何类型的智能体。 在 LangChain 0.x 时代,框架内的 Agent 系统经历了“碎片化”阶段。当时的设计理念是 “针对场景设计特定 Agent”——如果你要实现思维链推理(ReAct),就用 create_react_agent;如果需要结构化输出,就用 create_structured_chat_agent;要工具调用,则用 create_tool_calling_agent。这种方式灵活,但也带来了三个明显问题:
-
心智负担高——每种 Agent 都要单独记忆 API 与参数;
-
可组合性差——多个 Agent 之间无法统一调度;
-
生态碎片化——不同模块难以复用或协同演化。
而进入 LangChain 1.0 后,团队做出了彻底重构:将所有 Agent 的创建入口合并为 create_agent(),同时在底层通过“中间件机制(Middleware)”和“标准模型接口(invoke / stream)”实现全局统一。这让框架更轻、更稳,也更易于被集成到其他 Agent 平台中。
从底层架构来看,从 LangChain 1.0 开始,官方对框架的整体架构进行了根本性的角色重置:LangGraph 被正式确立为 LangChain 的底层运行框架(Runtime Foundation),而非附属扩展。在 0.x 时代,LangGraph 还被视作 LangChain 的“高层封装”——它是开发者在 LangChain 基础上进一步实现复杂 Agent 编排、状态流转与多节点控制的可选工具;换言之,那时 LangChain 是核心、LangGraph 是外挂。而进入 1.0 之后,情况彻底反转:LangGraph 被下沉为 LangChain 的底层执行引擎,一切新的高级 API(包括统一的 create_agent()、中间件系统、状态管理机制、流式回调与事件调度等)都直接运行在 LangGraph 架构之上。这样一来,LangChain 不再只是一个“Prompt 组织与调用库”,而是一个基于图结构的智能体运行时系统:每个 Agent 的生命周期、每次模型调用、每个工具执行,都是图中一个节点或边的执行过程。LangGraph 提供了稳定的调度、状态传递与事件流控制,而 LangChain 则提供了上层接口与开发体验。也就是说,上述Agent的实际运行逻辑,如果用LangGraph的语言来描述就是:

这种统一架构并以LangGraph为底层框架带来的优势如下:
-
接口统一,降低心智负担
-
无论是工具型、规划型还是对话型 Agent,都用同一个入口创建。
-
开发者不再需要区分不同 Agent 的实现逻辑。
-
-
跨生态兼容性增强
-
LangChain 1.0 的 Agent 架构与 LangGraph、LangServe、甚至 OpenAI Responses API 都完全兼容。
-
这意味着同一个 Agent 可以同时运行在命令行、Web UI、LangGraph 节点或云端推理环境中。
-
-
中间件机制的加入
-
新版本允许通过装饰器或中间件在 Agent 生命周期中插入逻辑: 如日志、速率限制、记忆压缩、PII 审查、内容重写等。
-
这使得 Agent 更像一个“微型操作系统进程”,具备可观察性与可管理性,后续会重点讲。
-
-
可扩展性与定制性更强
-
统一 API 底层基于标准化状态流(State Graph),这意味着用户可以自由地扩展 Agent 行为而不破坏核心逻辑。
-
而从官方的角度进行解释,LangChain 1.0中的Agent系统是一个Agent Runtime框架。在计算机领域中,Runtime 通常指的是一段代码运行所依赖的执行环境,它负责管理:
-
程序的生命周期(从初始化 → 执行 → 结束);
-
内部状态的维护;
-
与外部资源的交互(输入、输出、网络、文件等);
-
异常处理、事件调度、中断恢复等底层细节。
而Agent Runtime 框架 = 让智能体能够持续运行、思考、决策、调用工具、保持状态的底层执行系统。它不是一个“函数库”,而是一整套管理 Agent 生命周期与执行流程的框架。当然其中主要得益于LangChain 1.0 Agent框架继承了此前LangGraph的全套开发框架、并在此基础上增加了中间件Middleware,使得Agent开发和运行过程更加可控。
2、create_agent API模型接入方法
在 LangChain 1.0 中,Agent(智能体) 不再只是调用模型的脚本,而是一个能理解任务、推理路径、调用工具并自主完成目标的系统。每个 Agent 都包含一个循环结构(Agent Loop):模型会根据当前输入进行推理,决定是否调用工具、如何解析观察结果,并不断迭代,直到满足“停止条件”(Stop Condition),也就是模型生成最终答案,或达到设定的迭代次数上限。 LangChain 1.0 提供了全新的 create_agent() 接口,这是一个 可用于生产环境的标准化智能体构造函数。通过它,你可以用极简的方式创建一个完整的、可运行的智能体系统。create_agent 会在内部使用 LangGraph 构建一个基于图结构的 Agent Runtime,它以节点(Node)和边(Edge)的形式定义整个推理流程:
-
节点(Node):代表执行步骤,例如模型调用节点、工具执行节点或中间件节点;
-
边(Edge):代表执行流程与状态流转;
-
图(Graph):定义了 Agent 如何在这些节点之间流动、推理和决策。
换而言之,LangChain 的每个 Agent 都是一张有向图,语言模型是推理引擎,工具是行动节点,而底层则是通过LangGrph进行的编写和实现。

在 create_agent() 的底层运行机制中,最重要的三个组件分别是:
-
模型(Model) 模型是 Agent 的“大脑”,负责理解任务与决策推理。它既可以是静态模型(固定不变),也可以是动态模型(根据上下文切换)。
-
工具(Tools) 工具是 Agent 的“手脚”。模型可以选择调用不同工具来实现特定子任务,例如:
-
web_search() → 进行联网搜索
-
calculate() → 计算公式
-
database_query() → 查询数据源
-
-
中间件(Middleware) 中间件类似于“神经系统”,它可以在模型调用前后拦截请求、修改参数、或动态调整模型选择逻辑,是 LangChain 1.0 的强大扩展机制。
3、create_agent接入内置工具与Agent创建流程
当然,只有接入了一些工具,才能使用create_agent完成Agent创建(如果只是进行模型调用,可以采用上一小节介绍的model.invoke进行调用)。 这里我们首先介绍一个最基本的LangChain接入工具流程——接入LangChain内置的工具集。其实在MCP爆火之前,LangChian生态中就已经内置集成了非常多的实用工具,开发者可以快速调用这些工具完成更加复杂工作流的开发。
ounter(lineounter(lineounter(lineounter(lineimport langchainlangchain.__version__'1.0.5'
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line# 1.导入相关库from langchain.agents import create_agentfrom langchain_deepseek import ChatDeepSeekfrom langchain_community.tools.tavily_search import TavilySearchResults# 2.导入模型和工具web_search = TavilySearchResults(max_results=2)model = ChatDeepSeek(model="deepseek-chat")# 3.创建Agentagent = create_agent(model=model,tools=[web_search],system_prompt="你是一个智能助手,可以自己根据用户的问题来调用响应的工具帮助用户解决问题。")
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(line# 4.运行Agent获得结果result = agent.invoke({"messages": [{"role": "user", "content": "请帮我查询LangChain1.0发布的时间和主要功能更新?"}]})result
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line{'messages': [HumanMessage(content='请帮我查询LangChain1.0发布的时间和主要功能更新?', additional_kwargs={}, response_metadata={}, id='106bb7ef-f5ad-44ff-a436-77e1fb2fc696'),AIMessage(content='我来帮您查询LangChain 1.0的发布信息和主要功能更新。', additional_kwargs={'tool_calls': [{'id': 'call_00_8FVcBn05hN5eLqgItQJUd4xR', 'function': {'arguments': '{"query": "LangChain 1.0 release date time major features updates"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 45, 'prompt_tokens': 216, 'total_tokens': 261, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 0}, 'prompt_cache_hit_tokens': 0, 'prompt_cache_miss_tokens': 216}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': 'e499e3b4-948d-486f-bb99-80d3536cf86d', 'service_tier': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='lc_run--53efaad9-5dc8-499e-92ba-5f8329332d68-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'LangChain 1.0 release date time major features updates'}, 'id': 'call_00_8FVcBn05hN5eLqgItQJUd4xR', 'type': 'tool_call'}], usage_metadata={'input_tokens': 216, 'output_tokens': 45, 'total_tokens': 261, 'input_token_details': {'cache_read': 0}, 'output_token_details': {}}),ToolMessage(content='[{"title": "LangChain - Changelog", "url": "https://changelog.langchain.com/", "content": "generally available ---------------------------------------- LangGraph 1.0 is the first stable major release in the durable agent framework space —a major milestone for production-ready AI systems. After more than a... October 22, 2025LangChain LangChain 1.0 now generally available ------------------------------------- LangChain 1.0 is our first major stable release, marking our commitment to no breaking changes until 2.0. After three years of feedback, we\'ve streamlined... October 22,", "score": 0.7511561}, {"title": "LangChain and LangGraph 1.0 alpha released, stable 1.0 in October", "url": "https://www.linkedin.com/posts/jovannjegic_langchain-langgraph-10-alpha-released-activity-7368973420585263104-DB8J", "content": "reactions show positive feedback on GitHub & forum, with first bug reports already coming in — showing the alpha is actively tested in real use cases. 📅 Stable 1.0 release expected late October 2025. [...] 🚀 LangChain & LangGraph 1.0 alpha released The LangChain team just announced alpha versions of v1.0 for both LangChain and LangGraph (Python + JS). LangChain is no longer “just chains,” but a platform centered on production-ready agents. What’s new: - LangGraph 1.0alpha → stable, no breaking changes. - LangChain 1.0alpha → big shift to a central agent abstraction (create_agent) on top of LangGraph. - New content blocks for message formats. - New unified docs site (Python & JS). 🗣️ Community [...] v0.1.1 is out! 🚀 Keyword search across both logs and metadata, now supported on Python and TypeScript. Improved explainability UI for AI-powered root cause analysis. Polished tutorials & docs, better organized and easier to follow in our main repo. Huge thanks to the new contributors who jumped in and made this possible! 🙌\\n\\n Image 30: No alternative text description for this image\\n\\nImage 31Image 32Image 33 523 Comments\\n\\nLikeComment", "score": 0.6816637}]', name='tavily_search_results_json', id='366d179d-09ce-4b4c-b836-9bc6b365ff74', tool_call_id='call_00_8FVcBn05hN5eLqgItQJUd4xR', artifact={'query': 'LangChain 1.0 release date time major features updates', 'follow_up_questions': None, 'answer': None, 'images': [], 'results': [{'url': 'https://changelog.langchain.com/', 'title': 'LangChain - Changelog', 'content': "generally available ---------------------------------------- LangGraph 1.0 is the first stable major release in the durable agent framework space —a major milestone for production-ready AI systems. After more than a... October 22, 2025LangChain LangChain 1.0 now generally available ------------------------------------- LangChain 1.0 is our first major stable release, marking our commitment to no breaking changes until 2.0. After three years of feedback, we've streamlined... October 22,", 'score': 0.7511561, 'raw_content': None}, {'url': 'https://www.linkedin.com/posts/jovannjegic_langchain-langgraph-10-alpha-released-activity-7368973420585263104-DB8J', 'title': 'LangChain and LangGraph 1.0 alpha released, stable 1.0 in October', 'content': 'reactions show positive feedback on GitHub & forum, with first bug reports already coming in — showing the alpha is actively tested in real use cases. 📅 Stable 1.0 release expected late October 2025. [...] 🚀 LangChain & LangGraph 1.0 alpha released The LangChain team just announced alpha versions of v1.0 for both LangChain and LangGraph (Python + JS). LangChain is no longer “just chains,” but a platform centered on production-ready agents. What’s new: - LangGraph 1.0alpha → stable, no breaking changes. - LangChain 1.0alpha → big shift to a central agent abstraction (create_agent) on top of LangGraph. - New content blocks for message formats. - New unified docs site (Python & JS). 🗣️ Community [...] v0.1.1 is out! 🚀 Keyword search across both logs and metadata, now supported on Python and TypeScript. Improved explainability UI for AI-powered root cause analysis. Polished tutorials & docs, better organized and easier to follow in our main repo. Huge thanks to the new contributors who jumped in and made this possible! 🙌\n\n Image 30: No alternative text description for this image\n\nImage 31Image 32Image 33 523 Comments\n\nLikeComment', 'score': 0.6816637, 'raw_content': None}], 'response_time': 1.4, 'request_id': '27bbfd87-5481-4401-b17c-e67e91659909'}),AIMessage(content='让我再搜索更详细的LangChain 1.0功能更新信息:', additional_kwargs={'tool_calls': [{'id': 'call_00_48Imte18xOAAD1us9EUpULIY', 'function': {'arguments': '{"query": "LangChain 1.0 features updates what\'s new agent abstraction"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 44, 'prompt_tokens': 765, 'total_tokens': 809, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 256}, 'prompt_cache_hit_tokens': 256, 'prompt_cache_miss_tokens': 509}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': '2b9029da-063f-4c52-a497-0dc2bc310e87', 'service_tier': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='lc_run--66e9eb6f-48b2-4749-bbd2-5bf0b2bc58c4-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': "LangChain 1.0 features updates what's new agent abstraction"}, 'id': 'call_00_48Imte18xOAAD1us9EUpULIY', 'type': 'tool_call'}], usage_metadata={'input_tokens': 765, 'output_tokens': 44, 'total_tokens': 809, 'input_token_details': {'cache_read': 256}, 'output_token_details': {}}),ToolMessage(content='[{"title": "Introducing LangChain 1.0 Middleware: A New Agent Abstraction", "url": "https://www.linkedin.com/posts/christian-bromann_thrilled-to-share-my-first-big-contribution-activity-7371225886790098945-ydGI", "content": "ð\x9f\x98¬ Thrilled to share my first big contribution since joining LangChain a month ago ð\x9f\x8e\x89 For nearly 3 years, LangChain has had agent abstractions \x80\x94 and in that time, probably over 100+ other frameworks have emerged with similar ideas. But they\x80\x99ve all faced the same problem: as soon as developers need serious control over context engineering, the abstraction breaks down. With LangChain 1.0, we\x80\x99re tackling this head-on by introducing a new agent abstraction: Middleware. Middleware makes [...] ð\x9f\x9a\x80 We rewrote our deepagents package on top of the upcoming LangChain v1 release! Deepagents excel at agentic tasks by leveraging their planning, filesystem, and sub-task capabilities. We built these features with LangChain middleware (new in LangChain 1.0!), and as a result, deepagents are more extensible than ever before. Check out our technical deep-dive to learn exactly how this works: \\n\\n ### Rewriting Deep Agents on top of LangChain 1.0\\n\\n #### \\n\\n 353 4 Comments\\n\\n Like Comment [...] # Christian Bromann\x80\x99s Post\\n\\nChristian Bromann\\n\\nSoftware Engineer @LangChain | Cross Project Council Member at OpenJS Foundation | W3C AC Rep | WebdriverIO Core Maintainer | Open Source & Open Standards Advocate\\n\\n Report this post", "score": 0.87139857}, {"title": "What\'s new in v1 - Docs by LangChain", "url": "https://docs.langchain.com/oss/javascript/releases/langchain-v1", "content": "# What\'s new in v1\\n\\nLangChain v1 is a focused, production-ready foundation for building agents. We’ve streamlined the framework around three core improvements:\\n\\n## createAgent\\n\\nA new standard way to build agents in LangChain, replacing `createReactAgent` from LangGraph with a cleaner, more powerful API.## Standard content blocks\\n\\nA new `contentBlocks` property that provides unified access to modern LLM features across all providers.## Simplified package", "score": 0.7961819}]', name='tavily_search_results_json', id='733a79c1-73a4-41b4-adb3-fc870298bf31', tool_call_id='call_00_48Imte18xOAAD1us9EUpULIY', artifact={'query': "LangChain 1.0 features updates what's new agent abstraction", 'follow_up_questions': None, 'answer': None, 'images': [], 'results': [{'url': 'https://www.linkedin.com/posts/christian-bromann_thrilled-to-share-my-first-big-contribution-activity-7371225886790098945-ydGI', 'title': 'Introducing LangChain 1.0 Middleware: A New Agent Abstraction', 'content': 'ð\x9f\x98¬ Thrilled to share my first big contribution since joining LangChain a month ago ð\x9f\x8e\x89 For nearly 3 years, LangChain has had agent abstractions \x80\x94 and in that time, probably over 100+ other frameworks have emerged with similar ideas. But they\x80\x99ve all faced the same problem: as soon as developers need serious control over context engineering, the abstraction breaks down. With LangChain 1.0, we\x80\x99re tackling this head-on by introducing a new agent abstraction: Middleware. Middleware makes [...] ð\x9f\x9a\x80 We rewrote our deepagents package on top of the upcoming LangChain v1 release! Deepagents excel at agentic tasks by leveraging their planning, filesystem, and sub-task capabilities. We built these features with LangChain middleware (new in LangChain 1.0!), and as a result, deepagents are more extensible than ever before. Check out our technical deep-dive to learn exactly how this works: \n\n ### Rewriting Deep Agents on top of LangChain 1.0\n\n #### \n\n 353 4 Comments\n\n Like Comment [...] # Christian Bromann\x80\x99s Post\n\nChristian Bromann\n\nSoftware Engineer @LangChain | Cross Project Council Member at OpenJS Foundation | W3C AC Rep | WebdriverIO Core Maintainer | Open Source & Open Standards Advocate\n\n Report this post', 'score': 0.87139857, 'raw_content': None}, {'url': 'https://docs.langchain.com/oss/javascript/releases/langchain-v1', 'title': "What's new in v1 - Docs by LangChain", 'content': "# What's new in v1\n\nLangChain v1 is a focused, production-ready foundation for building agents. We’ve streamlined the framework around three core improvements:\n\n## createAgent\n\nA new standard way to build agents in LangChain, replacing `createReactAgent` from LangGraph with a cleaner, more powerful API.## Standard content blocks\n\nA new `contentBlocks` property that provides unified access to modern LLM features across all providers.## Simplified package", 'score': 0.7961819, 'raw_content': None}], 'response_time': 1.16, 'request_id': 'a65caba1-b60c-49e4-b3f2-a39b10a91763'}),AIMessage(content='让我再搜索一些更具体的发布时间信息:', additional_kwargs={'tool_calls': [{'id': 'call_00_9q4EaNDkA686fQyQDhmTmx5M', 'function': {'arguments': '{"query": "\\"LangChain 1.0\\" \\"October 2025\\" release date announcement"}', 'name': 'tavily_search_results_json'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 42, 'prompt_tokens': 1351, 'total_tokens': 1393, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 768}, 'prompt_cache_hit_tokens': 768, 'prompt_cache_miss_tokens': 583}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': '1fcfa3e2-d4fc-47a2-969e-6b5e49d72aaa', 'service_tier': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='lc_run--630b495f-f2b1-489a-a93e-f6281112a5ba-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': '"LangChain 1.0" "October 2025" release date announcement'}, 'id': 'call_00_9q4EaNDkA686fQyQDhmTmx5M', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1351, 'output_tokens': 42, 'total_tokens': 1393, 'input_token_details': {'cache_read': 768}, 'output_token_details': {}}),ToolMessage(content='[{"title": "LangChain and LangGraph 1.0 alpha released, stable 1.0 in October", "url": "https://www.linkedin.com/posts/jovannjegic_langchain-langgraph-10-alpha-released-activity-7368973420585263104-DB8J", "content": "reactions show positive feedback on GitHub & forum, with first bug reports already coming in — showing the alpha is actively tested in real use cases. 📅 Stable 1.0 release expected late October 2025. [...] 🚀 LangChain & LangGraph 1.0 alpha released The LangChain team just announced alpha versions of v1.0 for both LangChain and LangGraph (Python + JS). LangChain is no longer “just chains,” but a platform centered on production-ready agents. What’s new: - LangGraph 1.0alpha → stable, no breaking changes. - LangChain 1.0alpha → big shift to a central agent abstraction (create_agent) on top of LangGraph. - New content blocks for message formats. - New unified docs site (Python & JS). 🗣️ Community [...] [](", "score": 0.8443195}, {"title": "LangChain - Changelog", "url": "https://changelog.langchain.com/", "content": "generally available ---------------------------------------- LangGraph 1.0 is the first stable major release in the durable agent framework space —a major milestone for production-ready AI systems. After more than a... October 22, 2025LangChain LangChain 1.0 now generally available ------------------------------------- LangChain 1.0 is our first major stable release, marking our commitment to no breaking changes until 2.0. After three years of feedback, we\'ve streamlined... October 22, [...] improvements to evaluations: online multi-turn evaluations, composite feedback scores and JavaScript code evals. It also includes... October 23, 2025v0.12.7 LangSmith Evaluate end-to-end agent interactions with Multi-turn Evals ------------------------------------------------------------ Today, we\'re launching Multi-turn Evals to help you measure how your agent is performing across an entire end-to-end interaction. Multi-turn evals are online... October 23, 2025LangGraph LangGraph 1.0 is now [...] v0.9.15 v0.9.17 v0.9.23 v0.9.35 v0.9.71 v0.9.77 v0.9.83 v0.10.19 v0.10.38 v0.10.63 v0.10.69 v0.10.79 v0.10.90 v0.10.92 v0.10.111 v0.10.122 v0.11.31 v0.11.51 v0.11.79 v0.12.7\\n\\nRSS Feed Subscribe to all categories\\n\\nPowered by LaunchNotes\\n\\nLoading...\\n\\nLoading...\\n\\n October 2025", "score": 0.8190992}]', name='tavily_search_results_json', id='5af28669-70b5-4bb4-bd67-5aacda1a7f5c', tool_call_id='call_00_9q4EaNDkA686fQyQDhmTmx5M', artifact={'query': '"LangChain 1.0" "October 2025" release date announcement', 'follow_up_questions': None, 'answer': None, 'images': [], 'results': [{'url': 'https://www.linkedin.com/posts/jovannjegic_langchain-langgraph-10-alpha-released-activity-7368973420585263104-DB8J', 'title': 'LangChain and LangGraph 1.0 alpha released, stable 1.0 in October', 'content': 'reactions show positive feedback on GitHub & forum, with first bug reports already coming in — showing the alpha is actively tested in real use cases. 📅 Stable 1.0 release expected late October 2025. [...] 🚀 LangChain & LangGraph 1.0 alpha released The LangChain team just announced alpha versions of v1.0 for both LangChain and LangGraph (Python + JS). LangChain is no longer “just chains,” but a platform centered on production-ready agents. What’s new: - LangGraph 1.0alpha → stable, no breaking changes. - LangChain 1.0alpha → big shift to a central agent abstraction (create_agent) on top of LangGraph. - New content blocks for message formats. - New unified docs site (Python & JS). 🗣️ Community [...] [](', 'score': 0.8443195, 'raw_content': None}, {'url': 'https://changelog.langchain.com/', 'title': 'LangChain - Changelog', 'content': "generally available ---------------------------------------- LangGraph 1.0 is the first stable major release in the durable agent framework space —a major milestone for production-ready AI systems. After more than a... October 22, 2025LangChain LangChain 1.0 now generally available ------------------------------------- LangChain 1.0 is our first major stable release, marking our commitment to no breaking changes until 2.0. After three years of feedback, we've streamlined... October 22, [...] improvements to evaluations: online multi-turn evaluations, composite feedback scores and JavaScript code evals. It also includes... October 23, 2025v0.12.7 LangSmith Evaluate end-to-end agent interactions with Multi-turn Evals ------------------------------------------------------------ Today, we're launching Multi-turn Evals to help you measure how your agent is performing across an entire end-to-end interaction. Multi-turn evals are online... October 23, 2025LangGraph LangGraph 1.0 is now [...] v0.9.15 v0.9.17 v0.9.23 v0.9.35 v0.9.71 v0.9.77 v0.9.83 v0.10.19 v0.10.38 v0.10.63 v0.10.69 v0.10.79 v0.10.90 v0.10.92 v0.10.111 v0.10.122 v0.11.31 v0.11.51 v0.11.79 v0.12.7\n\nRSS Feed Subscribe to all categories\n\nPowered by LaunchNotes\n\nLoading...\n\nLoading...\n\n October 2025", 'score': 0.8190992, 'raw_content': None}], 'response_time': 1.26, 'request_id': '624cda25-612a-46cf-9295-a79e2683567d'}),AIMessage(content='根据搜索结果,我为您整理了LangChain 1.0的发布信息:\n\n## LangChain 1.0 发布时间\n\n**发布日期:2025年10月22日**\n\n这是LangChain的第一个稳定主要版本,标志着该框架从"实验性"向"生产就绪"的重要转变。\n\n## 主要功能更新\n\n### 1. **新的代理抽象 - createAgent**\n- 引入了新的标准方式来构建LangChain代理\n- 取代了LangGraph中的`createReactAgent`\n- 提供更简洁、更强大的API\n\n### 2. **中间件系统 (Middleware)**\n- 全新的代理抽象层\n- 解决了上下文工程控制的问题\n- 使开发者能够更好地控制代理行为\n\n### 3. **标准内容块 (Standard Content Blocks)**\n- 新的`contentBlocks`属性\n- 为所有提供商提供统一的现代LLM功能访问\n- 改进了消息格式处理\n\n### 4. **简化的包结构**\n- 更简洁的框架组织\n- 围绕三个核心改进进行优化\n\n### 5. **生产就绪承诺**\n- 承诺在2.0版本之前不会有破坏性变更\n- 基于三年社区反馈的优化\n- 专注于构建生产就绪的代理系统\n\n### 6. **与LangGraph的深度集成**\n- LangChain不再仅仅是"链",而是以生产就绪代理为中心的平台\n- 在LangGraph之上构建中央代理抽象\n\n这个1.0版本的发布标志着LangChain从一个实验性框架向企业级生产就绪平台的重大转变。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 328, 'prompt_tokens': 2045, 'total_tokens': 2373, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 1344}, 'prompt_cache_hit_tokens': 1344, 'prompt_cache_miss_tokens': 701}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': '0a3f8738-462c-4104-a79d-0fb8b6fe0928', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='lc_run--c79d3cf8-4443-4609-9ad2-73f37e2a1966-0', usage_metadata={'input_tokens': 2045, 'output_tokens': 328, 'total_tokens': 2373, 'input_token_details': {'cache_read': 1344}, 'output_token_details': {}})]}
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineprint(result['messages'][-1].content)根据搜索结果,我为您整理了LangChain 1.0的发布信息:## LangChain 1.0 发布时间**发布日期:2025年10月22日**这是LangChain的第一个稳定主要版本,标志着该框架从"实验性"向"生产就绪"的重要转变。## 主要功能更新### 1. **新的代理抽象 - createAgent**- 引入了新的标准方式来构建LangChain代理- 取代了LangGraph中的`createReactAgent`- 提供更简洁、更强大的API### 2. **中间件系统 (Middleware)**- 全新的代理抽象层- 解决了上下文工程控制的问题- 使开发者能够更好地控制代理行为### 3. **标准内容块 (Standard Content Blocks)**- 新的`contentBlocks`属性- 为所有提供商提供统一的现代LLM功能访问- 改进了消息格式处理### 4. **简化的包结构**- 更简洁的框架组织- 围绕三个核心改进进行优化### 5. **生产就绪承诺**- 承诺在2.0版本之前不会有破坏性变更- 基于三年社区反馈的优化- 专注于构建生产就绪的代理系统### 6. **与LangGraph的深度集成**- LangChain不再仅仅是"链",而是以生产就绪代理为中心的平台- 在LangGraph之上构建中央代理抽象这个1.0版本的发布标志着LangChain从一个实验性框架向企业级生产就绪平台的重大转变。
ounter(lineounter(lineounter(linelen(result['messages'])8
4、 自定义工具
注意:这里提到的内置工具和自定义工具的详细内容可参考之前的LangChain文章,创建过程是一致的,就不在这里细讲
ounter(lineounter(lineounter(lineimport requests,jsonOPENWEATHER_API_KEY = os.getenv("OPENWEATHER_API_KEY")
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(linefrom langchain.tools import tool@tooldef get_weather(loc):"""查询即时天气函数:param loc: 必要参数,字符串类型,用于表示查询天气的具体城市名称,\注意,中国的城市需要用对应城市的英文名称代替,例如如果需要查询北京市天气,则loc参数需要输入'Beijing';:return:OpenWeather API查询即时天气的结果,具体URL请求地址为:https://api.openweathermap.org/data/2.5/weather\返回结果对象类型为解析之后的JSON格式对象,并用字符串形式进行表示,其中包含了全部重要的天气信息"""# Step 1.构建请求url = "https://api.openweathermap.org/data/2.5/weather"# Step 2.设置查询参数params = {"q": loc,"appid": os.getenv("OPENWEATHER_API_KEY"), # 输入API key"units": "metric", # 使用摄氏度而不是华氏度"lang":"zh_cn" # 输出语言为简体中文}# Step 3.发送GET请求response = requests.get(url, params=params)# Step 4.解析响应data = response.json()return json.dumps(data)
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line# 创建Agentagent = create_agent(model=model,tools=[get_weather,web_search],system_prompt="你是一个智能助手,可以自己根据用户的问题来调用响应的工具帮助用户解决问题。")
ounter(lineounter(lineounter(lineounter(lineounter(line# 运行Agent获得结果result = agent.invoke({"messages": [{"role": "user", "content": "请问北京今天天气如何?"}]})result['messages']
ounter(lineounter(lineounter(lineounter(line在这里插入代码片[HumanMessage(content='请问北京今天天气如何?', additional_kwargs={}, response_metadata={}, id='9cc63ff0-ca84-49a8-95df-dab59d222b97'),AIMessage(content='我来帮您查询北京今天的天气情况。', additional_kwargs={'tool_calls': [{'id': 'call_00_twh0fgtW9zWRXA0YtLmqFawi', 'function': {'arguments': '{"loc": "Beijing"}', 'name': 'get_weather'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 23, 'prompt_tokens': 346, 'total_tokens': 369, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 320}, 'prompt_cache_hit_tokens': 320, 'prompt_cache_miss_tokens': 26}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': 'db69fe9d-31f5-4484-ad62-793236c37296', 'service_tier': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='lc_run--6c1102ec-b1e2-4a69-8ee0-ecbff5dbb5d1-0', tool_calls=[{'name': 'get_weather', 'args': {'loc': 'Beijing'}, 'id': 'call_00_twh0fgtW9zWRXA0YtLmqFawi', 'type': 'tool_call'}], usage_metadata={'input_tokens': 346, 'output_tokens': 23, 'total_tokens': 369, 'input_token_details': {'cache_read': 320}, 'output_token_details': {}}),ToolMessage(content='{"coord": {"lon": 116.3972, "lat": 39.9075}, "weather": [{"id": 804, "main": "Clouds", "description": "\\u9634\\uff0c\\u591a\\u4e91", "icon": "04d"}], "base": "stations", "main": {"temp": 14.94, "feels_like": 13.17, "temp_min": 14.94, "temp_max": 14.94, "pressure": 1019, "humidity": 26, "sea_level": 1019, "grnd_level": 1014}, "visibility": 10000, "wind": {"speed": 2.31, "deg": 210, "gust": 3.25}, "clouds": {"all": 100}, "dt": 1762759404, "sys": {"type": 1, "id": 9609, "country": "CN", "sunrise": 1762728798, "sunset": 1762765404}, "timezone": 28800, "id": 1816670, "name": "Beijing", "cod": 200}', name='get_weather', id='60a16179-9f0b-43e0-8b98-32e8edd39649', tool_call_id='call_00_twh0fgtW9zWRXA0YtLmqFawi'),AIMessage(content='根据查询结果,北京今天的天气情况如下:\n\n**天气状况**:阴,多云\n**温度**:14.94°C\n**体感温度**:13.17°C\n**湿度**:26%\n**气压**:1019 hPa\n**风速**:2.31 m/s\n**能见度**:10公里\n\n总体来说,今天北京天气阴凉,温度适中但湿度较低,风力较小。建议您根据这个温度适当穿着,由于湿度较低,可能需要注意保湿。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 107, 'prompt_tokens': 635, 'total_tokens': 742, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 576}, 'prompt_cache_hit_tokens': 576, 'prompt_cache_miss_tokens': 59}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': '96b89274-0b77-4144-b596-4411f79c9284', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='lc_run--6046843a-3866-45c2-8595-9c2c428a9728-0', usage_metadata={'input_tokens': 635, 'output_tokens': 107, 'total_tokens': 742, 'input_token_details': {'cache_read': 576}, 'output_token_details': {}})]
ounter(lineounter(lineounter(lineresult['messages'][-1].content'根据查询结果,北京今天的天气情况如下:\n\n**天气状况**:阴,多云\n**温度**:14.94°C\n**体感温度**:13.17°C\n**湿度**:26%\n**气压**:1019 hPa\n**风速**:2.31 m/s\n**能见度**:10公里\n\n总体来说,今天北京天气阴凉,温度适中但湿度较低,风力较小。建议您根据这个温度适当穿着,由于湿度较低,可能需要注意保湿。'
多次查询ounter(lineounter(lineounter(lineounter(lineounter(line
result = agent.invoke({"messages": [{"role": "user", "content": "请问今天杭州和上海哪里更冷?"}]})result['messages']
ounter(lineounter(lineounter(lineounter(lineounter(line[HumanMessage(content='请问今天杭州和上海哪里更冷?', additional_kwargs={}, response_metadata={}, id='24852e12-7689-4bc7-b4ee-48b4529d25d0'),AIMessage(content='我来帮您查询今天杭州和上海的天气情况,然后比较哪里更冷。', additional_kwargs={'tool_calls': [{'id': 'call_00_EDpuCMOWgamvBgDRFTaowYZg', 'function': {'arguments': '{"loc": "Hangzhou"}', 'name': 'get_weather'}, 'type': 'function', 'index': 0}, {'id': 'call_01_s5AkWatYf95zqFns01FuTu6e', 'function': {'arguments': '{"loc": "Shanghai"}', 'name': 'get_weather'}, 'type': 'function', 'index': 1}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 46, 'prompt_tokens': 349, 'total_tokens': 395, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 320}, 'prompt_cache_hit_tokens': 320, 'prompt_cache_miss_tokens': 29}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': '523976a8-3b45-4883-8f5a-37c52a917235', 'service_tier': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='lc_run--b32fe254-dfbe-49f3-a311-5a6080376d16-0', tool_calls=[{'name': 'get_weather', 'args': {'loc': 'Hangzhou'}, 'id': 'call_00_EDpuCMOWgamvBgDRFTaowYZg', 'type': 'tool_call'}, {'name': 'get_weather', 'args': {'loc': 'Shanghai'}, 'id': 'call_01_s5AkWatYf95zqFns01FuTu6e', 'type': 'tool_call'}], usage_metadata={'input_tokens': 349, 'output_tokens': 46, 'total_tokens': 395, 'input_token_details': {'cache_read': 320}, 'output_token_details': {}}),ToolMessage(content='{"coord": {"lon": 120.1614, "lat": 30.2937}, "weather": [{"id": 803, "main": "Clouds", "description": "\\u591a\\u4e91", "icon": "04d"}], "base": "stations", "main": {"temp": 18.95, "feels_like": 18.28, "temp_min": 18.95, "temp_max": 18.95, "pressure": 1019, "humidity": 53, "sea_level": 1019, "grnd_level": 1017}, "visibility": 10000, "wind": {"speed": 3.42, "deg": 91, "gust": 4.68}, "clouds": {"all": 74}, "dt": 1762759669, "sys": {"type": 1, "id": 9651, "country": "CN", "sunrise": 1762726837, "sunset": 1762765559}, "timezone": 28800, "id": 1808926, "name": "Hangzhou", "cod": 200}', name='get_weather', id='0a9e893d-864a-450d-be22-f65c74557f11', tool_call_id='call_00_EDpuCMOWgamvBgDRFTaowYZg'),ToolMessage(content='{"coord": {"lon": 121.4581, "lat": 31.2222}, "weather": [{"id": 800, "main": "Clear", "description": "\\u6674", "icon": "01d"}], "base": "stations", "main": {"temp": 17.92, "feels_like": 17.02, "temp_min": 17.92, "temp_max": 17.92, "pressure": 1020, "humidity": 48, "sea_level": 1020, "grnd_level": 1019}, "visibility": 10000, "wind": {"speed": 4, "deg": 60}, "clouds": {"all": 0}, "dt": 1762759654, "sys": {"type": 1, "id": 9659, "country": "CN", "sunrise": 1762726617, "sunset": 1762765156}, "timezone": 28800, "id": 1796236, "name": "Shanghai", "cod": 200}', name='get_weather', id='366b2f13-0196-4ab3-9170-bd16148c569d', tool_call_id='call_01_s5AkWatYf95zqFns01FuTu6e'),AIMessage(content='根据查询结果,我来为您比较今天杭州和上海的天气情况:\n\n**杭州天气:**\n- 温度:18.95°C\n- 体感温度:18.28°C\n- 天气状况:多云\n- 湿度:53%\n- 风速:3.42 m/s\n\n**上海天气:**\n- 温度:17.92°C\n- 体感温度:17.02°C\n- 天气状况:晴\n- 湿度:48%\n- 风速:4 m/s\n\n**比较结果:**\n今天**上海比杭州更冷**。上海的实际温度为17.92°C,体感温度为17.02°C;而杭州的实际温度为18.95°C,体感温度为18.28°C。上海的温度比杭州低了约1°C左右。\n\n虽然上海是晴天,杭州是多云天气,但上海的温度确实更低一些。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 191, 'prompt_tokens': 900, 'total_tokens': 1091, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 384}, 'prompt_cache_hit_tokens': 384, 'prompt_cache_miss_tokens': 516}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': '0d15b69d-fe3b-449d-a48f-8b4af447ce4a', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='lc_run--67d607fe-a0e8-4cf9-b36a-076b291ce65a-0', usage_metadata={'input_tokens': 900, 'output_tokens': 191, 'total_tokens': 1091, 'input_token_details': {'cache_read': 384}, 'output_token_details': {}})]
可以看到ToolMessage出现了两次
ounter(lineounter(lineounter(lineresult['messages'][-1].content'根据查询结果,我来为您比较今天杭州和上海的天气情况:\n\n**杭州天气:**\n- 温度:18.95°C\n- 体感温度:18.28°C\n- 天气状况:多云\n- 湿度:53%\n- 风速:3.42 m/s\n\n**上海天气:**\n- 温度:17.92°C\n- 体感温度:17.02°C\n- 天气状况:晴\n- 湿度:48%\n- 风速:4 m/s\n\n**比较结果:**\n今天**上海比杭州更冷**。上海的实际温度为17.92°C,体感温度为17.02°C;而杭州的实际温度为18.95°C,体感温度为18.28°C。上海的温度比杭州低了约1°C左右。\n\n虽然上海是晴天,杭州是多云天气,但上海的温度确实更低一些。'
5、多工具调用
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineimport os@tooldef write_to_markdown(content: str) -> str:"""将指定内容保存为 Markdown 格式的文件。:param content: 要保存的文本内容。:param filename: 保存的文件名,默认为 'output.md'。:return: 返回保存结果的消息。"""filename = "./output.md"try:# 确保文件名以 .md 结尾if not filename.endswith(".md"):filename += ".md"# 写入文件with open(filename, 'w', encoding='utf-8') as file:file.write(content)return f"内容已成功保存为 {filename} 文件。"except Exception as e:return f"保存文件时发生错误:{e}"
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(line# 创建Agentagent_3 = create_agent(model=model,tools=[get_weather,web_search,write_to_markdown],system_prompt="你是一个智能助手,可以自己根据用户的问题来调用响应的工具帮助用户解决问题。")
ounter(lineounter(lineounter(lineresult = agent_3.invoke({"messages": [{"role": "user", "content": "请帮我查询北京、杭州、上海等地天气,并写入本地文件。"}]})
ounter(lineounter(lineounter(lineresult['messages'][-1].content'已完成!我已经为您查询了北京、杭州、上海三地的天气信息,并将详细报告保存到了本地文件 `output.md` 中。\n\n**主要天气情况总结:**\n- **北京**:阴天多云,温度约15°C,较为凉爽\n- **杭州**:多云天气,温度约19°C,湿度较高\n- **上海**:晴朗天气,温度约18°C,风速稍大\n\n所有详细信息都已保存到Markdown文件中,包括温度、湿度、风速、气压等完整气象数据。'
ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineresult['messages'][HumanMessage(content='请帮我查询北京、杭州、上海等地天气,并写入本地文件。', additional_kwargs={}, response_metadata={}, id='a8427e85-929b-43b7-9a08-ccd81bdeb218'),AIMessage(content='我来帮您查询北京、杭州、上海的天气信息,并保存到本地文件中。', additional_kwargs={'tool_calls': [{'id': 'call_00_gZGAGpoLkorhpTV5Ph4hXGYd', 'function': {'arguments': '{"loc": "Beijing"}', 'name': 'get_weather'}, 'type': 'function', 'index': 0}, {'id': 'call_01_4tEtNLCeHyLG1PoXAzJqPPzK', 'function': {'arguments': '{"loc": "Hangzhou"}', 'name': 'get_weather'}, 'type': 'function', 'index': 1}, {'id': 'call_02_G810zBB3qWbRejpAfhx3afHt', 'function': {'arguments': '{"loc": "Shanghai"}', 'name': 'get_weather'}, 'type': 'function', 'index': 2}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 59, 'prompt_tokens': 441, 'total_tokens': 500, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 192}, 'prompt_cache_hit_tokens': 192, 'prompt_cache_miss_tokens': 249}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': 'f940de4d-5715-4bd6-b594-2674b287666f', 'service_tier': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='lc_run--f50a126c-9f96-4c1d-b04b-21a137f9d279-0', tool_calls=[{'name': 'get_weather', 'args': {'loc': 'Beijing'}, 'id': 'call_00_gZGAGpoLkorhpTV5Ph4hXGYd', 'type': 'tool_call'}, {'name': 'get_weather', 'args': {'loc': 'Hangzhou'}, 'id': 'call_01_4tEtNLCeHyLG1PoXAzJqPPzK', 'type': 'tool_call'}, {'name': 'get_weather', 'args': {'loc': 'Shanghai'}, 'id': 'call_02_G810zBB3qWbRejpAfhx3afHt', 'type': 'tool_call'}], usage_metadata={'input_tokens': 441, 'output_tokens': 59, 'total_tokens': 500, 'input_token_details': {'cache_read': 192}, 'output_token_details': {}}),ToolMessage(content='{"coord": {"lon": 116.3972, "lat": 39.9075}, "weather": [{"id": 804, "main": "Clouds", "description": "\\u9634\\uff0c\\u591a\\u4e91", "icon": "04d"}], "base": "stations", "main": {"temp": 14.94, "feels_like": 13.19, "temp_min": 14.94, "temp_max": 14.94, "pressure": 1019, "humidity": 27, "sea_level": 1019, "grnd_level": 1014}, "visibility": 10000, "wind": {"speed": 2.29, "deg": 210, "gust": 3.29}, "clouds": {"all": 100}, "dt": 1762760183, "sys": {"type": 1, "id": 9609, "country": "CN", "sunrise": 1762728798, "sunset": 1762765404}, "timezone": 28800, "id": 1816670, "name": "Beijing", "cod": 200}', name='get_weather', id='4494ce1c-8a74-4d5e-a81a-eec07f1be24f', tool_call_id='call_00_gZGAGpoLkorhpTV5Ph4hXGYd'),ToolMessage(content='{"coord": {"lon": 120.1614, "lat": 30.2937}, "weather": [{"id": 803, "main": "Clouds", "description": "\\u591a\\u4e91", "icon": "04d"}], "base": "stations", "main": {"temp": 18.95, "feels_like": 18.28, "temp_min": 18.95, "temp_max": 18.95, "pressure": 1019, "humidity": 53, "sea_level": 1019, "grnd_level": 1017}, "visibility": 10000, "wind": {"speed": 3.42, "deg": 91, "gust": 4.68}, "clouds": {"all": 74}, "dt": 1762759669, "sys": {"type": 1, "id": 9651, "country": "CN", "sunrise": 1762726837, "sunset": 1762765559}, "timezone": 28800, "id": 1808926, "name": "Hangzhou", "cod": 200}', name='get_weather', id='4c1d9eb9-15b7-4ab5-bb2b-2e9c5a731303', tool_call_id='call_01_4tEtNLCeHyLG1PoXAzJqPPzK'),ToolMessage(content='{"coord": {"lon": 121.4581, "lat": 31.2222}, "weather": [{"id": 800, "main": "Clear", "description": "\\u6674", "icon": "01d"}], "base": "stations", "main": {"temp": 17.92, "feels_like": 17.02, "temp_min": 17.92, "temp_max": 17.92, "pressure": 1020, "humidity": 48, "sea_level": 1020, "grnd_level": 1019}, "visibility": 10000, "wind": {"speed": 4, "deg": 60}, "clouds": {"all": 0}, "dt": 1762759654, "sys": {"type": 1, "id": 9659, "country": "CN", "sunrise": 1762726617, "sunset": 1762765156}, "timezone": 28800, "id": 1796236, "name": "Shanghai", "cod": 200}', name='get_weather', id='3f3d872e-7ee3-4d65-afb5-fe424aee2543', tool_call_id='call_02_G810zBB3qWbRejpAfhx3afHt'),AIMessage(content='现在我将这些天气信息整理成Markdown格式并保存到本地文件:', additional_kwargs={'tool_calls': [{'id': 'call_00_BjTQ6PN1XwKlCI2yplD2yrQK', 'function': {'arguments': '{"content": "# \\u4e09\\u57ce\\u5929\\u6c14\\u62a5\\u544a\\n\\n## \\u5317\\u4eac\\n- **\\u5929\\u6c14\\u72b6\\u51b5**\\uff1a\\u9634\\uff0c\\u591a\\u4e91\\n- **\\u6e29\\u5ea6**\\uff1a14.94\\u00b0C\\n- **\\u4f53\\u611f\\u6e29\\u5ea6**\\uff1a13.19\\u00b0C\\n- **\\u6e7f\\u5ea6**\\uff1a27%\\n- **\\u6c14\\u538b**\\uff1a1019 hPa\\n- **\\u98ce\\u901f**\\uff1a2.29 m/s\\n- **\\u80fd\\u89c1\\u5ea6**\\uff1a10000\\u7c73\\n\\n## \\u676d\\u5dde\\n- **\\u5929\\u6c14\\u72b6\\u51b5**\\uff1a\\u591a\\u4e91\\n- **\\u6e29\\u5ea6**\\uff1a18.95\\u00b0C\\n- **\\u4f53\\u611f\\u6e29\\u5ea6**\\uff1a18.28\\u00b0C\\n- **\\u6e7f\\u5ea6**\\uff1a53%\\n- **\\u6c14\\u538b**\\uff1a1019 hPa\\n- **\\u98ce\\u901f**\\uff1a3.42 m/s\\n- **\\u80fd\\u89c1\\u5ea6**\\uff1a10000\\u7c73\\n\\n## \\u4e0a\\u6d77\\n- **\\u5929\\u6c14\\u72b6\\u51b5**\\uff1a\\u6674\\n- **\\u6e29\\u5ea6**\\uff1a17.92\\u00b0C\\n- **\\u4f53\\u611f\\u6e29\\u5ea6**\\uff1a17.02\\u00b0C\\n- **\\u6e7f\\u5ea6**\\uff1a48%\\n- **\\u6c14\\u538b**\\uff1a1020 hPa\\n- **\\u98ce\\u901f**\\uff1a4.0 m/s\\n- **\\u80fd\\u89c1\\u5ea6**\\uff1a10000\\u7c73\\n\\n---\\n*\\u6570\\u636e\\u6765\\u6e90\\uff1aOpenWeather API*\\n*\\u66f4\\u65b0\\u65f6\\u95f4\\uff1a\\u5f53\\u524d\\u65f6\\u95f4*", "filename": "\\u4e09\\u57ce\\u5929\\u6c14\\u62a5\\u544a.md"}', 'name': 'write_to_markdown'}, 'type': 'function', 'index': 0}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 702, 'prompt_tokens': 1270, 'total_tokens': 1972, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 448}, 'prompt_cache_hit_tokens': 448, 'prompt_cache_miss_tokens': 822}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': 'a301e0ec-150c-4881-b15a-70f9de44b6f6', 'service_tier': None, 'finish_reason': 'tool_calls', 'logprobs': None}, id='lc_run--16ba0389-e6a7-4d5d-957c-c323e41ea46f-0', tool_calls=[{'name': 'write_to_markdown', 'args': {'content': '# 三城天气报告\n\n## 北京\n- **天气状况**:阴,多云\n- **温度**:14.94°C\n- **体感温度**:13.19°C\n- **湿度**:27%\n- **气压**:1019 hPa\n- **风速**:2.29 m/s\n- **能见度**:10000米\n\n## 杭州\n- **天气状况**:多云\n- **温度**:18.95°C\n- **体感温度**:18.28°C\n- **湿度**:53%\n- **气压**:1019 hPa\n- **风速**:3.42 m/s\n- **能见度**:10000米\n\n## 上海\n- **天气状况**:晴\n- **温度**:17.92°C\n- **体感温度**:17.02°C\n- **湿度**:48%\n- **气压**:1020 hPa\n- **风速**:4.0 m/s\n- **能见度**:10000米\n\n---\n*数据来源:OpenWeather API*\n*更新时间:当前时间*', 'filename': '三城天气报告.md'}, 'id': 'call_00_BjTQ6PN1XwKlCI2yplD2yrQK', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1270, 'output_tokens': 702, 'total_tokens': 1972, 'input_token_details': {'cache_read': 448}, 'output_token_details': {}}),ToolMessage(content='内容已成功保存为 ./output.md 文件。', name='write_to_markdown', id='3943f65b-b88b-4b80-b551-85f3bbfa312c', tool_call_id='call_00_BjTQ6PN1XwKlCI2yplD2yrQK'),AIMessage(content='已完成!我已经为您查询了北京、杭州、上海三地的天气信息,并将详细报告保存到了本地文件 `output.md` 中。\n\n**主要天气情况总结:**\n- **北京**:阴天多云,温度约15°C,较为凉爽\n- **杭州**:多云天气,温度约19°C,湿度较高\n- **上海**:晴朗天气,温度约18°C,风速稍大\n\n所有详细信息都已保存到Markdown文件中,包括温度、湿度、风速、气压等完整气象数据。', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 112, 'prompt_tokens': 1580, 'total_tokens': 1692, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 1280}, 'prompt_cache_hit_tokens': 1280, 'prompt_cache_miss_tokens': 300}, 'model_name': 'deepseek-chat', 'system_fingerprint': 'fp_ffc7281d48_prod0820_fp8_kvcache', 'id': '72222a5c-3b5c-42d9-a645-572b3fd3dc53', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None}, id='lc_run--39e4fdb7-d075-4637-bd1d-858ab317478f-0', usage_metadata={'input_tokens': 1580, 'output_tokens': 112, 'total_tokens': 1692, 'input_token_details': {'cache_read': 1280}, 'output_token_details': {}})]
更多推荐


所有评论(0)