Home › Blog › Agentic Systems
Deep Dive · With a runnable agent loop 🤖

Agentic Systems: From Single Tool Calls to Multi-Step Goal Completion

A plain LLM answers a question or makes one tool call. An agent pursues a goal: it plans, acts, observes the result, updates its state, reflects, replans, and keeps going until the goal is met or a limit is hit. This piece covers the loop and every component around it — planning, memory and state, tool use, reflection, human approval, failure recovery, subagents, stopping, observability — and shows with a working agent, and a little arithmetic, why long runs are hard to make reliable.

How to read this: claims about published systems and research are sourced. "Our run" output comes from the script in Run the Agent; its planner and critic are rule-based stand-ins for LLM calls and its tools are simulated (with a timeout and an over-budget result), so what it demonstrates is the loop machinery, not model intelligence. This is the eleventh piece in the How LLMs Are Built series and builds directly on Tool and Function Calling.

Why Agentic Systems

A normal LLM answers a question or makes one tool call. An agent can pursue a broader goal over many steps using tools, memory and reasoning: break a complex task down, decide the next action, use tools repeatedly, update its state with new information, recover from errors, and continue until the goal is done. Anthropic's guidance draws a useful line between workflows, where code fixes the sequence of LLM and tool calls in advance, and agents, where the model decides its own steps — and recommends the simplest option that works, since agents trade cost and predictability for flexibility.

The End-to-End Agent Loop

  1. User goal — "Find the best laptop options under ₹80,000 and email me a summary."
  2. Plan and reason — understand the goal, break it into tasks, decide the next step.
  3. Choose an action — pick a tool or subagent, create its arguments, respect constraints.
  4. Execute — web search, code, database, files, email, browser — or delegate to a subagent.
  5. Observe — receive the result, check for errors, interpret the output.
  6. Update memory and state — store results, update the plan and progress, track limits and resources.
  7. Reflect and decide — did it work? Is there enough information? Retry, branch, or change plan.
  8. Done? — check the stop conditions. If not, loop back to planning; if so, produce the final result.

Single Tool Call vs Agentic Workflow

AspectSingle tool callAgentic workflow
ScopeAnswer a question or make one callPursue a broader goal over many steps
DecisionsOneMany
ActionsOneMany, sequential or parallel
State and memoryWithin the promptMaintained across steps
Error handlingMinimalRecover, retry, replan
PlanningNot requiredExplicit planning and dynamic replanning
Example"Search for X""Research, analyze and email a report"

Task Decomposition and Planning

Given "plan a 3-day business trip under budget", an agent decomposes it: find suitable flights, compare hotels, build a daily itinerary, check the total budget, prepare a summary. Three planning strategies are common:

1Direct planning — the model writes a full plan up front, then follows it.
2Plan-and-execute — a planner creates the plan; an executor carries out the steps, and the planner revises when results come back.
3Iterative planning — plan a few steps, act, then replan in light of what happened (the ReAct style of interleaving reasoning and action).

Up-front plans are cheaper and easier to inspect; iterative plans adapt better when the world surprises you. Many systems combine them: a rough plan first, revised after each observation.

Core Agent Components

ComponentRole
LLM / reasoning coreUnderstands the goal, reasons, decides next actions
PlannerCreates and updates the task plan
Tool routerChooses the right tool or subagent
MemoryStores conversation, results and learnings
State storeTracks current state, progress and limits
Tool gatewayExecutes tools securely and manages permissions (the orchestrator from Tool Calling)
Evaluator / criticChecks results, detects errors, suggests improvements
Human approval layerRequests consent for consequential actions

Working Memory and State

During a task the agent keeps a short-term scratchpad: the current plan and upcoming steps, completed steps, intermediate results (search results, data, outputs), pending actions, budget and limits (tokens, cost, time), and resource IDs (file IDs, session IDs, links) that later steps need. That working state is task-specific and cleared afterwards; persistent memory — saved tasks, user preferences, past experiences, domain knowledge — survives across tasks. The distinction and the machinery are the same as in Context Engineering and Memory; long-running agents often keep state in a file or structured store outside the context window, so it survives compaction. Agent Memory and Planning Patterns covers checkpoints, write policies and learning from experience in depth.

Reflection and Replanning

After each observation the agent reflects: observe what happened → critique (did it work? do I have enough?) → update the plan (retry, branch, change approach) → choose the next action. Reflexion (Shinn et al., 2023) showed that having the model write feedback on its own failed attempts and keep it in memory improves later attempts. In our run, the critic found only two laptops under budget after the first search (it rejected one at ₹82,990), decided that wasn't enough, and replanned: search a second page, gather specs, check again — ending with four valid options.

Human-in-the-Loop and Safety

Safety checks run throughout the workflow, not only at the end: permission checks (does the agent have access?), policy checks, sandboxing for risky code, least privilege, and confirmation prompts before sending, deleting or purchasing. Read-only tools (web search, database reads, file reads) can usually run without approval; action tools (send email, delete files, make purchases, modify data) may require it. In our run the agent paused for approval before emailing; when the user declined, it stopped without sending anything.

Failure Handling and Recovery

FailureRecovery
Tool error (API failure, rate limit)Retry, usually with fixes or backoff
Timeout (tool or step takes too long)Choose an alternate tool or source
Bad argumentsRegenerate with the validation error
Missing dataAsk the user for the missing information
Unsafe action (violates policy or permissions)Replan around it, or stop
Contradictory resultsGather more evidence; flag the conflict
A step went wrong after actingRoll back changes if possible
Can't completeStop gracefully: explain the issue and report what was done

In our run, one store's product page timed out; that subagent switched to a review site and the run continued without the planner noticing.

Why Long Runs Fail — and What Helps

If each step of a task succeeds with probability p and the steps are independent, the whole task succeeds with probability pn. Even a step that works 95% of the time compounds badly. Our script computes this and checks it by simulation, then adds verification: each failed step is noticed 80% of the time and retried up to twice.

95% 99% 1 step 77% 95% 5 steps 60% 90% 10 steps 36% 81% 20 steps 8% 59% 50 steps 95% steps alone+ verify & retry
Our run: probability that a whole n-step task succeeds with 95%-reliable steps, without (grey) and with (green) verify-and-retry. Checking results and retrying doesn't make agents perfect, but it changes how long a task they can survive.

This is why the practical focus in agents is reliability, not only capability: evaluators and critics, validation, retries and fallbacks, short well-defined steps, and human checkpoints. METR's measurements of how long a task AI agents can complete — the length of task, in human time, that models finish half the time — have been doubling roughly every seven months since 2019, and they attribute much of the progress to better reliability and ability to recover from mistakes.

Parallelism and Subagents

Independent subtasks can run in parallel. A supervisor agent plans and coordinates; it delegates to specialist subagents — a research agent that searches and gathers information, a coding agent that writes and runs code, an analyst that analyzes data, a reviewer that checks quality — and synthesizes their results into the final output. Each subagent works in its own clean context, so the supervisor receives condensed findings rather than every raw search result.

Anthropic reported that its multi-agent research system — a lead agent directing parallel subagents — outperformed a single agent by 90.2% on an internal research evaluation, while using about 15 times as many tokens as a chat interaction. Parallelism buys breadth and speed at a real cost, so it fits high-value, broad tasks. (Multi-Agent Systems covers team designs in depth.) In our run, three spec-gathering subagents ran in parallel in 0.35 s, including one's fallback after its timeout.

Termination Criteria

An agent needs explicit rules for when it is done: the goal is satisfied; enough evidence has been collected; the final output is assembled; user confirmation obtained if required; a limit is reached (time, cost, tokens, steps); or a failure condition is met. Without them agents loop, wander or overspend. Our run shows three endings: success: goal satisfied after 9 tool calls; with a 6-call budget, stopped gracefully with the 2 valid options it had so far; and stopped by user when the email was declined.

A Full Run, Traced

Every step of an agent run should be logged — plans, tool calls, results, decisions, time, cost, tokens, human interventions, retries and failures — so it can be debugged and evaluated. Here is our agent's complete trace for the laptop goal:

2) goal: 'Find the best laptop options under Rs 80,000 and email me a summary'
    1.  0.00s  plan     search for candidates -> gather specs (parallel subagents) -> critic: check constraints -> draft comparison -> ask user to approve email -> send email
    2.  0.05s  act      web_search page 1 -> ['Acer Swift Go 14', 'Lenovo Slim 5', 'ASUS Vivobook S15']
    3.  0.40s  observe  Acer Swift Go 14: Rs 74,990 via store
    4.  0.40s  observe  Lenovo Slim 5: Rs 78,490 via review site (fallback after timeout)
    5.  0.40s  observe  ASUS Vivobook S15: Rs 82,990 via store
    6.  0.40s  parallel 3 subagents in 0.35s (sequential would be ~0.75s+)
    7.  0.40s  critic   2 under budget; rejected over budget: ['ASUS Vivobook S15']
    8.  0.40s  replan   fewer than 4 valid options -> search one more page, gather, re-check
    9.  0.45s  act      web_search page 2 -> ['HP Pavilion Plus', 'Dell Inspiron 14']
   10.  0.70s  observe  HP Pavilion Plus: Rs 76,990 via store
   11.  0.70s  observe  Dell Inspiron 14: Rs 69,990 via store
   12.  0.70s  parallel 2 subagents in 0.25s (sequential would be ~0.50s+)
   13.  0.70s  critic   4 under budget; rejected over budget: ['ASUS Vivobook S15']
   14.  0.70s  act      draft: Lenovo Slim 5 Rs 78,490 (16 GB, 1.5 kg, 4.5); Acer Swift Go 14 Rs 74,990 (16 GB, 1.3 kg, 4.4); HP Pavilion Plus Rs 76,990 (16 GB, 1.4 kg, 4.3); Dell Inspiron 14 Rs 69,990 (8 GB, 1.5 kg, 4.1)
   15.  0.70s  human    approval requested to email the summary -> approved
   16.  0.73s  act      send_email -> sent
   17.  0.74s  stop     success: goal satisfied
   tool calls: 9; total time 0.74s

The laptop models, prices and ratings are illustrative data inside the script, not live prices.

Agent Patterns

PatternIdea
ReActInterleave reasoning and actions using observations
Plan-and-executeCreate a plan first, then execute the steps, revising as needed
Supervisor–workerA supervisor delegates to specialist subagents and combines their results
Reflection / criticReview outputs, learn from failures, revise the plan
Retrieval + action loopCombine RAG for knowledge with tools for action
Agents in one paragraph
An agent wraps an LLM in a loop — plan, act through tools or subagents, observe, update state, reflect, replan — and runs it until explicit stop conditions say the goal is met or a budget or failure limit is hit. The model supplies the judgment; the system supplies everything that makes it dependable: a state store and memory, a secure tool gateway, a critic that checks results, fallbacks and retries, human approval for consequential actions, parallel subagents when work is independent, and a full trace. Because per-step errors compound over long tasks, reliability engineering — not just a smarter model — is what turns a demo into an agent you can trust.

Run the Agent

One script, standard library only, runs in about two seconds.

"""An agent loop, end to end: plan -> act -> observe -> update state -> reflect/replan -> stop.

The planner and critic are rule-based stand-ins for LLM calls, and the tools are simulated (with latency,
a timeout and a bad result), so the loop machinery is real: state, budgets, stop conditions, a critic that
triggers replanning, a fallback tool, parallel subagents, a human-approval gate and a full trace.
Part 1 first shows why long agent runs fail: per-step errors compound. Standard library only.
"""
import concurrent.futures as cf, random, time

# ---------------- 1. why agents fail: reliability compounds over steps ----------------
print("1) chance a whole task succeeds, if each step succeeds with probability p")
def run_task(n, p, detect, retries, rng):
    for _ in range(n):
        ok = rng.random() < p
        tries = 0
        while not ok and tries < retries and rng.random() < detect:       # the error is noticed, so retry
            ok = rng.random() < p; tries += 1
        if not ok: return False
    return True
rng = random.Random(0)
print("   steps   p=0.95 exact   p=0.95 simulated   + verify & retry (80% of errors caught, 2 retries)")
for n in (1, 5, 10, 20, 50):
    sim = sum(run_task(n, 0.95, 0, 0, rng) for _ in range(20000)) / 20000
    fix = sum(run_task(n, 0.95, 0.8, 2, rng) for _ in range(20000)) / 20000
    print(f"   {n:>5}   {0.95 ** n:>12.1%}   {sim:>16.1%}   {fix:>12.1%}")

# ---------------- 2. an agent that completes a multi-step goal ----------------
GOAL = "Find the best laptop options under Rs 80,000 and email me a summary"
CATALOG = {"Acer Swift Go 14": (74990, 1.3, 16, 4.4), "Lenovo Slim 5": (78490, 1.5, 16, 4.5),
           "ASUS Vivobook S15": (82990, 1.4, 16, 4.6), "HP Pavilion Plus": (76990, 1.4, 16, 4.3),
           "Dell Inspiron 14": (69990, 1.5, 8, 4.1)}             # price, kg, GB RAM, rating (illustrative data)
def web_search(query, page=1):
    time.sleep(0.05); names = list(CATALOG)
    return names[:3] if page == 1 else names[3:]
def store_specs(name):                                           # primary tool: one product page times out
    time.sleep(0.25)
    if name == "Lenovo Slim 5": raise TimeoutError("store API timed out")
    return dict(zip(("price", "kg", "ram", "rating"), CATALOG[name]))
def review_site_specs(name):                                     # fallback tool
    time.sleep(0.10); return dict(zip(("price", "kg", "ram", "rating"), CATALOG[name]))

class Agent:
    def __init__(self, budget_calls=20, budget_s=5.0):
        self.state = {"goal": GOAL, "plan": [], "done": [], "candidates": {}, "results": {}, "pending": None}
        self.budget_calls, self.budget_s, self.calls, self.t0, self.trace = budget_calls, budget_s, 0, time.perf_counter(), []
    def log(self, kind, detail):
        self.trace.append((len(self.trace) + 1, round(time.perf_counter() - self.t0, 2), kind, detail))
    def tool(self, fn, *a):
        if self.calls >= self.budget_calls: raise RuntimeError("tool-call budget exhausted")
        self.calls += 1; return fn(*a)
    # planner (an LLM call in a real agent): decompose the goal into subtasks
    def plan(self):
        self.state["plan"] = ["search for candidates", "gather specs (parallel subagents)", "critic: check constraints",
                              "draft comparison", "ask user to approve email", "send email"]
        self.log("plan", " -> ".join(self.state["plan"]))
    # subagent: one per laptop, each with its own fallback
    def spec_subagent(self, name):
        try: return name, self.tool(store_specs, name), "store"
        except TimeoutError: return name, self.tool(review_site_specs, name), "review site (fallback after timeout)"
    def run(self, approve=True):
        self.plan(); page = 1
        while True:
            if time.perf_counter() - self.t0 > self.budget_s: return self.stop("budget exhausted (time)")
            step = next((s for s in self.state["plan"] if s not in self.state["done"]), None)
            if step is None: return self.stop("success: goal satisfied")
            try:
                if step == "search for candidates":
                    found = self.tool(web_search, "laptop under 80000", page)
                    self.state["candidates"].update({n: None for n in found}); self.log("act", f"web_search page {page} -> {found}")
                elif step == "gather specs (parallel subagents)":
                    todo = [n for n, v in self.state["candidates"].items() if v is None]
                    t = time.perf_counter()
                    with cf.ThreadPoolExecutor(len(todo)) as ex: out = list(ex.map(self.spec_subagent, todo))
                    for name, spec, src in out: self.state["candidates"][name] = spec; self.log("observe", f"{name}: Rs {spec['price']:,} via {src}")
                    self.log("parallel", f"{len(todo)} subagents in {time.perf_counter() - t:.2f}s (sequential would be ~{0.25 * len(todo):.2f}s+)")
                elif step == "critic: check constraints":         # evaluator: reflect on results, maybe replan
                    ok = {n: s for n, s in self.state["candidates"].items() if s["price"] <= 80000}
                    over = [n for n in self.state["candidates"] if n not in ok]
                    self.state["results"] = ok
                    self.log("critic", f"{len(ok)} under budget; rejected over budget: {over or 'none'}")
                    if len(ok) < 4 and page == 1:
                        page = 2; self.log("replan", "fewer than 4 valid options -> search one more page, gather, re-check")
                        self.state["done"] = []; continue
                elif step == "draft comparison":
                    ranked = sorted(self.state["results"].items(), key=lambda kv: (-kv[1]["rating"], kv[1]["price"]))
                    self.state["summary"] = "; ".join(f"{n} Rs {s['price']:,} ({s['ram']} GB, {s['kg']} kg, {s['rating']})" for n, s in ranked)
                    self.log("act", "draft: " + self.state["summary"])
                elif step == "ask user to approve email":         # human-in-the-loop gate for an action tool
                    self.log("human", f"approval requested to email the summary -> {'approved' if approve else 'declined'}")
                    if not approve: return self.stop("stopped by user (declined the email)")
                elif step == "send email":
                    self.tool(lambda: time.sleep(0.03)); self.log("act", "send_email -> sent")
                self.state["done"].append(step)
            except RuntimeError as e:
                return self.stop(f"stopped gracefully: {e}; partial results kept ({len(self.state['results'])} options)")
    def stop(self, reason):
        self.log("stop", reason); return reason

print(f"\n2) goal: {GOAL!r}")
a = Agent(); a.run()
for n, t, kind, d in a.trace: print(f"   {n:>2}. {t:>5.2f}s  {kind:<8} {d}")
print(f"   tool calls: {a.calls}; total time {time.perf_counter() - a.t0:.2f}s")

print("\n3) the same goal with a 6-tool-call budget")
b = Agent(budget_calls=6); print("   ->", b.run())
print("\n4) the same goal, but the user declines the email")
c = Agent(); print("   ->", c.run(approve=False))

Output (simulation uses a fixed seed; timings vary slightly by machine):

1) chance a whole task succeeds, if each step succeeds with probability p
   steps   p=0.95 exact   p=0.95 simulated   + verify & retry (80% of errors caught, 2 retries)
       1          95.0%              95.1%          99.0%
       5          77.4%              77.2%          94.7%
      10          59.9%              60.4%          90.2%
      20          35.8%              36.4%          80.8%
      50           7.7%               7.5%          58.9%

2) goal: 'Find the best laptop options under Rs 80,000 and email me a summary'
    1.  0.00s  plan     search for candidates -> gather specs (parallel subagents) -> critic: check constraints -> draft comparison -> ask user to approve email -> send email
    2.  0.05s  act      web_search page 1 -> ['Acer Swift Go 14', 'Lenovo Slim 5', 'ASUS Vivobook S15']
    3.  0.40s  observe  Acer Swift Go 14: Rs 74,990 via store
    4.  0.40s  observe  Lenovo Slim 5: Rs 78,490 via review site (fallback after timeout)
    5.  0.40s  observe  ASUS Vivobook S15: Rs 82,990 via store
    6.  0.40s  parallel 3 subagents in 0.35s (sequential would be ~0.75s+)
    7.  0.40s  critic   2 under budget; rejected over budget: ['ASUS Vivobook S15']
    8.  0.40s  replan   fewer than 4 valid options -> search one more page, gather, re-check
    9.  0.45s  act      web_search page 2 -> ['HP Pavilion Plus', 'Dell Inspiron 14']
   10.  0.70s  observe  HP Pavilion Plus: Rs 76,990 via store
   11.  0.70s  observe  Dell Inspiron 14: Rs 69,990 via store
   12.  0.70s  parallel 2 subagents in 0.25s (sequential would be ~0.50s+)
   13.  0.70s  critic   4 under budget; rejected over budget: ['ASUS Vivobook S15']
   14.  0.70s  act      draft: Lenovo Slim 5 Rs 78,490 (16 GB, 1.5 kg, 4.5); Acer Swift Go 14 Rs 74,990 (16 GB, 1.3 kg, 4.4); HP Pavilion Plus Rs 76,990 (16 GB, 1.4 kg, 4.3); Dell Inspiron 14 Rs 69,990 (8 GB, 1.5 kg, 4.1)
   15.  0.70s  human    approval requested to email the summary -> approved
   16.  0.73s  act      send_email -> sent
   17.  0.74s  stop     success: goal satisfied
   tool calls: 9; total time 0.74s

3) the same goal with a 6-tool-call budget
   -> stopped gracefully: tool-call budget exhausted; partial results kept (2 options)

4) the same goal, but the user declines the email
   -> stopped by user (declined the email)

⚠️ Notes

The source infographic is accurate as an overview; three points it doesn't make explicit:
  • Reliability compounds. The loop diagram makes long multi-step runs look routine; the arithmetic above is why they're hard, and why critics, retries and human checkpoints matter.
  • Agents aren't always the right design. A fixed workflow is cheaper and more predictable when the steps are known in advance; Anthropic's guidance is to add autonomy only where it pays.
  • Subagents cost tokens. Anthropic's multi-agent system used about 15× the tokens of a chat — parallelism is not free.
Checked against sources: Anthropic's "Building effective agents" (workflows vs agents) and "How we built our multi-agent research system" (90.2% improvement, ~15× tokens); METR's time-horizon paper (50% time horizon, doubling about every seven months, 2019–2025); ReAct; Reflexion; Plan-and-Solve prompting. The reliability numbers are computed and simulated by the included script.

🔗 References