Phase 4 — Agentic AI Engineering
An agent is a language model placed inside a loop, given tools, memory, and a goal. Instead of answering once, it acts: it decides what to do, calls a tool, looks at the result, and decides again — until the task is done or it decides to stop.
This is where AI systems stop being text generators and start doing work. It is also where most of the hard engineering lives. A single model call fails in simple ways; an agent loop fails in compound ways — it loops forever, calls the wrong tool, loses state, corrupts memory, spends money, or takes an irreversible action with no approval. This phase builds the machinery that makes agents reliable: loops, state, memory, planning, tools, permissions, checkpoints, human approval, and orchestration patterns.
What you will be able to do
By the end of this phase you should be able to:
- Explain what an agent is and, more importantly, when not to build one.
- Implement the observe → reason → act loop with tool execution and result validation.
- Design memory: short-term, working, long-term, episodic, and semantic.
- Plan, decompose, route, reflect, and self-correct.
- Prevent infinite loops, manage retries, and terminate cleanly.
- Persist state, checkpoint, and support durable, long-running, resumable agents.
- Add human-in-the-loop approval and guardrails around dangerous actions.
- Define tool schemas, selection, and permissions safely.
- Build with LangGraph (nodes, edges, reducers, checkpoints, interrupts, subgraphs) and the OpenAI Agents SDK.
- Choose among ReAct, plan-and-execute, router, supervisor, worker, evaluator, and critic patterns.
The agent loop
flowchart TD
G["Goal"] --> O["Observe<br/>state + tool results"]
O --> R["Reason<br/>what next?"]
R --> D{"Decide"}
D -->|"call a tool"| T["Act<br/>execute tool"]
T --> V["Validate result"]
V --> O
D -->|"answer"| A["Terminate<br/>return result"]
D -->|"need a human"| H["Approval"]
H --> O
R -.->|"remember"| M["Memory"]
M -.-> O
O -.->|"checkpoint"| C["Durable state"]
Everything in this phase is one of four concerns: what the loop does (planning, reasoning), what it remembers (state, memory, checkpoints), what it can touch (tools, permissions), and how it stays safe and stops (guardrails, approvals, termination, reliability).
Topic order
- What an AI agent is — and when a plain workflow is better.
- The agent loop — observe, reason, act.
- Tool execution and result validation — acting safely on the world.
- Agent memory: short-term and working — what is in context right now.
- Agent memory: long-term, episodic, semantic — what survives the run.
- Planning, decomposition, and routing — breaking a goal into steps.
- Reflection and self-correction — catching your own mistakes.
- Retries, termination, and loop detection — knowing when to stop.
- State management and persistence — the single source of truth.
- Checkpointing and durable execution — surviving restarts.
- Human-in-the-loop and approvals — putting a person in the path.
- Guardrails — bounding what the agent can do.
- Structured agent outputs — machine-checkable actions.
- Tool schemas and selection — describing and choosing tools.
- Tool permissions — least privilege for agents.
- Parallel and conditional workflows — direction and fan-out.
- Long-running and background agents — work beyond a request.
- LangGraph: graphs and state — nodes, edges, reducers.
- LangGraph: checkpoints, interrupts, subgraphs — durable and human-aware.
- OpenAI Agents SDK — the batteries-included alternative.
- Agent orchestration patterns — ReAct, plan-and-execute, supervisor, worker, critic.
- Agent reliability — making agents dependable in production.
Tip:
How to study this phase. The recurring theme is that agents are distributed systems with a stochastic component. Every time you add a capability, ask: what happens when it fails halfway, runs twice, or returns something invalid? If you can answer that, you can build production agents.
Checkpoint project
At the end of the phase, build Project 2 — Autonomous Enterprise Workflow Agent: a LangGraph agent that plans, uses tools, checkpoints, pauses for human approval, resumes durably, and reports. The exact scope lives in the projects part of the book.