Intermediate10 min
Anthropic Tool Use & Extended Thinking
Claude's native tool use API: tool definitions, tool_choice modes, extended thinking for complex reasoning, computer use for desktop automation, and streaming with tool calls.
Quick Reference
- →Define tools with `input_schema` (JSON Schema) — Claude selects tools based on descriptions and schema
- →tool_choice modes: `auto` (model decides), `any` (must use a tool), `tool` (specific tool forced)
- →Extended thinking: Claude shows chain-of-thought reasoning before selecting tools — better decisions on complex tasks
- →Computer use: Claude interacts with desktop applications via screenshots and coordinate-based actions
- →Stream tool use with `stream=True` — handle `content_block_start` and `content_block_delta` events for partial tool inputs
Claude Tool Use Fundamentals
Anthropic's tool use follows a similar pattern to OpenAI but with key differences in structure and capability. Tools are defined with input_schema (not parameters), and Claude's tool selection tends to be more conservative — it explains its reasoning before calling tools, which reduces hallucinated tool calls.
Complete Anthropic tool use with streaming