Build a Tool Calling Agent with LangGraph ToolNode
The Juejin AI report explains how to build a tool-calling agent in LangGraph by converting Python functions into tools with LangChain's @tool decorator and executing them through ToolNode. It shows how to bind multiple tools to a model, route requests using tool_calls, return tool results, and generate a final natural-language response. The article also compares the prebuilt ToolNode with a manual execution node and notes that invalid tool names or mismatched arguments require additional error handling.
The tutorial provides a concrete implementation pattern for extending LangGraph agents from fixed routing choices to model-selected tools, including search, weather, and database operations.
LangGraph 的工具调用代理 - Tool Calling Agent
一、为什么需要 Tool Calling Agent
在 LangGraph 支持的代理架构中,路由代理(Router Agent)是基础形态:它通过 add_conditional_edges 搭配 Router Function,让大模型借助"结构化输出"在少数几个预设分支之间做选择。
但 Router Agent 有一个明显的局限:大模型通常只能控制单个决策,分支数量是写死的。比如我们只定义了"插入数据库"这一个分支,一旦希望接入网络搜索、RAG、天气查询等一堆各式各样的工具,难道要在每个工具下再套一层 Router Function 做分支判断吗?虽然可行,但显然不是高效的做法。
由此引出本文的主角——工具调用代理(Tool Calling Agent)。它是在 Router Agent 基础上的升级:大模型可以自主选择并使用工具库中的多种工具来完成某个分支中的任务。
它的核心思想一句话概括: