FOUNDATIONS · 5 MIN READ

The anatomy of an agentic system

A model is one part of the system. Understand the parts around it.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Trace one support request across the application

When a wrong answer reaches a customer, the developer needs to know whether authentication, lookup or answer construction failed.

Input
An authenticated tenant, order ID, run identifier and a tenant-scoped order fixture.
Expected output
Correlated request, policy, tool, evaluation and completion events.
  • Success check: Every event has the same run ID; the status in the answer matches the actual tool observation.
  • Try a failure: A denied lookup must terminate before an answer is marked successful.

Example scope: The local example exposes the application boundaries. Tracing products can export the same events; the example is not a live model benchmark.

OpenTelemetry exampleLangfuse example
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
requestcontextproposalresultpersistobserveRequest + identityWho and whatAgent controllerPlan a bounded turnModel + contextReason over evidenceTool serviceRead or actState + memoryContinue and recallEvaluation + traceInspect the outcome
  1. Authenticate before resolving tenant-scoped application data.

  2. The controller selects context, calls the model, and dispatches approved tools.

  3. Send instructions, the task, selected memories, and tool schemas.

  4. Validate arguments and permissions again at the service that owns the resource.

  5. A checkpoint resumes a run; selected memories can inform later conversations.

    Result or stopping point
  6. Join the run events and check whether the task completed correctly.

    Result or stopping point
Agent controller

The controller selects context, calls the model, and dispatches approved tools.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

The control loop

  • The application sends instructions, a task, selected context, and tool descriptions to a model.
  • The model produces an answer or a tool request.
  • The application validates the request, executes the tool, and returns the observation.
  • The loop continues until a completion or stopping condition.

The supporting layers

  • Context: information selected for this turn, including the user request and relevant retrieved material.
  • Tools: functions that read information or perform actions.
  • State: progress, messages, and results needed to continue execution.
  • Memory: selected information that can be recalled in later interactions.
  • Policy: application rules governing access, approvals, and budgets.
  • Evaluation: checks that tell you whether the task actually succeeded.

Follow one request end to end

  • For an order inquiry, the user supplies a reference, the application authenticates the user, and the agent requests a scoped lookup.
  • The service verifies access to that order.
  • The tool returns the authoritative status.
  • The answer is then checked for consistency with the returned data.

Set up the lab

  • Use a new working directory for this example.
Shell
python3 -m venv .venv
source .venv/bin/activate

Implement the example

Save as trace.py

Python · trace.py
import json
from uuid import uuid4

orders = {("shop-a", "A104"): "packed"}

def run(tenant, order_id, can_read=True):
    run_id, events = str(uuid4()), []
    def event(stage, **fields):
        events.append({"run_id": run_id, "stage": stage, **fields})
    event("request", tenant=tenant, order_id=order_id)
    event("policy", operation="orders:read", allowed=can_read)
    if not can_read:
        event("complete", outcome="denied")
        return events
    observation = {"order_id": order_id,
                   "status": orders.get((tenant, order_id), "not_found")}
    event("tool", name="lookup_order", result=observation)
    answer = f"{order_id}: {observation['status']}"
    event("evaluation", grounded=observation["status"] in answer)
    event("complete", outcome="answered", answer=answer)
    return events

normal = run("shop-a", "A104")
assert len({e["run_id"] for e in normal}) == 1
assert normal[-1]["answer"] == "A104: packed"
assert run("shop-b", "A104")[-1]["answer"] == "A104: not_found"
denied = run("shop-a", "A104", can_read=False)
assert not any(e["stage"] == "tool" for e in denied)
for event in normal:
    print(json.dumps(event))
print("cross-tenant and denied-access cases passed")

Run and verify

Shell
python trace.py
  • Five events share a run ID and include the actual tenant-scoped observation and constructed answer.
  • The other-tenant request returns not_found. Denied access terminates before any tool event.

Troubleshooting and failure tests

  • A final answer without its tool observation cannot be debugged from model text alone.
  • An allowed model request does not override a denied application policy.

Before production

  • Replace the deterministic answer stage with a model call and retain the policy/tool boundaries.
  • Export redacted spans through OpenTelemetry or a tracing product, keeping stable run/parent identifiers.

Keep exploring

Design tools an agent can use wellA layered architecture for agent memoryAI agent evaluation: frameworks, tools and an example