LATENT LIBRARY AI ENGINEERING AI Agents inPractice Designing Assistants That Plan, UseTools and Stay Safe LATENT LIBRARY EDITORIAL

AI Agents in Practice

Designing Assistants That Plan, Use Tools and Stay Safe

Latent Library Editorial

IntroductionIntroduction

A chatbot answers. An agent acts. Ask an agent to "find the three invoices that are overdue, draft reminder emails and put them in my outbox for review", and it decides which steps to take, calls tools to search the accounting system and the email client, inspects what comes back, recovers when something fails, and stops when the job is done.

That shift from producing text to taking actions is powerful. It is also where most of the new risk lives. An agent that misreads an instruction does not just write a wrong sentence; it may send the wrong email, delete the wrong file, spend money, or loop for an hour accumulating costs. Text that the agent reads along the way, from web pages, documents or emails, may even try to steer it.

This book is a practical design guide for building agents that are genuinely useful and safely bounded. It assumes you are comfortable with language models and basic programming, and uses language-neutral pseudocode.

A design review worksheet, exercises with answers and a glossary close the book.

Chapter 1What Makes Something an Agent

A spectrum, not a switch

It helps to think of AI systems on a spectrum of autonomy:

LevelDescriptionExample
0. Single callOne prompt, one responseSummarise this document
1. Fixed workflowCode calls the model in predefined stepsExtract fields → validate → write to database
2. RouterThe model chooses one of several predefined pathsClassify a ticket and send it to the right workflow
3. Tool-using agentThe model decides which tools to call, in what order, how many timesResearch a question across search, documents and a calculator
4. Long-running autonomous agentWorks for long periods on open-ended goals, with many toolsInvestigate and fix a software bug across a codebase

The defining feature of an agent (levels 3–4) is that the model controls the flow: it decides the next step based on what it has observed so far. In a workflow, your code controls the flow.

The essential ingredients

  1. A model capable of reasoning about goals and tool results.
  2. Tools: functions the model can request, which your code executes.
  3. A loop that feeds tool results back to the model until it finishes.
  4. Instructions: the goal, constraints and policies.
  5. State and memory: what has been done so far, and what persists.
  6. Guardrails: limits on what can happen, and when a human must approve.

Do you need an agent?

Agents pay off when the path to the goal genuinely varies from case to case, and when steps depend on information discovered along the way. They are a poor fit when the steps are known in advance, since a fixed workflow is cheaper, faster, more predictable and easier to test.

Ask:

You have reached the end of the free sample.
The full book continues with 16 more chapters, plus everything else in its 81 pages.

Get the full book