PrepGenAICerts

The Tool-Use Loop: tool_use, tool_result, and Who Executes

Core

Implement tools and understand the function-calling loop · Difficulty 1/5

0%
tool-usefunction-callingtool-resultagentic-loop

Explanation

How Tool Use Works

Tool use (function calling) follows a fixed loop:

  1. You send a request with a tools array; each tool has a name, a description, and an input_schema (JSON Schema).
  2. If Claude decides it needs a tool, it responds with `stop_reason: "tool_use" and a tool_use block containing the tool's name and the input` arguments.
  3. Your code executes the tool -- Claude never runs it itself -- and you return the result as a `tool_result block inside a new user message, matched to the request by tool_use_id`.
  4. Claude uses the result to continue the turn, possibly calling more tools, until it reaches end_turn.

Client-Side vs. Server-Side Tools

*Client-side* tools are the default pattern: your application executes the tool. *Server-side* tools run within Anthropic's own infrastructure (certain built-in tools). Knowing which category a given tool falls into determines who is responsible for execution and where the code that implements it lives.

Agentic Harness Dispatch and Approval

In an agent, a dispatcher maps each `tool_use` name to the corresponding function and runs it. For sensitive or destructive tools, an approval pattern requires human or hook-based sign-off before the tool actually executes.

Common exam traps

  • "Claude executes the tool." False -- Claude only *requests* a tool call by emitting a `tool_use` block; your code runs it and returns the result.
  • Forgetting to feed the `tool_result back with the matching tool_use_id` -- without it, the loop cannot continue and Claude has no way to use the outcome of the call.
  • Assuming all tools are client-side; some built-in tools execute server-side within Anthropic's infrastructure.

Key Takeaways

  • The loop is: send tools array -> Claude emits a tool_use block (name + input) -> your code executes it -> you return a tool_result matched by tool_use_id -> Claude continues or ends the turn
  • Claude never executes a tool itself; it only requests the call, and your application code is what actually runs it
  • Client-side tools are executed by your app (the default); server-side tools run within Anthropic's infrastructure
  • Sensitive or destructive tools should sit behind an approval pattern (human or hook-based) before executing

Glossary Terms

Related Concepts

PrepGenAICerts.com is an independent third-party exam-prep platform for the Claude Certified Architect (CCA-F) certification. We are not affiliated with, endorsed by, or acting on behalf of Anthropic PBC.

Note: New premium upgrades are temporarily paused while we resolve an issue with our payment provider. Existing premium members retain full access.