0PricingLogin
AI Agents · Lesson

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

  1. You send messages + tool definitions
  2. Model returns either a final answer OR a tool_call
  3. You execute the tool with the model's arguments
  4. You append the result as a tool message
  5. You call the model again with the updated history

Repeat 2-5 until the model returns a final answer.

All lessons in this course

  1. How Function Calling Works
  2. Defining Tool Schemas (JSON Schema)
  3. Choosing Tools at Runtime
  4. Returning Results to the Model
← Back to AI Agents