The whole hunk
from line 4, old and new numbered
/
lines
from line 4
44description: Connect Claude to external tools and APIs. See where tools execute, when Claude calls them, and which tool fits your task.
55---
66
7Tool use lets Claude call functions that you define or that Anthropic provides. Claude determines when to call a tool based on the user's request and the tool's description. It then returns a structured call that your application executes (client tools) or that Anthropic executes (server tools).
7Tool use (also called function calling) lets Claude call functions that you define or that Anthropic provides. Claude determines when to call a tool based on the user's request and the tool's description. It then returns a structured call that your application executes (client tools) or that Anthropic executes (server tools).
88
99Here's a minimal example using a server tool, the [Web search tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool), which Anthropic executes for you:
1010
from line 175
175175 echo "Claude called $(echo "$TOOL_USE" | jq -r '.name') with $(echo "$TOOL_USE" | jq -c '.input')"
176176
177177 # Run the tool, then send the result back in a tool_result block.
178 # Claude uses the result to answer the original question.
178179 WEATHER="15 degrees Celsius, partly cloudy"
179 FOLLOWUP=$(curl -s https://api.anthropic.com/v1/messages \
180 curl -s https://api.anthropic.com/v1/messages \
180181 -H "x-api-key: $ANTHROPIC_API_KEY" \
181182 -H "anthropic-version: 2023-06-01" \
182183 -H "content-type: application/json" \
from line 199
198199 {type: "tool_result", tool_use_id: $tool_use_id, content: $weather}
199200 ]}
200201 ]
201 }')")
202
203 # Claude uses the result to answer the original question.
204 echo "$FOLLOWUP" | jq -r '.content[] | select(.type == "text") | .text'
202 }')"
205203 ```
206204
207205 ```bash CLI
from line 244
246244 {type: "tool_result", tool_use_id: $tool_use_id, content: $weather}
247245 ]}
248246 ]' <<<"$MESSAGES")
249 FOLLOWUP=$(call_api)
250247
251248 # Claude uses the result to answer the original question.
252 jq -r '.content[] | select(.type == "text") | .text' <<<"$FOLLOWUP"
249 call_api
253250 ```
254251
255252 ```python Python