Tool calling (Anthropic's term) — or function calling (OpenAI's term) — is the LLM ability to invoke predefined functions instead of just generating text.
The Idea
Without tool calling, an LLM only outputs text. With tool calling:
- You define tools with schemas
- LLM decides to invoke one
- LLM outputs a JSON tool_call
- Your code runs the function
- You feed the result back to the LLM
- LLM continues with the new context
This unlocks agents.
Anthropic Claude Tool Use
tools = [{
"name": "get_weather",
"description": "Get weather for a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
}
}]
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "Weather in Istanbul?"}]
)
OpenAI Function Calling
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
}
}
}]
Same idea, slightly different shape.
Multi-Tool
Most LLMs handle multiple tools in one call. They pick the right one based on the prompt.
Parallel Tool Use
Claude and GPT-4 can call multiple tools in parallel. Use when independent (no dependency between).
Structured Output
A common use: force the model to output strict JSON matching a schema. Set the tool as "the response itself" and you get type-safe output.
Common Failure Modes
- Bad tool descriptions: model picks wrong tool
- Required fields missing in schema: model invents values
- Vague return types: model can't reason about result
- No max_iterations: agent loops forever
Next Step
Build a real agent: read how to build an AI agent.