Skip to content
AI Agents

Understanding AI Agents Through Practical Examples

Distinguish chat, a fixed workflow, and an agent through a fictional stock lookup with observations and stopping rules.

Overview

For learners who want to complete this practical exercise with inspectable sample data and explicit checks.

  • Map the goal, decision, tool, and observation loop.
  • Distinguish a proposed action from application execution.
  • Set turn budgets and permission boundaries.

You will build: A trace containing a tool, observation, answer, and explicit stopping condition.

Prerequisites

  • A text editor; optionally Python 3 for the simulation.

The conceptual exercise and simulation run offline without an account or API. A fixed-rule simulation must not be presented as an LLM agent.

Step-by-step tutorial

Conceptual practice workflow; not measured results.

Step 1. Compare three ways to solve one task

Task: report DEMO-PEN stock in a training inventory. Chat without tools can only use conversation data. A fixed workflow always executes its prescribed sequence. An agent chooses actions based on a goal and observations and may ask for clarification or stop. Merely adding an LLM does not turn every workflow into an agent.

Step 2. Define permissions and data

TEXT
Goal: answer the training stock question
Allowed tool: lookup_stock(sku), read-only
Fixture: DEMO-PEN = 7; DEMO-BOOK = 0
Unknown SKU: missing, never zero by assumption
Budget: at most 3 decisions
Forbidden: purchases, database writes, shell commands

Distinguish zero known stock from missing data. For changing facts, a tool observation is preferable to model memory, but the tool still needs permission and source checks.

Step 3. Run an explicitly labeled simulation

PYTHON
stock = {"DEMO-PEN": 7, "DEMO-BOOK": 0}
question_sku = "DEMO-PEN"
observation = None
for turn in range(3):
    if observation is None:
        observation = {"found": question_sku in stock,
                       "units": stock.get(question_sku)}
        print("TOOL", observation)
    else:
        answer = str(observation["units"]) if observation["found"] else "unknown"
        print("FINAL fictional stock:", answer)
        break
else:
    raise RuntimeError("turn limit")

This is a rule-based controller without model inference or API calls. Use it to read a trace and test stopping before the next tutorial’s actual model-driven Python agent. Change the SKU to DEMO-BOOK and then MISSING to compare zero with unknown.

Step 4. Read the trace and identify human decisions

Record each input, proposed tool, result, and stop condition. A change from “check stock” to “purchase” requires a new permission; do not silently add a writing tool. If the SKU is missing, request it rather than guessing a similar product.

PROMPT · INSTRUCTIONS
Review this trace. Identify tool-supplied data, controller decisions, and cases that must stop or ask for clarification. Add no purchasing or data-writing actions.

Verification

  • Identify the simulation and do not claim it uses an LLM.
  • DEMO-BOOK returns 0, MISSING returns unknown, and execution is bounded.

Troubleshooting

Every chatbot is called an agent

Cause: No action/observation loop has been identified.

Fix: Map actual steps and identify where a model can choose an action.

Missing data becomes zero

Cause: The found state is conflated with units.

Fix: Keep found=false and return unknown instead of inferring stock.

Exercises & extensions

  • Write a trace for two SKUs and define its maximum tool-call count.
  • Continue to the Python agent to replace fixed decisions with the Responses API.

The simulation measures no model autonomy, accuracy, or reliability. Every inventory value is fictional.

References

  1. OpenAI function calling
  2. Python control flow

Keep practicing