An agent is not just a model with access to tools. It is a system that repeatedly decides what to do, acts on the world, observes the result and decides whether to continue.
When I evaluate an agent framework, or build an agent from scratch, I want to understand what the model decides and what the surrounding system guarantees. Those boundaries determine whether an agent is inspectable, recoverable and reliable enough to use.
This is my working decomposition of an agent system, with a coding agent as the running example. It is an architectural model, not a claim that every agent needs every component.
1. Start with the execution loop

The smallest useful loop is:
- Construct the model's context from instructions, task state and observations.
- Ask the model to respond or request an action.
- Validate and execute the requested tool call.
- Record the observation and update task state.
- Continue until the task is complete, blocked, or an execution limit is reached.
┌──────────────────────────────┐
│ Task, instructions and state│
└──────────────┬───────────────┘
▼
Context construction
│
▼
Model decision
/ \
Final response Tool request
│
Validate / authorize
│
Tool execution
│
Observation + state
│
└──────► next decision
The model can propose the next action. The harness decides whether that action is allowed, executes it, records what happened and controls whether the loop continues. The distinction matters whenever tools have side effects or a task spans many model calls.
A deliberately minimal implementation looks like this (illustrative pseudocode, not a production-ready runtime):
for step in range(max_steps):
context = build_context(task, state, recent_observations)
decision = model.generate(context, tools=tool_schemas)
if decision.is_final:
if verifier.accepts(decision, state):
return decision.output
recent_observations.append("Completion criteria not met")
continue
action = validate_tool_call(decision.tool_call)
authorize(action, task.permissions)
result = execute_with_limits(action)
state.record(action, result)
recent_observations.append(result)
raise TaskStopped("Step budget exhausted")
There are important omissions here: idempotency, concurrency, error categories, resumability and approval gates. But even this sketch reveals the control points that disappear when we treat the framework as a black box.
2. The model versus the harness
The model selects actions; the harness governs their execution.
| Responsibility | Typically owned by |
|---|---|
| Interpret task, choose next tool, synthesize result | Model, guided by context |
| Define tool schemas and available capabilities | Harness |
| Build and truncate context | Harness, sometimes with model assistance |
| Enforce permissions, sandbox actions, cap spending | Harness |
| Maintain authoritative task state and checkpoints | Application / harness |
| Run tests and other external verifiers | Tools / harness |
| Decide whether completion evidence is sufficient | Explicit acceptance logic, evaluators, or a person |
A framework may bundle context assembly, retries, permissions, execution limits and state persistence. When evaluating one, I would inspect those defaults and determine which controls the application needs to override.
3. Context is constructed, not remembered
For each model invocation, the system chooses what the model sees: system instructions, task requirements, tool definitions, retrieved documents, recent actions, summaries and sometimes an explicit plan.
These are not interchangeable:
- Conversation history records what was said and attempted.
- Task state records what remains to be done and the current authoritative status.
- External artifacts are the files, database rows, code, or experiment outputs that actually exist.
- Longer-term memory can preserve reusable facts or preferences across tasks, but it can be stale or wrong.
Consider a coding agent that has made three unsuccessful edits. A compressed conversation might say, “Fixed the parser.” The repository and failing tests may show otherwise. On resumption, files and test results should win over the summary.
A useful context builder should answer: Why was this information included? What was omitted? Is the evidence still current? That requires logging context provenance, not merely token counts.
4. Tools turn model output into side effects
Tool use is a protocol boundary. The model emits a structured request; the harness interprets that request and potentially changes the world.
For a coding agent, tools might read files, modify files, run a test suite, or open a pull request. These have different risks. A read can be repeated freely; applying a patch or posting a comment may not be safe to repeat after a timeout.
I would design the tool layer around:
- Schema validation: reject malformed arguments and enforce path and value constraints.
- Authorization: constrain tools by task, user approval, filesystem scope and network access.
- Execution limits: timeouts, CPU/GPU budgets, token budgets and maximum tool calls.
- Idempotency and retries: distinguish safe retries from actions that might duplicate side effects.
- Typed results: report successful output, test failures, timeouts, permission errors and transient errors distinctly.
- Auditability: keep action, arguments, result and relevant artifact versions together.
A model saying “I ran the tests” is not evidence. A recorded test command, exit code and output tied to a particular commit is.
5. Planning, reflection and multi-agent workflows
Several patterns are commonly grouped under agents, but they make different tradeoffs.
| Pattern | Useful when | Failure mode to watch |
|---|---|---|
| ReAct-style step-by-step tool use | The next action depends on observations | Loops, repeated calls, local decisions without global progress |
| Plan then execute | The task has identifiable stages and dependencies | Plan becomes stale as evidence changes |
| Generate, evaluate, repair | A verifier can cheaply detect failures | Optimizing to the verifier while missing the real objective |
| Subagents / delegation | Subtasks have separable context, tools, or expertise | Coordination overhead, conflicting edits, loss of shared context |
| Fixed workflow with model steps | A known process needs judgment at specific points | Artificially restricting cases that do need exploration |
I would start with the simplest loop and add an orchestration pattern only when measured failures justify it. More agent roles or more reasoning steps are not automatically better.
6. Durable execution: interruptions are normal
A useful long-running agent has to survive a model timeout, process restart, expired credential, or interrupted human approval. Replaying the entire conversation is not a recovery strategy.
For a coding task, I would persist at least:
task_id
goal + acceptance_criteria
status: pending | running | blocked | completed | failed
workspace / repository revision
current plan or next action
completed actions and tool results
remaining budgets
approval requests
checkpoint timestamp
Resume from the checkpoint, re-read the actual workspace and reconcile completed actions before issuing any new side-effecting tool call. A good resume path is often more important than an elaborate planner.
7. Verification belongs in the architecture
A final answer is an assertion of completion. Different tasks need different evidence.
For a coding agent, verification might include tests, static analysis, diffs, security checks and a human review of intended behavior. For a research agent, it might include source-level citation checking, reproducibility of calculations, data provenance and whether the conclusion actually follows from the evidence.
A separate evaluator can help, but two model calls agreeing is not proof of correctness. A verifier should be selected to detect a meaningful failure mode.
There are at least three things to measure:
- Outcome quality: did the task satisfy its acceptance criteria?
- Trajectory quality: did it make unnecessary or unsafe calls, loop, or require intervention?
- Operational performance: completion rate, latency, token/tool cost and recovery rate after failure.
I would evaluate agent improvements on a set of representative tasks, not only on a compelling demo. A seemingly better prompt might pass one example and regress on harder cases.
8. A concrete trace: fixing a failing test
Imagine the request is: Fix the failing parser test without changing the public API.
| Step | Agent decision or system action | Evidence and state |
|---|---|---|
| 1 | Read failure report and relevant code | Task constraints captured; code revision recorded |
| 2 | Run the failing test | Exit code and failure trace stored |
| 3 | Form a hypothesis and apply a scoped patch | Diff recorded against starting revision |
| 4 | Re-run focused tests | Test results associated with patched revision |
| 5 | Run broader checks | Regressions, lint and static checks captured |
| 6 | Verify API constraint and inspect diff | Acceptance criteria checked explicitly |
| 7 | Return summary or request review | Final claim links to test and artifact evidence |
Now consider three failure cases:
The test runner times out. This is not the same as a failed assertion. Retry policy should consider whether an action is safe to replay and whether the environment needs repair.
The model declares success after editing. The harness should reject completion until the required evidence exists.
The process dies after applying the patch but before recording the tool response. On restart, the system needs to inspect the workspace before applying the same change again.
These details are what make an agent system an engineering system rather than a long prompt.
9. Where does self-improvement fit?
I separate three ideas that are sometimes conflated:
- Retry and reflection within a task: the agent sees an error and revises its approach.
- Learning across tasks: observations improve prompts, retrieval, tools, workflows, or policies for future runs.
- Recursive self-improvement (RSI): a system proposes changes to its own capabilities or architecture, tests them and adopts changes through a controlled process.
Only the third is a candidate for RSI in the stronger sense and even there the scope of what can change needs to be specified. A generate-test-repair loop does not, by itself, establish durable capability improvement.
An improvement loop should have a held-out evaluator, versioned artifacts, explicit promotion criteria, regression checks and a way to roll back. Otherwise the system may simply learn to exploit its own evaluation.
10. When should I use a framework?
My starting preference is a thin implementation close to the model API. It makes the loop visible and failures easier to localize. I would adopt a framework when I can name the complexity it removes and understand the behavior it introduces.
Before choosing one, I want answers to these questions:
- Can I see and control the exact context supplied to each model call?
- Can tasks checkpoint and resume without blindly replaying side effects?
- Where are permissions, execution limits and approval gates enforced?
- Can I replace the planner or model without rebuilding task state and tools?
- What traces and measurements will tell me why a task failed?
- Which abstractions are essential today and which are workarounds for current model limitations?
Better models may reduce prompt workarounds and rigid decomposition rules. They do not automatically eliminate the need for controlled execution, durable state and evidence of completion.
My design preference: keep the model loop simple, make the harness observable and add orchestration only when failures show that it is needed.
What I was reading
- Building effective agents — agent and workflow patterns
- Effective context engineering for AI agents — context selection and management
- Effective harnesses for long-running agents — continuity across execution windows
Related notes
- AI systems: context and memory — how information and state persist across agent execution.
Diagrams generated using AI.