IamBishal
New

Agentic AI series · Book 1 • Free to read • Python

Agentic AI Foundations

From LLM Calls to Your First Agent

Learn how AI agents really work by building one yourself, in plain Python and without a framework hiding the details. You'll write the model client, tool calling and the agent loop, manage context and memory, choose a model, and test your agent with golden tasks and evals. Every chapter works on the same fictional retailer, Kestrel Outfitters, and the code runs locally with a fake model, so you don't need an API key.

  • 16Chapters
  • 600+ testsTested code examples
  • 3.12Python
  • NoneAPI key needed
  • Python developers who have called an HTTP API and want to build AI agents from the ground up. No machine learning background needed.

Updated Nov 28, 2026 · v1.0EnglishFree · HTML

About This Book

Agentic AI Foundations takes you from a single call to a language model to a working, tested AI agent that you understand line by line. No framework hides the moving parts: you write the model client, the tool-calling cycle and the agent loop yourself, in plain Python, and test each piece before you build on it.

Every chapter works on the same realistic company, Kestrel Outfitters, a home and outdoor goods retailer with support tickets, orders, shipments, stock and policies served by a local mock API. The examples answer the kind of questions its staff really ask, so you see where an agent helps, where a fixed workflow is the better choice, and what each design decision costs.

What's inside

  • Part I: What agents are and how models work. The difference between a workflow and an agent, the autonomy spectrum, and just enough about tokens, context windows, sampling and reasoning models to make good decisions. Then the Messages API, system prompts, streaming, and prompts written for agents.
  • Part II: Tools and the agent loop. Structured outputs with JSON Schema and validation, tool calling from first principles, the agent loop with explicit stop rules and run budgets, and how to design tools a model can use well.
  • Part III: Context, models and testing. What goes into the context window and why, short-term memory with summarisation and compaction, how to choose a model on capability, latency and cost, when a framework helps, and how to test an agent with golden tasks, traces and simple evals.
  • Part IV: Capstone. Design, build and harden a research assistant for Kestrel's CTO: it searches, reads files and cites its sources, stays within a cost limit, and ships with an eval suite.

How the code works

Each chapter has its own folder in the companion repository, with runnable code, tests and the exact output shown in the text. Everything runs on your laptop with Python 3.12 and uv: a fake model and the local Kestrel mock API mean you don't need an API key or an account to follow along. Fake-model output is labelled as such in the text. When you want to, you can point the same code at a real model with your own key.

Who it's for

Backend, full-stack and data developers who write Python and have called an HTTP API, and want to build AI agents properly, from the ground up. No machine learning background is needed.

This is book 1 of the free Agentic AI series. Later books cover context, memory and retrieval; tools and protocols (MCP, A2A and Agent Skills); design patterns; multi-agent systems; and running agents in production.

Kestrel Outfitters is a fictional company; any resemblance to real businesses or products is coincidental.

What You’ll Learn

Learning outcomes
  • Tell an agent from a workflowDecide where a task sits on the autonomy spectrum, and choose a plain workflow when an agent would add cost and risk without benefit.
  • Call models with confidenceUse the Messages API, system prompts, streaming and structured outputs, and recover cleanly when a model returns output you can't use.
  • Build tool calling and the agent loopWrite the call/result cycle and the agent loop yourself, with explicit stop rules, run budgets and tool errors returned as results.
  • Engineer context and memoryDecide what goes into the context window, and keep long conversations useful with summarisation and compaction.
  • Choose models and frameworksCompare models on capability, latency and cost, and know when a framework helps and when to keep the loop in your own code.
  • Test before you trustCheck an agent with golden tasks, traces and a small eval suite, and harden it with error handling and cost limits.

Frequently Asked Questions

Is the book really free?

Yes. Every chapter is free to read on iambishal.com, and the companion code is MIT-licensed. The whole Agentic AI series is free.

What do I need to know before starting?

You should be comfortable writing Python (functions, classes, packages, virtual environments), reading JSON and calling an HTTP API. You don't need any machine learning background.

Do I need an API key or a paid account?

No. Every example and test runs on your machine against a fake model and the local Kestrel mock API, and fake-model output is labelled in the text. Tests that call a real model are marked `live` and skipped by default; you can run them later with your own key.

Which model provider and libraries does it use?

The code uses Python 3.12, `uv`, the Anthropic Python SDK, Pydantic and httpx, with model calls behind a small model-client interface. Chapter 11 explains how to choose a model, hosted or open-weight, on capability, latency and cost.

Does it use LangChain or another agent framework?

Not for the main build. You write the loop yourself so you understand every step. Chapter 12 surveys the framework landscape and helps you decide when adopting one is worth it.

Where is the code?

In the public books-code repository on GitHub, one folder per chapter, each with its own tests and a README showing the commands and the expected output.

What is Kestrel Outfitters?

A fictional home and outdoor goods retailer used throughout the series, with support tickets, orders, shipments, stock and policies served by a local mock API. It gives every example a realistic problem to solve. Any resemblance to real businesses or products is coincidental.

What comes after this book?

Book 1 gives you the foundations. The rest of the Agentic AI series builds on it: context, memory and retrieval; tools and protocols such as MCP and A2A; design patterns; multi-agent systems; trustworthy agents; architecture; and running agents in production.

Bishal SahaLet's build together

Have a system to design, or an AI feature to get right?

Tell me about the problem. You'll get a clear, honest view of the best way forward.

  • Reply within 24 hoursOn business days, with my honest view and a next step.
  • Accepting select engagementsArchitecture, AI features and full builds.
  • Remote, worldwideWorking with startups, SMEs and enterprises.