Skip to content

Workflow: Tool Use Cycle ​

Updated: 2026-05-26

Complete tool use cycle from schema definition through the agentic loop to final response.

flowchart TD
    A[Define Tool Schema] --> B[Send Request with Tools Array]
    B --> C{Claude Response}
    C -->|stop_reason: tool_use| D[Parse tool_use Blocks]
    D --> E[Execute Tool Logic]
    E --> F[Send tool_result Back]
    F --> C
    C -->|stop_reason: end_turn| G[Final Text Response]
    C -->|stop_reason: max_tokens| H[Handle Truncation]
    H --> B

    subgraph Client Side
        A
        B
        D
        E
        F
        H
    end

    subgraph Server Side
        C
        G
    end

Phases ​

Phase 1: Define Tool Schema ​

Create JSON Schema definitions for each tool your Claude instance can use. Each tool needs a name, description, and input_schema with typed properties.

Phase 2: Send Request ​

Include the tools array in your Messages API request. Claude sees the tool definitions alongside the user message and decides whether to use a tool or respond directly.

Phase 3: Parse Tool Calls ​

When stop_reason is tool_use, extract the tool_use blocks from the response. Each block contains the tool name, input arguments, and a unique tool_use ID.

Phase 4: Execute and Return ​

Run the tool logic with the provided arguments. Format results as tool_result blocks with the matching tool_use_id. Send back to continue the loop.

Phase 5: Final Response ​

The loop continues until Claude has enough information to respond directly with text (stop_reason: end_turn), or hits the token limit (max_tokens).

Key Decisions ​

  • Tool selection: Claude chooses which tool to call based on the user request and tool descriptions
  • Parallel calls: Claude can call multiple tools in one response for independent operations
  • Error handling: Return errors as tool_result content - Claude will attempt recovery

See Also ​