Learn/Agentic AI/How Agents Use Tools
Agentic AI

How Agents Use Tools

Tool use — sometimes called function calling — is the mechanism that gives agents the ability to interact with the world beyond generating text.

How Agents Use Tools

Tool use — also called function calling — is the mechanism that gives agents the ability to interact with the world beyond generating text.

The Tool Use Cycle

1. Define tools as JSON schema: You declare available tools in your API request. Each tool has a name, description, and input schema. The description is critical — the model uses it to decide when to call the tool.

2. Model outputs a structured tool call: When the model needs a tool, it returns stop_reason: "tool_use" and a structured block with the tool name and arguments — not free text.

3. Host executes and returns results: Your application receives the tool call, executes it, and appends the result as a tool_result message. The model continues reasoning with that new information.

This loop repeats until stop_reason: "end_turn".

Common Tool Categories

  • Web search — Query a search engine, return summaries
  • File read/write — Read source code, configs; write or patch files
  • Code execution — Run Python, shell commands, test suites in a sandbox
  • API calls — Hit REST endpoints: databases, email, external services
  • Database queries — SQL or NoSQL lookups

Provider Implementations

Anthropic: Tools in the tools array. Results as tool_result content blocks in a user message. Supports parallel tool calls.

OpenAI: tools array with function type objects. Results via tool role messages. Responses API adds built-in tools (web search, code interpreter) without host-side execution.

Google: "Function declarations" in the tools config. Results use functionResponse parts.

Practical Guidance

  • Write tool descriptions like documentation — the model uses them to decide when to call
  • Validate tool inputs server-side before execution
  • Return structured JSON results for reliable follow-up reasoning
  • Log every tool call and result — agents fail silently without traces

Have a follow-up question about this topic?

Ask AI