Who Actually Executes Agent Tools? Inside Function Calling, MCP, and Pi's Harness
Tool calling underpins every Agent product, so understanding that the Harness, not the model, is the executor clarifies where to add safety checks, error handling, and control. This matters for anyone building agents in production, where a native `tool.execute()` is trivial but stable, secure, and controllable execution is the real engineering burden.
A common misconception about Agent tool calling is that the large language model executes the tools. In reality, the LLM only decides which tool to call and with what parameters; the Harness, the engineering layer built from program code, is what finds the tool, validates arguments, runs it, and wraps the result back into a message for the model's next turn. This split between decision and execution is the core of the Agent = LLM + Harness formula.
The Pi framework's implementation shows the full lifecycle: `executeToolCalls()` chooses between sequential and parallel modes, then each call goes through `prepareToolCall()` which checks tool existence, adapts parameters, validates schemas, and runs a `beforeToolCall` hook for permission checks, user confirmation, logging, or policy interception. After `tool.execute()`, `afterToolCall` hooks handle desensitization, truncation, and error correction, and the result becomes a `ToolResultMessage` added to context.
A notable design choice is error handling: Pi converts tool exceptions into `isError: true` result messages instead of throwing them out of the loop, so the model can retry or adjust. The author draws three design principles: everything in the model interaction layer is a Message, hooks matter as much as the tool itself, and the clean separation between LLM decision-making and Harness execution is what makes Agent systems reliable.
The emphasis on beforeToolCall and afterToolCall hooks shows that production Agent reliability comes from engineering control around the naive `tool.execute()`, not from the model itself.
Converting errors into result messages instead of exceptions is a deliberate pattern that treats model self-correction as a first-class recovery strategy, which is fine for small loops but could mask systemic failures.
The parallel-by-default behavior of Pi is a pragmatic efficiency choice, but it requires that tool calls be independent; sequential mode exists for operations that must happen in order.
The article's clear separation of LLM and Harness roles makes it easier to debug why an agent failed: either the model chose poorly or the harness mis-executed, which are distinct failure domains.