Inside Pi’s Tool-Calling Implementation
A source-code analysis examines Pi’s tool-calling flow, the second installment in the author’s Pi research series. It follows tool calls from the LLM’s structured request through execution in sequential or parallel mode, tool lookup, parameter adaptation and schema validation, beforeToolCall and afterToolCall hooks, cancellation checks, error handling, and the creation of tool-result messages for the next Agent Loop iteration. It also contrasts local tools with MCP tools, which the Harness accesses through an MCP client and server. The article does not identify the Pi version examined.
The analysis highlights a central division in agent architecture: the LLM decides which tool and parameters to use, while the Harness validates the request and executes it with controls such as hooks, cancellation checks, and error handling.
引言
工具调用已经是Agent领域的老生常谈了,
但我发现,很多人虽然每天都在使用 Agent,对工具调用背后的运行机制却未必真正理解。
比如,
大模型能直接执行工具吗?
Function Calling 和 MCP 到底是什么关系?