Agentic AI Engineering · Module 02 of 16

Inside an Agent

An agent is not magic. It is a loop around a model: observe the current goal and state, decide what should happen next, perform a permitted action, observe the result and either continue or stop.

Engineering focus: Goal, instructions, model, tools, state and the agent loop

In plain English

What problem are we solving?

An agent is not magic. It is a loop around a model: observe the current goal and state, decide what should happen next, perform a permitted action, observe the result and either continue or stop.

Framework names come later. First understand what the application is doing and where its control boundaries belong.

Running case · Operations Investigator

Across the course, imagine an assistant that investigates operational problems using narrow tools. The design progressively adds plans, specialist agents, approvals, reliability controls and MCP while keeping model output separate from execution authority.

Learning objectives

By the end of this module, you should be able to:

  • Identify goal, model, instructions, tools and state.
  • Trace the observe → decide → act → observe loop.
  • Explain why stop conditions and execution boundaries matter.

The five-part mental model

The goal defines success. Instructions constrain behaviour. The model proposes decisions. Tools provide bounded capabilities. State carries the facts needed across steps.

The agent loop is a feedback loop

After a tool runs, its result must become an observation for the next decision. Without that feedback, the application cannot adapt to what actually happened.

Decision and execution are different responsibilities

A model can propose an action, but the application should mediate execution. This separation is where validation, authorization, approval, timeouts and audit controls can be enforced.

Loops need boundaries

Production agents need maximum turns, timeouts, budgets and explicit stop conditions. Otherwise a harmless prototype can become an infinite or expensive loop.

Worked examples

Minimal agent loop

while not finished:
    observation = observe(state)
    decision = decide(observation)
    if decision.kind == "tool":
        result = execute_allowed_tool(decision)
        state.add(result)
    else:
        return decision.answer
  • The model proposes; the application executes.
  • State changes after observations.
  • A stop condition bounds the loop.

Disk investigation

Goal: Is this host low on disk?
→ choose get_disk_usage
→ observe 87% used
→ answer with evidence
  • The tool result changes the final decision.
  • One bounded read-only tool is enough for this example.
Try it · core lab · account-free

Trace observe → decide → act

Goal: See an agent loop execute without depending on an external model.

Before you start

  • Python 3 only. The lab uses a deterministic decision fixture so you can focus on control flow.
STEP 1

Run the simulation

python3 public/labs/agentic-ai/02_observe_decide_act.py
STEP 2

Read each turn

Identify the observation, the decision and the action.

STEP 3

Change the fixture threshold

Modify the disk percentage and predict the final answer before rerunning.

Verify

  • The loop terminates successfully.
  • You can point to where a tool result becomes state for the next turn.

Expected outcome

  • The first turn chooses a disk tool.
  • The second turn answers using the observed disk value.

Break / fix · diagnose

  • If the loop repeats forever, inspect the condition that marks the task finished.
  • If the answer ignores the disk value, verify that the observation includes the tool result.
Production view

Frameworks differ, but reliable agent runtimes still need bounded loops, state transitions, execution mediation and stop conditions.

Avoid these traps

Common mistakes

  • Learning framework syntax before understanding the loop.
  • Letting model output execute directly without a control boundary.
  • Omitting a maximum-turn or stop condition.
Knowledge check

Explain the control decision, not just the vocabulary.

Open every answer only after committing to your own answer. Opening all four answers records knowledge-check activity in My Learning.

1What does the observe step do?

Adds execution results back into the decision context — Observations let the next decision react to what actually happened.

2What prevents an agent loop from continuing forever?

Explicit stop conditions and bounded turns — Production loops require explicit bounds.

3Which item describes what success means?

Goal — The goal defines the desired outcome.

4Why separate decision from execution?

So the application can validate and control actions before executing them — The application must mediate model-proposed actions.

My Learning

Record your progress for this module.

Progress is saved in this browser immediately. When you sign in to My Learning, it can also sync across devices.

Not started

Attempt the core lab and knowledge checks before marking the module complete.