Skip to content

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.

Task + contextsystem, tools, historyModel calltool call or answer?toolApproval gateonly for risky actionsRun toolresult or errorappend the observation to the context, then call the model againanswer → stopAlso stop on: step limit, token or cost budget, repeated identical calls (a loop)
An agent is this loop. Everything else in the course (state, memory, MCP, multi-agent, evals) makes the loop safer or smarter.

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.

Common misconception: “The model runs the tool.” It never does. It asks; your code decides whether to run it, with what permissions, and what to send back.

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.

In production: Record the baseline’s task success on five sample incidents now. Every later module reports against it.

Hands-on: coding window

The coding window and the full VS Code lab are available after you sign in.

Sign in to code

Labs

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

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

Checkpoint quiz

1. Who executes a tool call?
2. How do you match a tool result to its call in OpenAI-compatible APIs?
3. The model sends an invalid argument. Best response?
4. Why generate the JSON Schema from a Pydantic model?
5. Which modules does the diagnostic say everyone should do?

Interview questions

  1. Walk me through one round of tool calling, message by message.
  2. How do you validate tool arguments, and what do you send back on failure?
  3. What are parallel tool calls and when do they help?
  4. When is an agent the wrong solution?
  5. 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).