AI agents and MCP

Stage 2 · Lesson 2 of 7

The tool call and result round trip

Tool calling from scratch

When the model wants a tool, it replies with a instead of text: an id, the tool name and the arguments as . With Anthropic's API the reply has stop_reason set to tool_use and contains tool_use blocks. Your code runs the tool, then sends a new request that includes the model's reply unchanged plus a tool result that quotes the same id.

With OpenAI's the pieces are called function_call and function_call_output, matched by call_id. The id matters because one reply can contain several calls, and the model must know which result belongs to which request. The model never runs anything itself: your code decides what actually executes.

Common trapdropping the model's tool call message before adding the results, which the API rejects or the model misreads.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

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

Mark this stage as not done?