D2 · Tool Design & MCP › Cluster 4 · Advanced Tool Use

4.1 · Tool Use with Extended Thinking

Reason across tool results

CONCEPT Claude reasons about which tool — and about what came back

Extended thinking (on current 4.x models this is adaptive thinking, thinking: {"type": "adaptive"}) gives Claude a private reasoning scratchpad. Combined with tools, that reasoning happens in two places: before a tool call, Claude thinks about which tool to call and with what arguments; after a tool_result returns, Claude thinks again — reasoning across the result — before deciding the next action or the final answer. This second pass is interleaved thinking, and adaptive thinking turns it on automatically (no beta header on 4.6+).

🔑 Interleaved thinking is what lets Claude chain tool calls intelligently: it can look at what search() returned, notice the answer is incomplete, and reason its way to a second, better-targeted call — rather than blindly firing a fixed sequence.

CONCEPT Two rules the exam tests: replay signed blocks, and no forced tools

Thinking + tools comes with two hard constraints:

⚠️ If you need both "Claude must call a tool" and deep reasoning, you can't force it — steer with a strong user-message instruction instead, or drop thinking for that call.

DIAGRAM Thinking wraps every tool round-trip

sequenceDiagram participant U as User participant C as Claude participant H as Your harness U->>C: question + tools Note over C: 🧠 thinking (signed):
which tool? which args? C->>H: tool_use(search, ...) H->>C: tool_result Note over C: 🧠 interleaved thinking:
reason across the result C->>H: tool_use(fetch, ...) H->>C: tool_result Note over C: 🧠 thinking: enough to answer C->>U: final answer Note over H: replay ALL thinking blocks
+ signatures unchanged each turn

CODE Adaptive thinking + tools, then echo signed blocks back

First call enables adaptive thinking with tool_choice at its only legal values (auto). The follow-up turn must carry the original thinking block and the tool_use block back, unmodified, alongside the tool_result.

# 1) First request — thinking on, tool_choice must be auto/none
resp = client.messages.create(
    model="claude-opus-4-8", max_tokens=16000,
    thinking={"type": "adaptive"},   # interleaved thinking auto-on
    tools=tools,
    tool_choice={"type": "auto"},     # 'any'/'tool' would 400 here
    messages=[{"role": "user", "content": "What changed in the Q3 report?"}],
)

# resp.content = [ thinking(signature=...), tool_use(id=..., name="search") ]
tool_use = next(b for b in resp.content if b.type == "tool_use")
result = run_tool(tool_use.name, tool_use.input)

# 2) Continue — replay resp.content VERBATIM (thinking block + signature intact)
resp2 = client.messages.create(
    model="claude-opus-4-8", max_tokens=16000,
    thinking={"type": "adaptive"}, tools=tools,
    messages=[
        {"role": "user", "content": "What changed in the Q3 report?"},
        {"role": "assistant", "content": resp.content},   # ← unchanged, signed
        {"role": "user", "content": [{
            "type": "tool_result",
            "tool_use_id": tool_use.id,
            "content": result,
        }]},
    ],
)

TRADE-OFFS Interleaved reasoning vs. its constraints

✅ Thinking + tools

  • Claude reasons across results, not just before the first call
  • Smarter multi-step chains: adapts the next call to what came back
  • Fewer wasted / redundant tool calls on hard, ambiguous tasks

⚠️ The price

  • Must replay every thinking block + signature unchanged
  • Can't force a tool (any/tool error) — only auto/none
  • More output tokens; thinking is billed even when its text is omitted
Use thinking + tools for genuinely multi-step, ambiguous work. For a single deterministic extraction where you'd force one tool, skip thinking and force the tool instead (see 4.5).

EXAM TRAPS

Trap: "Force a specific tool while extended thinking is on." → Not allowed. tool_choice: any / tool error with thinking; only auto and none are compatible.
Trap: Stripping or regenerating thinking blocks before the next turn to "save tokens." → The signature is a seal; altered or missing signed blocks break the continuation. Replay them verbatim on the same model.
Trap: Assuming thinking only happens before the first tool call. → With adaptive thinking, Claude thinks again after each tool_result (interleaved) — that's the whole point.
Trap: Setting budget_tokens to bound thinking on Opus 4.8. → Removed on 4.7/4.8 (400). Use thinking: {"type":"adaptive"} and steer depth with output_config.effort.

PRACTICE

Q1 · Why must you send the assistant's thinking block back on the next turn?

Because on the same model Claude expects its prior reasoning — sealed by an opaque signature — to be replayed unchanged. It uses the signed block to continue coherently; tampering with or dropping it makes the API reject the turn. You can display a summary, but never edit the block.

Q2 · A teammate sets tool_choice:{"type":"tool","name":"lookup"} with adaptive thinking and gets an error. Why?

Forced tool use (any or tool) is incompatible with extended thinking — forcing a tool prefills the assistant turn, which can't coexist with a leading thinking block. Only auto (default) and none work. To bias selection, put "use the lookup tool" in a user message.

Q3 · What is "interleaved" thinking and what does it buy you?

Thinking that occurs between tool calls — after each tool_result Claude reasons again before its next move. It buys smarter multi-step behavior: Claude can notice a partial result and reformulate the next call instead of following a fixed script.