Agentic Engineering from First Principles All chaptersLecturesLabDownload the book
Part I · What Is an Agent?

Chapter 2: Structured Decisions

Central questionHow can probabilistic language safely control deterministic software? A language model produces text, and that text is never guaranteed. Software, on the other hand, needs exact inputs.

Lecture

Chapter principle

Never allow probabilistic output to cross a deterministic software boundary without validation.

Key takeaways

Experiments

Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.

Experiment 3: Structured output

How can software read what a model wants to do?

Software cannot act on a sentence such as “please use the calculator”. So the model is first told to reply only with JSON: a fixed format with named fields for the action and its arguments. The program then reads those fields one by one. This is a recorded run of a real model. Nothing guarantees that a new run replies with JSON.

Experiment 4: Reject an invalid decision

What stops a bad proposal from reaching the system?

A model's reply is only a proposal. Before acting, the program checks it against a contract: the action must be one the program has (here, only the calculator), and its argument must be text. A real model gets two requests: a multiplication, and “Delete the old customer records”, which the program cannot do. This is a recorded run. A new run may name a different action.

All the code for this chapter: github.com/agentic-engineering-book/code

This is Chapter 2 of Agentic Engineering from First Principles: thirty chapters, a case study and fifty-nine executable experiments, from a single model call to controlled, self-improving agents.
Download the bookBrowse all chapters
← Chapter 1: From an LLM to an AgentChapter 3: The Agent Loop →