Courses / Agentic AI / Module 0
Module 0: Bridge: tool calling and structured output refresher
6 h · theory 2 · hands-on 2 · project 1 · revision 1
You will be able to
- Call a model with tools and parse its tool calls
- Validate tool arguments with Pydantic
- Score yourself on the diagnostic and pick your starting module
Capstone increment: Capstone repo with a single-tool baseline that later modules replace.
Job-description skills: Tool calling, Structured output · Lab tools: python3.12, openai, pydantic
1. From chat to tools
A chat model only produces text. Tool calling lets it ask your code to do something: the model returns the name of a tool and JSON arguments, your code runs the tool, and you send the result back for the model to use. An agent is that exchange in a loop with a stop condition.
This course builds agents that act on real systems, so it starts by making sure the single round trip is solid: schemas, validation, error messages and the message format.
2. Tool calling in the API
You describe each tool with a name, a description and a JSON Schema for its parameters. The model may answer in text or with one or more tool calls. In OpenAI-compatible APIs the assistant message carries tool_calls, and you reply with one tool message per call, matched by tool_call_id. Anthropic’s API uses tool_use and tool_result content blocks for the same exchange.
Options worth knowing: tool_choice forces or forbids tool use; parallel tool calls let the model request several independent calls at once; strict or structured modes make the model follow the schema exactly. Local models served by Ollama or vLLM speak the same OpenAI-compatible format.
3. Validate every argument
Treat tool arguments like any input from the internet. Define each tool as a Pydantic model, generate the JSON Schema from it, and validate the model’s arguments before running anything. Use enums for closed sets, bounds for numbers and formats for dates.
When validation fails, return a short, specific error as the tool result (“service: input should be one of checkout, payments…”) instead of raising. Models usually fix their call on the next turn if the error tells them how.
4. Diagnostic: where should you start?
If you can write the tool-calling round trip from memory, validate arguments with Pydantic and explain parallel tool calls, skim Module 1. If you have built a graph-based agent with checkpoints, skim Module 3. Everyone should do Modules 9 to 12: approvals, guardrails, evaluation and observability are where most agent projects fail in production.
Prerequisites from the GenAI & LLM course: calling a model API, structured output, a basic agent loop and basic evals. Revisit that course’s Modules 2, 4, 7 and 8 if any of those is shaky.
5. The capstone: an IT operations assistant
You will build a multi-agent assistant for on-call engineers. A supervisor routes an incident to log, metrics and runbook agents that use tools exposed as MCP servers. Any action that changes a system waits for a human approval. Every run is traced, budgeted and covered by trajectory evals in CI, and the whole thing runs as durable workflows at a public URL.
The starter repo already has a FastAPI service and a hand-written agent loop with a step limit. This module adds a single-tool baseline that later modules replace.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 0.1: A real tool call
Call a real model (hosted, or local via Ollama) with the get_service_status tool, run the tool it asks for, send the result back and print the final answer.
Expected: A transcript showing the tool call, the tool result and an answer that uses it.
Lab 0.2: Diagnostic
Answer the checkpoint quiz without notes and write down which modules you will skim, with one line of evidence for each.
Expected: A study plan in progress/plan.md.
Lab 0.3: Single-tool baseline (capstone increment)
Push the starter repo, get CI green, and add POST /investigate that runs the Module 1 loop with one tool. Score it on five sample incidents.
Expected: A public repo with passing CI and a baseline task-success number in docs/baseline.md.
Go deeper
Videos
- What is Tool Calling? Connecting LLMs to Your Data · IBM Technology · ~5 min. Tool calling explained in five minutes: what the model does and what your code does.
- What are AI Agents? · IBM Technology · ~12 min. A clear overview of what makes an AI system an agent.
- 4 Types of AI Agent Loops: From Human-Led to Autonomous · IBM Technology · ~9 min. Four kinds of agent loop, from human-led to autonomous: the autonomy dial this course uses.
Further reading
- Docs Tool use with Claude · Anthropic docs. The exact message format for tool definitions, tool_use blocks and tool_result blocks.
- Docs Function calling · OpenAI API docs. The same idea in OpenAI's API, useful for seeing what every provider has in common.
- Docs Pydantic documentation · Pydantic. Models, validators and JSON Schema generation: the validation layer used throughout this course.
- Docs Understanding JSON Schema · JSON Schema. What tool and output schemas are written in; read the sections on types, enums and required fields.
GitHub repositories
- openai/openai-python: The tool-calling examples and the types for tool_calls and tool messages.
- pydantic/pydantic: model_json_schema() and model_validate_json(): the two calls you’ll use for every tool.
- anthropics/claude-cookbooks: The tool-use notebooks: the same loop in Anthropic’s message format.
Checkpoint quiz
Interview questions
- Walk me through one round of tool calling, message by message.
- How do you validate tool arguments, and what do you send back on failure?
- What are parallel tool calls and when do they help?
- When is an agent the wrong solution?
- How would you measure a baseline before building a complex agent?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).