Most AI agent tutorials start with a framework. This book starts with the loop.
An agent is a model in a loop: it decides, acts through a tool, observes the result, and decides again. Most agent frameworks abstract that loop. Learn the framework first, and when something breaks - a malformed tool call, a runaway loop, unexpected cost - you may find yourself debugging an abstraction you never fully understood.
Agentic Python teaches you to build production AI agents in plain Python, calling model APIs directly over HTTP. Across 18 chapters, you build one real application: a research assistant that finds sources, reads them, cites them, and says so when it isn't sure. Each chapter adds one capability, and every code listing comes from a companion GitHub repository with a full test suite that runs offline.
You'll learn how to:
- Run the same agent on Anthropic or OpenAI through one interface, so switching providers is a configuration change
- Get reliable structured output with schemas, validation, and automatic repair
- Build tools, a dispatch table, and the core agent loop from scratch
- Give your agent persistent memory with Postgres and pgvector, and search your own documents
- Plan multi-part questions, coordinate specialist agents, and require human approval before risky actions
- Use and expose tools over the Model Context Protocol (MCP), implemented by hand and interoperability-tested against the official MCP Python SDK
- Add retries, timeouts, guardrails, tracing, and replay
- Build a realistic evaluation dataset that checks citations against what the agent actually read, with a regression gate that runs in CI
- Defend against prompt injection, scope tool permissions, and sandbox model-generated code
- Ship the system as an authenticated API with per-user budgets, structured logs, and Docker deployment
Once you understand the loop, you rebuild part of the assistant in LangGraph, side by side with your own code, and test that both implementations produce the same result. Frameworks make sense once you know what they abstract.
Written for Python developers who are new to agents. No machine learning background required.