Define tools with JSON schemas — LLMs select and call them, you execute and feed results back.
Tool Use and Function Calling
import anthropic, json
client = anthropic.Anthropic()
tools = [
{
"name": "search_web",
"description": "Search the internet for current information",
"input_schema": {
"type": "object",
"properties": {
"query": {"type":"string","description":"Search query"}
},
"required": ["query"]
}
},
{
"name": "run_python",
"description": "Execute Python code and return output",
"input_schema": {
"type": "object",
"properties": {
"code": {"type":"string","description":"Python code to execute"}
},
"required": ["code"]
}
}
]
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
tools=tools,
messages=[{"role":"user","content":"Search for Python 3.13 new features"}]
)
for block in response.content:
if block.type == "tool_use":
print(f"Tool: {block.name}")
print(f"Input: {block.input}")
# Execute tool and feed result back