From answering a question to carrying out a task
Agentic AI combines a model with instructions, tools, context, memory, state, and guardrails so the system can work toward a goal across several steps. Unlike an ordinary chatbot that normally returns one response, an agent can decide what to do next, act through approved tools, inspect the result, and continue or stop. A workflow follows developer-defined steps; an agent is used only where the next step must be chosen from changing, open-ended information.
What You Will Learn
- Distinguish ordinary code, fixed workflows, and agentic decisions.
- Trace the bounded decide–act–observe loop used by an agent.
- Place common agent types on an autonomy spectrum without memorising labels.
- Choose the least autonomous design that can solve a task reliably.
What changes when software becomes agentic?
Ordinary software follows instructions chosen by a developer. A workflow may contain branches, but the permitted route through those branches is still designed in advance. An agent adds a model-directed decision point: after seeing the current evidence, the model may choose which approved action should happen next.
That freedom is bounded. The application still decides which tools exist, what each tool may access, which actions need approval, how much time or money may be spent, and when the loop must stop. The model proposes the next move; it does not grant itself authority.
Follow one bounded agent run
Receive a goal, trusted instructions, and the current context or state.
Decide the next safe action: answer, use a tool, ask for clarification, or stop.
Execute an approved tool and treat its result as a new observation.
Update state, check progress, and repeat only while the goal remains unfinished and budgets allow.
Vary the design only as needed: a reflex-style agent reacts, a stateful agent remembers the environment, and a goal- or utility-based agent compares possible outcomes.
Prefer ordinary code or a fixed workflow when the rules and branches are already known; autonomy is useful only when flexibility justifies its extra cost and risk.
Instructional figure
The bounded agent loop
How does an agent turn a goal into a sequence of controlled actions?
Choose the simplest control style that fits the task
Agent types are points on a spectrum
A reflex agent reacts only to the current observation. A model-based agent also maintains a representation of the environment. Goal-based and utility-based agents compare possible outcomes, while learning agents improve a decision rule from experience. An LLM agent uses a language model to interpret open-ended context and select among tools or responses.
These names are useful examples, not a checklist that every product must implement. A support system may combine deterministic validation, a fixed approval workflow, and one small LLM-directed search decision. What matters is where autonomy is genuinely needed and how it is controlled.
Instructional figure
Autonomy is a continuum, not an on/off switch
Where do code, workflows, and common agent types sit as decision freedom increases?
A Realistic Example: Choosing the right amount of autonomy for a support request
Code can validate required ticket fields, and a fixed workflow can enforce refund limits. An agent is useful only for the ambiguous middle: it may inspect the order, search the relevant policy, ask for missing evidence, and propose a resolution. A high-value refund still pauses for human approval.
Read the Mechanism in Code
Use the label and note to understand what this block represents before reading each line.
agent = {
"instructions": support_policy,
"tools": [get_order, search_policy],
"state": {"goal": ticket, "steps": 0},
"limits": {"max_steps": 6, "can_issue_refund": False},
}
while not goal_complete(agent["state"]):
decision = model.choose_next_action(agent)
if decision.requires_approval:
return request_human_review(decision)
observation = execute_validated(decision, agent["tools"])
agent["state"] = update_state(agent["state"], observation)Hands-On Runnable Python Lab: Run a Two-Lookup Delivery Agent
The first source is stale. The second contains a current Friday delivery estimate. Each lookup costs one action from a budget of two; checking whether the result is usable does not consume another lookup.
- Read the cached record. It says Thursday, but current=False prevents using it as the answer.
- Inspect the failed evidence check and choose the live record as the next permitted source.
- Accept Friday only when the current flag is true. Stop immediately rather than spending another action.
- Run a second fixture with two stale records. The same controller must abstain instead of inventing a date.
Observations determine whether to continue or stop
The successful fixture uses the stale cache first and the current service second. The loop never gets a third lookup. If both records are stale, it abstains.
def run_agent(records, limit=2):
trace = []
for step, record in enumerate(records[:limit], start=1):
trace.append(
f"lookup {step}: {record['source']} "
f"current={record['current']}"
)
if record["current"]:
return "success", record["date"], trace, limit - step
return "abstain", "No current delivery estimate", trace, max(0, limit - len(trace))
cached = {"source": "cache", "date": "Thursday", "current": False}
live = {"source": "order service", "date": "Friday", "current": True}
for name, records in [("Supported", [cached, live]), ("Unsupported", [cached, cached])]:
status, answer, trace, remaining = run_agent(records)
print(name)
print("\n".join(trace))
print(f"{status}: {answer}; remaining={remaining}")
Supported
lookup 1: cache current=False
lookup 2: order service current=True
success: Friday; remaining=0
Unsupported
lookup 1: cache current=False
lookup 2: cache current=False
abstain: No current delivery estimate; remaining=0What This Run Shows
- The stale record is rejected because of an explicit rule, even though it contains a plausible date.
- The second action is justified by the first observation. This is the smallest useful adaptive loop.
- Both success and abstention terminate normally; a safe refusal is not an infinite retry.
A more capable language model could choose better queries, but it should not be allowed to bypass this boundary. First prove that the controller stops and accepts only adequate evidence; then replace the simulated decisions with model proposals.
From the Exercise to an Application
Experiment: Reduce the lookup limit from 2 to 1. Does the supported case still succeed?
No. Only the stale cache is inspected, so the controller abstains. This makes the trade-off visible: an action budget bounds cost but can also prevent useful completion.
Summary / Key Takeaways
- An agent is a bounded system in which a model helps decide what to do next while working toward a goal.
- Ordinary code is best when rules are deterministic; workflows are best when branches are known; agents are useful when the next step depends on open-ended context.
- A practical agent loop is goal → decide → act through permitted tools → observe → update state → continue or stop.
- Agent types such as reflex, stateful, goal-based, utility-based, learning, and LLM-powered agents describe different decision machinery, not a ladder where more autonomy is always better.
- Tools, context, memory, state, instructions, budgets, and guardrails are supporting parts of an agent system; none of them alone makes a system an agent.
- Autonomy adds latency, cost, and failure paths, so the design should use the least autonomy that solves the problem.
- A good agent has explicit success conditions and stop conditions so it can finish, abstain, or return control to a person.
Verified Further Reading
These primary research papers and current official specifications support the concepts and implementation guidance in this lesson. The explanations, analogies, exercises, and code above remain original teaching material.
ReAct: Synergizing Reasoning and Acting in Language Models
Original research on interleaving task reasoning with external actions and observations.
Hugging Face Agents Course: Introduction to Agents
Official course covering tool use and the thought-action-observation cycle.
OpenAI: A practical guide to building agents
Primary guidance on agent suitability, orchestration, tools, guardrails, and human intervention.