跳转到内容

Day 2 · Function Calling 与最小 Agent

本章目标:理解工具调用协议,实现 ToolRegistry,搭出最小 Agent Loop。 产出:my-agent/tools.py — 你的 ToolRegistry 类。

你将学到

  • Chatbot vs Agent:为什么需要循环
  • Function Calling 协议:4 条消息的完整流转
  • ToolRegistry:从函数签名自动生成 schema
  • 最小 Agent Loop:LLM + Tools + While 循环

内容结构

内容讲义Demo
6Agent vs Chatbot06-agent-vs-chatbotdemo_06_chatbot_vs_agent.py
7Function Calling 协议07-function-callingdemo_07_function_calling_protocol.py
8ToolRegistry08-tool-registrydemo_08_tool_registry.py
9最小 Agent Loop09-agent-loopdemo_09_mini_agent.py

运行 Demo

bash
cd 02-tools-and-agent-loop/lab
python demo_06_chatbot_vs_agent.py
python demo_07_function_calling_protocol.py
python demo_08_tool_registry.py
python demo_09_mini_agent.py

今日产出

补全 my-agent/tools.py 中的 ToolRegistry 类,让测试通过:

bash
cd my-agent
python tests/test_tools.py

配套练习

exercises/02-tools-and-agent-loop/ — 3 道代码填空题

Released under the MIT License.