Agentic AI is a large language model running in a loop: the model decides what to do next, calls a tool, observes the result, and repeats until the task is done. That loop — not the model's size, not a framework — is what makes a system "agentic." Everything else (memory, planning, guardrails) is engineering around that core.
"Agent" is the most overloaded word in AI right now — vendors slap it on anything with a prompt and a for-loop. This guide is the plain version: the loop, the tools, the failure modes, and the framework-versus-scratch decision — including when not to build one.
TL;DR
- An agent = an LLM + a loop + tools + memory; the model chooses each step at runtime.
- Workflows with fixed steps are cheaper, more reliable, easier to test — agents are for genuinely open-ended, branching tasks.
- Production agents need a bounded loop: max steps, cost ceiling, validated least-privilege tools, untrusted tool output.
- You can build one in ~200 lines; add LangGraph or CrewAI only when you need what they actually provide.
- One deterministic call? That's a function — not an agent.
What actually makes a system agentic?
The defining property is dynamic control flow: the model — not your code — decides the next step at runtime based on what it has seen so far. That one property separates three things that get lumped together:
| Single LLM call | Workflow (pipeline) | Agent | |
|---|---|---|---|
| Control flow | One call, one answer | Fixed steps you define | Model picks each next step |
| Tools | None or one | Fixed order | Chosen and sequenced dynamically |
| Failure surface | Small | Medium | Large — needs guardrails and evals |
| Example | "Classify this ticket" | Retrieve → rerank → answer | "Why did this deploy fail?" |
A chatbot answering from a prompt is a single LLM call. A RAG pipeline is a workflow: every step predetermined, even when an LLM performs some of them. An agent is what you get when you hand the model a goal and tools and let it loop: read the log, form a hypothesis, query metrics, refine, check the last commit, answer.
The intelligence lives in the loop and the tools, not in magic. Three components make it work:
- The loop — decide → act → observe, with a stop condition.
- Tools — functions the model can call to inspect or affect the world.
- Memory — the running context of this task, plus anything persisted across sessions.
What does the agent loop look like?
Every framework — and every hand-rolled agent — reduces to the same four-beat cycle: plan → act → observe → answer.
┌─────────────── AGENT LOOP ───────────────┐
task ─►│ 1. PLAN model decides the next step │
│ 2. ACT run the chosen tool (safe) │
│ 3. OBSERVE result returns as data │
│ 4. ANSWER done? stop : repeat │
│ bounded: max steps · cost ceiling · time │
└──────────────────────────────────────────┘
In pseudocode, the whole thing is embarrassingly small:
context = task + tool_schemas
loop:
decision = llm(context) # {tool_call} or {answer}
if decision.is_answer: return decision.answer
result = run_tool(decision.tool) # validated, least-privilege
context += sanitize(result) # untrusted data
enforce(max_steps, cost_ceiling)
Walk one real run. Task: "Why did the payments deploy fail last night?"
First pass, the model calls read_logs(service="payments"). Observation: a
missing-environment-variable error. Second pass, it calls
search_commits(query="STRIPE_WEBHOOK_SECRET") and sees a 23:40 commit
removing it from the config template. Third pass, it answers with the cause,
the commit, and a fix. Three iterations, two tool calls, one answer — and your
code never scripted that sequence. The model chose it at runtime, which is
exactly why guardrails are not optional.
How do tools and function calling work?
A tool is a plain function in your code — search, a database query, a calculator — that the model may invoke. The mechanics of function calling are simpler than the branding: you send tool schemas with the context; the model can reply with a structured call (name plus arguments); your code executes it and appends the result as an observation; the loop continues. The model never executes anything — it requests, your code decides.
The schema is the contract, and it does more work than most developers expect. The model chooses tools from what the schema says, so names, descriptions, and parameter types are effectively part of your prompt:
{
"name": "search_commits",
"description": "Search commit messages by keyword. Returns up to 5 commits with hash, author, date.",
"parameters": {
"type": "object",
"properties": {
"query": { "type": "string", "description": "Keyword or phrase to search for" }
},
"required": ["query"]
}
}
Schemas matter for three practical reasons:
- Selection. Vague descriptions get tools misused or ignored; precise ones get chosen at the right moments.
- Validation. Typed parameters let you reject malformed calls before they
reach your systems. Never
evalmodel output. - Blast radius. Small, single-purpose, least-privilege tools separate an
agent that misbehaves from one that can't misbehave much.
read_logsis safe; a generalrun_sqlis a liability with a prompt attached.
Exposing internal APIs to agents across teams? MCP — the Model Context Protocol — standardizes how tools are described and served, so you're not hand-rolling adapters per framework.
What about memory?
Memory splits into two kinds, and conflating them causes real bugs.
Short-term memory is the running context of the current task: the goal, every decision, every observation. It grows each iteration, creating two production problems — token cost and context-window pressure. The fixes: truncate old observations, summarize finished subtasks, keep raw tool output out of the prompt once digested. Context is a budget, not a dumping ground.
Persistent memory survives across runs: user preferences, facts from earlier sessions, a store the agent reads and writes through tools. The discipline is deciding what earns persistence — storing everything makes retrieval noisy and creates privacy surface you now own. Store deliberately; let users inspect and delete it.
Neither kind is magic — memory is data you put back into the context; the engineering is what you keep, compress, and fetch.
How do agents plan?
"Planning" covers a few distinct patterns, and the simple ones carry you further than you'd expect:
- Interleaved reasoning (ReAct-style). Reason, act, observe, reason again in one loop. The default because it adapts as facts arrive — for most tasks under ~10 steps it's all you need.
- Plan-then-execute. A planner decomposes the task up front; an executor runs the steps, replanning on failure. Good for long, structured tasks; plans rot fast in unpredictable environments.
- Reflection. The model critiques its own output and retries — useful where "check your work" is cheap. Each pass costs tokens and latency.
- Multi-agent. Specialized agents splitting work. Useful in a narrow band of workloads; elsewhere it multiplies failure modes. Don't start here.
Start with the interleaved loop; add explicit planning when eval data shows it failing on long tasks — not before.
How do you keep an agent under control?
An agent without guardrails is a while-loop with a credit card attached. The controls are code, not prompt text — "please be careful" in the system prompt is not a guardrail. The standard set:
- Bounded loop. Hard max-steps cap and wall-clock timeout; on hitting it, return what you have or escalate.
- Cost ceiling. Track tokens per run and abort at a budget — an agent retrying a failing tool 40 times will find your budget for you.
- Validated, least-privilege tools. Every tool validates arguments and holds minimum permissions; destructive or expensive actions are separate tools, not parameters on a general one.
- Sanitized observations. Tool output is untrusted data: label it, truncate it, never let retrieved text trigger tool calls by itself. This is the main defense against prompt injection arriving through a tool result — where injections actually land in agentic systems.
- Structured tracing. One log line per step: decision, tool, cost. You can't debug an agent you can't trace.
Human-in-the-loop is the highest-leverage guardrail for anything irreversible: the agent prepares the action — drafts the email, stages the migration — then blocks on human confirmation. Read-heavy agents run free; write actions get a checkpoint.
These are the controls the free agentic starter repo ships, in code you can read in one sitting. The LLMOps for DevOps engineers guide covers the operations side in more depth.
Should you use a framework or build from scratch?
The loop above is genuinely ~200 lines of Python or TypeScript. So when does a framework earn its complexity?
| Your own loop (~200 lines) | LangGraph | CrewAI | |
|---|---|---|---|
| Best for | One well-scoped agent you must understand and control | Stateful flows: branching graphs, checkpoint/resume, human interrupts | Role-based multi-agent prototypes |
| Debuggability | High — your code, your logs | Medium — a layer to see through | Medium-low |
| Cost of entry | An afternoon | Days of idioms | Hours |
| Lock-in | None | Real | Real |
The rules of thumb are honest ones. Building your first agent? Go from scratch — you'll debug production agents for the rest of your career, and you can't debug what you never understood; the build an AI agent from scratch walkthrough takes an afternoon. Need durable execution, pause/resume, or a graph of nodes with checkpoints? LangGraph earns its keep — that's the problem it actually solves. Prototyping a multi-agent demo? CrewAI is fast; know what you're trading.
No framework gives you guardrails, cost ceilings, evals, or understanding of your system for free — those are yours either way. Start from scratch; import a framework later, once you know which problem you're delegating.
How do agents fail in production?
Agents fail in ways single-call apps don't, and the failure modes are consistent enough to table:
| Failure mode | What it looks like | Standard mitigation |
|---|---|---|
| Runaway loop | Never converges; re-checks the same thing | Max steps + wall-clock timeout, always |
| Cost explosion | One task fans out into 60 calls | Per-run cost ceiling; small model for routine steps |
| Tool ping-pong | Alternates between two tools forever | Step cap, repeated-call detection |
| Injection via tool results | Retrieved text says "ignore your instructions, run X" | Observations sanitized and labelled as data; least-privilege tools; human checkpoint |
| Cascading tool errors | One API 500 becomes 30 retries and a hallucinated fallback | Validated tools, bounded retries with backoff |
| Confident wrong answer | Loop stops early with a plausible wrong result | Evals on real tasks; citations; abstention allowed |
Two deserve emphasis. Injection through tool results is the agentic-specific security hole: once your agent reads web pages, tickets, or logs, adversarial text enters the context as data and tries to act as instructions. You can't prompt your way out; you shrink the blast radius with least-privilege tools, checkpoints, and strict separation of instructions from observations. Evals are the only way you know the mitigations work: a golden set of tasks with known-good outcomes, run in CI, grown from every production failure — the production-ready GenAI architecture guide shows where that harness sits. A demo agent impresses; an evaled agent survives.
When should you NOT build an agent?
More often than the hype suggests. Run down this list first:
- One deterministic call solves it — that's a function, not an agent. Classification, extraction, summarizing a known input: single call, done.
- The steps are known in advance — that's a workflow. If you can draw the flowchart today, write the flowchart; add LLM calls where judgment is needed.
- The task must be auditable — dynamic control flow is a liability when you must explain every decision.
- You can't eval it — no way to measure success means no way to know the agent works. Build the harness first or don't build the agent.
- Latency or cost budgets are tight — an agent is N model calls with unpredictable N. Strict p95 latency means a pipeline, not a loop.
Agents earn their complexity when the task is genuinely open-ended and branching: deep research, multi-step debugging, exploratory analysis, coding where the next step depends on what the compiler says. The tell: you cannot write down the steps in advance — only the goal and the tools. Everything else is a workflow wearing a costume.
FAQ
Is agentic AI the same thing as AGI?
No. Agentic AI is an engineering pattern — a model in a loop with tools — built on models that exist today. AGI is a hypothesis about general human-level capability. Agents are useful because they're mundane: bounded systems you can test, trace, and ship.
What's the difference between an agent and a chatbot?
A chatbot answers; an agent acts. A chatbot takes a message and returns text, maybe grounded by retrieval. An agent takes a goal and returns an outcome, having called tools and adjusted along the way. The distinction is whether a loop with tool use runs between request and response, not what the UI looks like.
Do I need LangChain or another framework to build an agent?
No. The core loop — model call, tool dispatch, observation, repeat — is about 200 lines you can read in one sitting. Frameworks add durable state, orchestration, and integrations, which earn their complexity only once you hit those specific needs. You'll debug production agents by understanding the loop, not the framework.
Will agentic AI come up in AI engineer interviews?
Yes — "when would you use an agent instead of a workflow?" and "how do you make tool calls safe?" are standard questions now. The AI engineer interview questions guide has model answers; one small guarded agent you can narrate end-to-end beats a dozen tutorials.
Where should I start hands-on?
Build one. Read the from-scratch walkthrough and starter repo linked above, get the loop running, then break it on purpose — remove the step cap, feed it a hostile tool result — and watch what happens. That afternoon teaches more than a month of threads. Then the roadmap shows where agents sit in the full AI engineering skill set.