Phase 10 · Agentic AI/
Lesson 10.2core3 h⚡ live demo

Tool use and function calling

Schemas, the tool-result loop, errors, code execution and computer use

Tools are how a model's words become actions. The function-calling interface is the same everywhere: you describe functions with JSON Schema, the model emits a structured call, you run it and feed the result back. Getting this loop right — including parallel calls, errors, budgets and good tool descriptions — is the single most reusable skill in agent engineering; every framework in 9.10 Frameworks and SDKs and 10.6 Multi-agent systems is a wrapper around it, and MCP (10.7 MCP and interoperability (plus Agent Skills and A2A)) is a protocol for sharing it.

You'll be able to

  • Define tools with JSON Schema and explain why the description is a prompt
  • Implement the complete tool-call/tool-result loop against the Anthropic or OpenAI API, including parallel calls and error returns
  • Apply Anthropic's tool-design guidance: consolidation, namespacing, meaningful results, token efficiency
  • Explain code execution and computer use as generalized tools and their cost/safety trade-offs

Key ideas

  1. A tool = name + description + JSON Schema; the model emits a structured call, your code executes it and returns a tool result with the matching id.
  2. Anthropic (tool_use / tool_result blocks, stop_reason) and OpenAI (tool_calls / role 'tool') implement the identical loop with different field names.
  3. Tool descriptions are prompts: say when to use and when not to, use enums and required fields, namespace tools, and consolidate near-duplicates.
Show 4 more key ideas
  1. Return high-signal, token-efficient results and send errors back as flagged tool results so the model can recover.
  2. Handle parallel calls (one result per id), cap steps/time/tokens, detect loops, and validate arguments before executing anything.
  3. Code execution turns many tool calls into one and keeps intermediate data out of the context; 'tools as code APIs' reported >98% token savings.
  4. Computer use is a universal but slow, costly and injection-exposed tool interface; prefer APIs or DOM access when available.

Suggested path through this lesson