"Give me a lever long enough and a fulcrum on which to place it, and I shall move the world."
Pip, Archimedes-Quoting AI Agent
Chapter Overview
Agents become truly useful when they can interact with external systems: calling APIs, querying databases, executing code, and browsing the web. This chapter covers the mechanisms that enable tool use, from provider-specific function calling APIs (OpenAI, Anthropic, Google) to standardized protocols like MCP (Model Context Protocol) and A2A (Agent-to-Agent Protocol).
You will learn to design tool schemas with proper parameter validation, build and deploy MCP servers that expose tools and resources to LLM-powered agents, implement inter-agent communication using A2A Agent Cards and task lifecycle management, and combine retrieval-augmented generation with agentic tool use for knowledge-grounded agents. The chapter emphasizes production-quality tool design with input validation, error handling, rate limiting, and security controls.
Agents become truly powerful when they can call external tools: APIs, databases, code interpreters, and more. This chapter covers function calling, tool protocols like MCP, and structured output formats that enable reliable tool use. These capabilities are prerequisites for the specialized and multi-agent systems in Chapters 24 and 25.
Learning Objectives
- Implement function calling across major providers (OpenAI, Anthropic, Google) with proper schema design and parameter validation
- Build and deploy MCP servers that expose tools, resources, and prompts to LLM-powered agents
- Explain the A2A protocol lifecycle and design inter-agent communication using Agent Cards and task management
- Design production-quality custom tools with input validation, error handling, rate limiting, and security controls
- Combine retrieval-augmented generation with agentic tool use to build self-reflective, knowledge-grounded agents
Prerequisites
- Chapter 10: LLM APIs (chat completions, message formatting, structured outputs)
- Chapter 22: AI Agent Foundations (ReAct loop, planning patterns, agent architectures)
- Chapter 20: Retrieval-Augmented Generation (vector search, chunking, retrieval pipelines)
- Experience with REST APIs, JSON Schema, and basic Python async programming
Sections
- 23.1 Function Calling Across Providers OpenAI, Anthropic, Google, and open-source function calling APIs. Schema design, parameter validation, multi-step tool chains.
- 23.2 Model Context Protocol (MCP) MCP architecture, servers, resources, prompts, ecosystem (97M+ monthly SDK downloads, 6400+ servers), building custom MCP servers.
- 23.3 Agent-to-Agent Protocol (A2A) Google's A2A protocol, Agent Cards, task lifecycle, inter-agent communication standards, and federation patterns.
- 23.4 Custom Tool Design: Validation, Error Handling & Security Building production-quality tools with input validation, error handling, rate limiting, authentication, and security best practices.
- 23.5 Agentic RAG: Retrieval-Augmented Agents CRAG, Adaptive-RAG, knowledge-grounded agents, self-reflective retrieval, and combining RAG with tool use.
What's Next?
In the next chapter, Chapter 24: Multi-Agent Systems, we explore how to coordinate multiple specialized agents to tackle complex tasks.
