Agent Systems: Tool Use and Code Execution

Figure

Tool use and code execution

Figure: the agent acts through typed tool interfaces and receives explicit observations.

In one sentence. Act through typed interfaces that return explicit observations, so side effects are authorized and checkable rather than asserted.

Problem

Language generation is not the right mechanism for deterministic operations, external state, or exact computation. The agent needs a controlled way to act and to receive an observation.

Intent and structure

agent → tool schema → capability → observation → agent

Function calling, MCP-style tool protocols, HTTP services, databases, code runners, and proof assistants are implementations of this boundary. The stable part is the tool name, input schema, permissions, return schema, and error behavior.

Code execution

Use code for exact arithmetic, symbolic experiments, finite searches, plots, or formal proof checking. Keep the program, environment, and output as inspectable artifacts. A successful execution is evidence about the computation, not automatically a proof of the surrounding theorem.

Safety and reliability

Use least privilege, validate arguments, control side effects, set timeouts, make writes idempotent where possible, and distinguish a tool error from a negative mathematical result. An observation must be checked before it changes the next state.

Example

The Rethlas generation agent exposes theorem search and proof verification as explicit tools; Danus adds a role-gated gateway so different agents see different capabilities.

Real-world application

An operations agent may query a database, run a diagnostic command, and open a ticket. Typed tool schemas, permission checks, timeouts, and explicit observations turn those side effects into a controlled workflow rather than an unreviewable conversation.

Reference basis

The tool-use pattern is Gulli, Agentic Design Patterns, Chapter 5, and Lakshmanan and Hapke, Generative AI Design Patterns, where tool calling and code execution are Patterns 21 and 22. The reasoning/action interface is exemplified by the ReAct paper; standardized access to external data and tools is specified by the MCP specification. Function calling as an implementation, and its parallel form, are treated practically in James Phoenix and Mike Taylor, Prompt Engineering for Generative AI, O’Reilly, 2024, Chapter 4. For the packaging of tools and instructions as named, loadable capabilities — so that a capability’s detail enters context only when it is needed — see Stephen Clear, Claude AI Bible, Chapters 14 and 16.