Skip to main content
This page continues Client Tools. The examples reuse the search_gutenberg_books tool, tools, instructions, and input defined there.

Interleaved Thinking

Interleaved thinking allows models to reason between tool calls, enabling more sophisticated decision-making after receiving tool results. This feature helps models chain multiple tool calls with reasoning steps in between and make nuanced decisions based on intermediate results. Important: Interleaved thinking increases token usage and response latency. Consider your budget and performance requirements when enabling this feature.

How Interleaved Thinking Works

With interleaved thinking, the model can:
  • Reason about the results of a tool call before deciding what to do next
  • Chain multiple tool calls with reasoning steps in between
  • Make more nuanced decisions based on intermediate results
  • Provide transparent reasoning for its tool selection process

Example: Multi-Step Research with Reasoning

Here’s an example showing how a model might use interleaved thinking to research a topic across multiple sources: Initial Request:
Model’s Reasoning and Tool Calls:
  1. Initial Thinking: “I need to research electric vehicle environmental impact. Let me start with academic papers to get peer-reviewed research.”
  2. First Tool Call: search_academic_papers({"query": "electric vehicle lifecycle environmental impact", "field": "environmental science"})
  3. After First Tool Result: “The papers show mixed results on manufacturing impact. I need current statistics to complement this academic research.”
  4. Second Tool Call: get_latest_statistics({"topic": "electric vehicle carbon footprint", "year": 2024})
  5. After Second Tool Result: “Now I have both academic research and current data. Let me search for manufacturing-specific studies to address the gaps I found.”
  6. Third Tool Call: search_academic_papers({"query": "electric vehicle battery manufacturing environmental cost", "field": "materials science"})
  7. Final Analysis: Synthesizes all gathered information into a comprehensive response.

Best Practices for Interleaved Thinking

  • Clear Tool Descriptions: Provide detailed descriptions so the model can reason about when to use each tool
  • Structured Parameters: Use well-defined parameter schemas to help the model make precise tool calls
  • Context Preservation: Maintain conversation context across multiple tool interactions
  • Error Handling: Design tools to provide meaningful error messages that help the model adjust its approach

Implementation Considerations

When implementing interleaved thinking:
  • Models may take longer to respond due to additional reasoning steps
  • Token usage will be higher due to the reasoning process
  • The quality of reasoning depends on the model’s capabilities
  • Some models may be better suited for this approach than others

Function Definition Guidelines

When defining tools for LLMs, follow these best practices: Clear and Descriptive Names: Use descriptive function names that clearly indicate the tool’s purpose.
Comprehensive Descriptions: Provide detailed descriptions that help the model understand when and how to use the tool.

Streaming with Tool Calls

When using streaming responses with tool calls, handle the different content types appropriately. The Python, Go, and cURL tabs define the tool-call handler they use; handleToolCalls in the TypeScript tab is your own function with the same job. The Python, Go, and cURL follow-up requests follow A Simple Agentic Loop on Client Tools. The TypeScript tab receives raw Responses API events, so take tools from the TypeScript (fetch) tab in Define the Tool, not the SDK setup, and build its follow-up like the TypeScript (fetch) tabs in Tool use and tool results: match the raw search_gutenberg_books name and send each result with the raw call_id, not the SDK loop’s searchGutenbergBooks and callId. Reuse this tab’s MODEL in that follow-up so the conversation stays on the same model, and start the follow-up’s input from streamInput, not input, so the tool results stay paired with the streamed prompt. In Go, build on the Go tabs in Define the Tool and Tool use and tool results, which use the flat Responses API tool format, not the nested Chat Completions tools in the first Go program on Client Tools. Add bufio to your imports, and use this request in place of that walkthrough’s first request and every step after it (the response1 handling and the second request), not after them, since it declares body and req again and runs its own follow-up:

Tool Choice Configuration

Control tool usage with the tool_choice parameter:

Parallel Tool Calls

Control whether multiple tools can be called simultaneously with the parallel_tool_calls parameter (default is true for most models):
When parallel_tool_calls is false, the model will only request one tool call at a time instead of potentially multiple calls in parallel.

Multi-Tool Workflows

Design tools that work well together:
This allows the model to naturally chain operations: search → get details → check inventory.

Reliability Tracking

OpenRouter tracks how reliably each provider completes tool calls and surfaces this as the Tool Call Error Rate on the Performance tab of every model page. The same signal drives Auto Exacto provider ordering on tool-calling requests. For the exact validator, JSON Schema draft, regex semantics, and per-tool-call classification, see How Tool-Calling Success Rate Is Measured. For more details on the Responses API input format and tool parameters, see the Responses API reference.