AI agents and MCP

Stage 2 of 10 · 7 lessons · ~2 weeks

Tool calling from scratch

Build the agent loop yourself with one provider API and no framework: define tools, read tool calls, return results and errors, handle parallel calls, then read a second provider to see what is universal.

Start: Defining tools

Lessons· one lesson for each topic, in this order

  1. 1Defining tools
  2. 2The tool call and result round trip
  3. 3Writing the loop in code
  4. 4Tool choice and parallel calls
  5. 5Tool errors the model can recover from
  6. 6Descriptions and result size
  7. 7Reading a second provider

Do this

  • Get an API key from one provider and set a monthly spending limit.
  • Define three tools with clear names, descriptions and schemas.
  • Write the loop with the official SDK and print every call and result.
  • Return error results for a missing record and a timeout, and watch the model recover.
  • Trigger a turn with parallel calls and return all results in one message.
  • Add a step limit and test that it stops a looping run.
  • Read a second provider's tool-calling guide and write down the field mapping.

Start with· follow one of these

  • GuideFree
    Claude Tool Use Documentation

    Anthropic · Intermediate

    Read Overview, Define tools and Handle tool calls, then follow the tutorial that grows one call into a full loop

  • GuideFree
    OpenAI Function Calling Guide

    OpenAI · Intermediate

    The same loop on the Responses API: read it after your first provider to see what is universal

Practise

  • Free notebooks: work through the tool use course, which builds tools and a loop exercise by exercise

  • Runnable function-calling examples to compare with your own loop

Keep handy

Also worth your time

Before moving on: A framework-free agent in your language with three real tools, error results the model can act on, parallel call handling, a step limit and a printed trace of every call, plus a note mapping it to a second provider's API.

Tauseef's advice
Do this stage even if you plan to use a framework. Fifty lines of your own loop will teach you more about agents than a week of framework tutorials. If you want a compact reference while you work, Sefism's LLM APIs cheat sheet at /cheatsheets/llm-apis/ covers the request shapes across providers; this stage goes further into the loop itself.

Mark this stage as not done?