Function Calling & Tool Use

LLMs cannot do anything. They generate text. That is the entire capability. They cannot check the weather, query a database, send an email, run code, or read a file. Every "AI agent" you have ever seen is an LLM generating JSON that says which function to call -- and then your code actually calling it. The model is the brain. Tools are the hands. Function calling is the nervous system connecting them.

Build 1.3 hr Python

Prerequisites: Phase 11 Lesson 03 (Structured Outputs)

#Learning Objectives

  • Implement a function calling loop: define tool schemas, parse the model's tool-call JSON, execute functions, and return results
  • Design tool schemas with clear descriptions and typed parameters that the model can reliably invoke
  • Build a multi-turn agent loop that chains multiple function calls to answer complex queries
  • Handle function calling edge cases: parallel tool calls, error propagation, and preventing infinite tool loops
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.