01. Introduction to Agentic AI
How Does Agentic AI Work?
Agentic AI works as a control loop: take a goal, observe context, think/plan, act with tools, check results, and repeat until done, budgeted, or escalated.
What you will learn
- Explain the Agentic AI runtime loop end to end
- Name what each layer does: orchestrator, model, tools, memory, guardrails
- Describe how tool calls are proposed, validated, and executed
- List stop conditions and failure handling
- Walk through a concrete coding-agent example
- Answer interview questions with short, solid answers
Definition
Agentic AI works by running a goal-seeking control loop. The system observes the current state, reasons about the next useful step, takes an action (often a tool call), checks the outcome, and continues until success criteria, limits, or human escalation stop it.
A generative model may power the “think” step. Software around the model — orchestration, tool runtimes, memory, and policies — makes the loop real and safe.
If there is no loop and no actions beyond text, you mostly have Generative AI chat, not a working agentic system.
Introduction
This lesson (#7 in Introduction to Agentic AI) answers the practical question after definitions and characteristics: what actually happens at runtime?
You will map the loop, the software stack under it, how tools execute, when the system stops, and a concrete coding-agent walkthrough you can reuse in interviews.
Why understanding the loop matters
- Debugging: failures live in observe, decide, act, or check — not “the AI” as a blob
- Safety: you know where to put permissions and approvals
- Cost: each loop iteration spends tokens and tool time
- Design: you can choose single-turn GenAI vs a real agent loop
The runtime loop (step by step)
Every serious agentic system is a variant of this cycle. Frameworks differ in APIs; the loop shape stays stable.
- Start with a goal and constraints (tools allowed, time/cost budget, risk level)
- Observe — build context from user input, memory, docs, and prior tool results
- Think — model/planner chooses reply, clarifying question, or tool + arguments
- Act — runtime validates and executes the action
- Check — evaluate success, errors, and budgets
- Loop or stop — continue, finish, or escalate to a human
What runs under the loop
The loop is implemented as layered software. Missing a layer usually means a demo, not production.
- Orchestrator — control flow, retries, routing, stop rules
- Reasoning model — plans and proposes actions (often an LLM)
- Tools/connectors — APIs, search, code runners, DBs, browsers
- Memory/logs — short-term state, transcripts, optional long-term store
- Guardrails — authz, schemas, rate limits, human approval
How tool calling works
Tool use is how agents change the world. The model proposes a tool name and arguments; your runtime must treat that proposal as untrusted input.
- Register tools with names, descriptions, and JSON schemas
- Model emits a structured tool call (not free-form shell by default)
- Validate arguments against the schema and policy
- Execute in a sandbox with timeouts
- Return the observation to the model as the next context
- Never let the model silently escalate privileges
Planning styles inside “Think”
Different products plan differently. Interleaved reason-and-act (ReAct-style) is common. Some systems plan a full DAG first, then execute. Others route to specialized workers.
- Reactive step-by-step — decide one action, observe, repeat
- Plan-then-execute — outline steps, then run with revisions
- Router / supervisor — pick a specialist agent or tool path
- Human-in-the-loop — pause for approval on risky steps
Stop conditions and failure handling
A working agent knows how to stop. Infinite loops are a design bug, not an inevitable AI mystery.
- Success — done criteria met (tests green, brief delivered, ticket updated)
- Budget — max steps, tokens, wall-clock, or money spent
- Policy block — tool denied; escalate or replan
- Hard error — tool down; retry with backoff or fail closed
- User cancel / human takeover
Worked example: coding agent
Map the abstract loop onto a familiar scenario so it sticks in interviews.
- Goal: make the failing test suite pass within N steps
- Observe: read failing assertions and stack traces
- Think: hypothesize root cause; choose file edits
- Act: apply patch tool; run tests tool
- Check: if green, stop; if red, loop; if budget hit, escalate with a summary
How this differs from plain GenAI chat
- Chat — one (or few) completions; user pastes context manually
- Agentic — system fetches context via tools and continues without hand-holding
- Chat — success is “good answer text”
- Agentic — success is “goal state reached” in an external system
Program / implementation notes
Implement the loop as explicit state: messages, scratchpad, tool results, step count. Prefer typed tool interfaces. Log every transition for debugging and evals.
Start thin: one model, two tools, strict max steps. Add memory and multi-agent routing only when a single loop is insufficient.
- Store state as data you can inspect (not only hidden chain-of-thought)
- Unit-test tool adapters separately from the LLM
- Add idempotency for write tools when possible
- Build an eval suite of tasks with expected end states
- Measure step count and cost per successful goal
Advantages and limitations of the loop design
- Advantage: can finish multi-step work with live data and tools
- Advantage: debuggable stages (observe/think/act/check)
- Advantage: composable with HITL and policies
- Limitation: more latency and cost per goal than one-shot GenAI
- Limitation: tool failures and bad observations cascade
- Limitation: poor stop rules create loops and surprise bills
Key points
- Agentic AI works as a goal-seeking loop: observe → think → act → check.
- LLMs often propose; runtimes validate, execute tools, and enforce stop rules.
- Stack: orchestrator + model + tools + memory/logs + guardrails.
- Tool calls need schemas, permissions, timeouts, and logged observations.
- Stop on success, budget, policy block, hard error, or human cancel.
- Same loop powers coding, research, support, and ops — tools differ.
FAQs
Is the LLM the whole agent?
No. The LLM is usually the reasoning component. Orchestration, tools, memory, and guardrails make Agentic AI work as a system.
Do all agents use ReAct?
No. ReAct-style interleaved reason-and-act is common, but plan-then-execute, routers, and multi-agent graphs are also used.
Why can agents get stuck in loops?
Weak done checks, repeated failing tool calls, or no step/cost budget. Fix with stop rules, retries limits, and escalation.
Where should human approval sit in the loop?
Typically before high-impact Act steps (writes, payments, deletes) or when policy confidence is low — after Think, before execute.
Interview questions
- How does Agentic AI work at a high level?
Answer It runs a loop: observe context, think/plan, act with tools, check results, and repeat until the goal is done, limited, or escalated.
- What is the role of the LLM in that loop?
Answer It usually handles reasoning — choosing next steps, wording replies, and proposing tool calls — while the runtime executes and constrains actions.
- How does tool calling work safely?
Answer The model proposes a structured call; the runtime validates schema and permissions, executes with limits, and returns the observation to the loop.
- When should an agent stop?
Answer When done criteria are met, budgets are exhausted, a policy blocks action, a hard error persists, or a human cancels or takes over.
- Walk through a coding agent example.
Answer Observe test failures, think of a fix, act by editing and re-running tests, check pass/fail, and loop or escalate based on results and budget.
- How is this different from a normal chatbot?
Answer A chatbot mainly generates text responses. Agentic systems take multi-step actions toward a goal using tools and state checks.
- What fails most often in practice?
Answer Bad observations, invalid tool args, missing stop rules, and unclear goals. Logs for each loop stage make these failures visible.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Draw Goal → Observe → Think → Act → Check and write one sentence under each box.
- List four stop conditions you would enforce in any agent you ship.
- For a support agent, name two read tools and one write tool; mark which needs approval.
- Write a 5-step coding-agent story aloud in under 60 seconds.
- Answer interview questions 1, 3, and 5 in two sentences each.