Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 15 min · revision 3

What Makes Something an Agent, and Where Agents Pay Off

Tell agents apart from workflows and routers, see which tasks are worth the extra cost and latency of an agent loop, and map that loop onto ReAct prompts, native tool calls and framework agent classes.

Contentsand lesson path

What you will learn

  • Explain how ReAct-style prompting relates to native tool calling and to reasoning models that interleave thinking with tool calls, and how a framework's agent abstraction maps onto the same loop.

Prerequisites: Tool Calling

01. The Spectrum of Autonomy: Routers, Chains, and Autonomous Agents

The word "agent" is used for almost any system that connects a large language model (LLM) to data or tools. Mixing up fixed pipelines and agents leads to poor design choices: you pay for a loop you do not need, or you test a loop as if it were a fixed pipeline.

It helps to place a system on a scale of autonomy, meaning how much of the control flow the model decides. The scale has three levels:

  1. Prompt chaining and workflows. A workflow is a predefined code path: the steps, the branches and any loops (with their exit conditions) are written in application code. A request flows through Step A, passes to Step B, and branches into Step C based on if/else statements. An LLM may classify the input to pick one of those branches, or judge whether a draft passes and should leave a review loop, but it can only choose among paths the developer wrote. Workflows are predictable, auditable and usually low-latency.

  2. Routers and single tool calls. A router asks the LLM to classify the request and pick one tool or one destination. After that choice, the code runs a fixed sequence. The model makes one decision per request: it does not see the result of its choice and decide again.

  3. Agents. An agent puts the model inside a loop with its environment. The model gets a goal, a set of tools and what it has observed so far. The key difference is that the model decides the control flow: it picks which tool to call, reads the result, changes its next step when the result is unexpected, and decides when the task is done. Your code still sets the limits, such as the step cap and the tools the model may call.

The difference changes how you test, monitor and handle failures. In a workflow you test each step and check that every path is covered. In an agent loop the path is chosen at run time, so you also measure how often runs reach the goal, how many steps they take, and whether the loop's limits stop the runs that go wrong.

02. Where Agents Pay Off

An agent loop uses a varying number of tokens, and its latency adds up over turns, so using one for the wrong problem is expensive. Parsing structured invoices, or routing support tickets by strict compliance rules, is better done with a fixed workflow and schema-constrained extraction.

Agents tend to be worth their cost on tasks with one of three properties:

  1. Open-ended information gathering. Research, competitive intelligence, and complex customer investigations where the exact query path depends on intermediate discoveries. For example, investigating a security incident requires searching audit logs, pivoting on discovered IP addresses, and querying firewall rules dynamically.

  2. Iterative changes to an environment. Software development agents (such as automated bug-fixing assistants) that read files, draft code changes, execute unit test runners, read compiler error traces, and iteratively refine their implementation until the test suite passes.

  3. Dynamic tool sequencing under ambiguity. Operations where twenty microservices could be called, but a given task needs only two or three of them, depending on that customer's configuration.

The Python snippet below illustrates the structural difference between a static workflow node and an autonomous agent dispatch loop.

Python · architecture/comparison.py Deterministic pipeline vs. dynamic agent loop
import os
from typing import Dict, List
from openai import OpenAI

MODEL = os.environ["OPENAI_MODEL"]  # for example gpt-6-luna

# 1. Deterministic Workflow: Code dictates the execution path
def run_deterministic_pipeline(user_query: str, client: OpenAI) -> str:
    # Step 1: Always extract entities
    entities = client.chat.completions.create(
        model=MODEL,
        messages=[{"role": "user", "content": f"Extract entities: {user_query}"}],
    )
    # Step 2: Always query search with extracted terms
    search_results = {"data": "Found 3 user accounts"}
    # Step 3: Always format response
    return f"Processed query using {entities.choices[0].message.content}"

# 2. Autonomous Agent: Model dictates control flow dynamically
MAX_STEPS = 8  # hard cap: lesson 04 shows why every loop needs one

def run_agentic_loop(goal: str, tools: List[Dict], client: OpenAI) -> str:
    messages = [{"role": "user", "content": goal}]
    for _ in range(MAX_STEPS):
        # Model decides whether to call tools or terminate with an answer
        response = client.chat.completions.create(
            model=MODEL,
            messages=messages,
            tools=tools,
            # Chat Completions tool calls need "none". It works with gpt-6-luna;
            # GPT-6.2 models reject it (lesson 02 shows the Responses API way).
            reasoning_effort="none",
        )
        msg = response.choices[0].message
        messages.append(msg)
        if not msg.tool_calls:
            return msg.content or ""  # Agent determines goal is reached
        # Execute the actions the model chose. Stubbed here: lesson 02
        # dispatches each call to a real handler.
        for call in msg.tool_calls:
            messages.append({"role": "tool", "tool_call_id": call.id, "content": "{}"})
    raise RuntimeError(f"step budget of {MAX_STEPS} exhausted")

03. The Operational Cost Equation: Latency, Tokens, and Reliability

Before you run an agent loop in production, work out how its costs add up. In a fixed pipeline, a user request makes a fixed, small number of model calls (one or two here). Its token use still varies with the input, but within a narrow range, and so does its latency.

In an autonomous agent loop, each additional step accumulates the entire previous conversation transcript. If an agent executes six consecutive tool turns, the system resends the growing message history six times. When each turn adds a similar amount of text, total input tokens grow roughly with the square of the turn count, and wall-clock latency scales linearly with model inference and tool execution durations.

Every extra turn that the agent decides on its own is another chance for an error, and errors compound. If an individual tool call has an independent success rate of 95%, a six-step agent run succeeds end to end only about 74% of the time (0.95^6 ≈ 0.735) unless active recovery and validation mechanisms are implemented.

So a large part of production engineering is removing autonomy that the task does not need. Where plain code can do a step reliably, use code. Keep the agent loop for the points where the next step really depends on what the model reads, and where recovering from surprises is worth the extra calls and latency.

04. The Same Loop in ReAct, Native Tool Calls and Frameworks

Every agent in this skill runs the loop in run_agentic_loop above: call the model, run the tools it asks for, add the results to the history, and stop on a final answer or a limit. Three common ways of building an agent differ only in who does each part:

  • ReAct prompting (2022) asks the model to write Thought: and Action: lines as plain text. Your code stops the model at the next Observation: (or cuts the reply there), parses the action out of the text with patterns, runs the tool and appends an Observation: line with the real result. If the model writes the observation itself, it has invented the tool result. Lesson 03 shows why this parsing breaks easily.
  • Native tool calling, as in the code above, returns each call as a structured object with a tool name and JSON arguments, so nothing is parsed out of prose. Reasoning models also think between calls, and your loop must send that reasoning back with the tool results (lesson 03).
  • A framework agent class wraps the same loop. In the OpenAI Agents SDK, for example, await Runner.run(agent, task, max_turns=10) calls the model, runs the functions you registered with @function_tool and listed in Agent(tools=[...]), adds their results and stops on a final answer. When the turn limit is reached it raises MaxTurnsExceeded. LangGraph and the Claude Agent SDK use their own names for the same parts; LangGraph, for instance, caps the steps of a run with recursion_limit.

So when you meet a new framework, look for four things: where the model is called, where tool calls are dispatched, how results are added to the history, and which limits stop a run. A turn limit counts model calls, not tokens, so a cost ceiling still needs its own check (lesson 04).

05. Practice questions

Practice check · 3 questions

Agent autonomy boundaries and economic tradeoffs check

Three scenario-based questions on the definition of agentic autonomy, compounding reliability and ReAct mechanics.

Q1. A support system uses an LLM to classify each ticket and sends it to one of four fixed handlers, each a two-step chain. How should you describe it?
Q2. Each step of a six-step run succeeds 95% of the time, independently of the others. Without any recovery logic, roughly how often does the whole run succeed?
Q3. A ReAct reply ends with `Action: get_order[id=812]` and then `Observation: order 812 shipped on 3 May`. Your code has not run `get_order` yet. What should it do?
Practice only: not graded, not saved, not evidence.

06. Apply it

Before you build an agent, check these points on your own task:

  • Can you write the steps down in advance? If so, build a workflow: code-defined steps, branches and bounded loops. Use an agent loop only when the number of steps is unknown, or the next step depends on what a tool returns.
  • Measure one plain model call first. A loop of N turns makes about N model calls plus its tool calls, so expect it to take several times longer and cost several times more.
  • Mix the two styles where it helps: a fixed pipeline for the steps you can predict, such as loading data, and a small, bounded agent loop only for the step that needs judgement.
  • Estimate how often a whole run fails. If each of 8 steps succeeds 95% of the time and the steps fail independently, a run succeeds only about 66% of the time (0.95 to the power 8). That may mean a person must check the result before the agent acts.
  • Compare the agent with a tuned two-step pipeline on the same tasks, and keep it only if it does better by enough to pay for its extra calls.

07. Review prompt

Contrast the control flow of a deterministic prompt chaining workflow with an autonomous agent loop. Describe two real tasks where an agent loop is worth its extra cost, explain how re-sent history affects tokens and latency over many turns, and name the four parts of the loop you look for in a framework.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check