Open-source agent project adds LangChain tool calling
The third chapter of EasonChenC’s open-source Zero-to-One-Building-an-AI-Agent project explains how to add tools to an agent. The implementation uses LangChain AIMessage objects and bind_tools, with a Harness validating and dispatching model-generated tool requests before returning ToolMessage results to the message history. The project includes structured tool definitions, a tool registry, file-access restrictions, confirmation for writes, per-turn and total call limits, output truncation, and error handling. The supplied report does not identify the article’s publication platform.
The chapter provides a code-oriented example of an agent loop that executes tools while limiting access, requiring confirmation for write operations, restricting call frequency, and truncating output.
GitHub 项目地址:EasonChenC/Zero-to-One-Building-an-AI-Agent 本文对应的完整代码都在上面的 GitHub 项目中,对应的是第三章节:给 Agent 添加工具,可以边读边对照源码运行。 笔者创建了这个开源项目 Zero-to-One-Building-an-AI-Agent,把构造 Agent 的每一个功能都拆分成一个对应的章节:每一章不仅介绍该知识点的概念内容,还会实现对应的项目代码,并在项目中扩展实现相应功能,让你真正看到这项能力在智能体中如何发挥作用。
在前面的章节中,我实现了一个小型Agent,这个Agent已经能够理解用户目标、提出问题,并在多轮对话中给出最终回答。但这个 Agent 仍然只能“说”,不能真正查看文件、查询天气、计算数据、调用接口或修改项目。
如果把模型比作人的大脑,那么工具就是这个人的双手。模型负责判断“下一步需要做什么”,工具负责在真实环境里根据模型的意图去执行这个决策,然后再把执行结果返回给模型进行下一步的决策判断。