How Function Calling Works
Understand the full round-trip: model picks a tool, your code runs it, you send the result back, and the model continues.
Function Calling: The Core Pattern
Function calling is the protocol that turns an LLM into an agent. The model picks a function from a list you provide, fills in the arguments, and you run it.
This pattern is supported by OpenAI, Anthropic, Google, Cohere, Mistral, and most major OSS models with the right fine-tunes.
The Five-Step Round-Trip
- You send messages + tool definitions
- Model returns either a final answer OR a tool_call
- You execute the tool with the model's arguments
- You append the result as a tool message
- You call the model again with the updated history
Repeat 2-5 until the model returns a final answer.
All lessons in this course
- How Function Calling Works
- Defining Tool Schemas (JSON Schema)
- Choosing Tools at Runtime
- Returning Results to the Model