AI Agent Architecture: LLMs and Execution Frameworks in a Controlled Loop
An AI agent is best understood as an LLM paired with an execution framework. This article explains the observe-reason-act loop, the capabilities the framework must add, the distinction between tools and skills, context assembly, common failure modes, observability, evaluation, and a minimal path to a production closed loop.
An AI agent can be abstracted as an LLM plus an execution framework. The LLM understands the goal, organizes reasoning, and generates the next decision. The execution framework turns decisions into actions in a verifiable environment: reading files and logs, calling APIs, running checks, returning results, and stopping when the agent exceeds its boundaries. Both parts are essential. With only a model, the system remains at the level of text suggestions. With tool calls but no clear loop and constraints, the system can easily take consecutive actions based on incorrect assumptions. In engineering terms, an agent should be treated as a controlled closed-loop controller, not as a single conversation.
Why the Loop Must Be Closed, Not a Single Generation
Information for complex tasks is often not present in the initial prompt. Whether code passes checks, whether an API returns expected fields, and whether configuration matches the environment can only be known after action. A single generation can only guess based on training knowledge and the user’s description. It cannot be accountable to the real environment.
The execution framework turns guessing into hypothesis validation. The model proposes a small executable step, the framework executes it and collects objective feedback, and the model revises its hypothesis based on that feedback. This process mirrors manual troubleshooting: observe the symptom, locate the cause, make the smallest change, and verify again. The difference is that the model proposes the steps, while the framework enforces the boundaries.
Therefore, an agent should not be evaluated only by whether a single-turn answer is fluent. It should be evaluated on three things: whether environment state is actually read, whether each action is traceable, and whether the system stops on failure instead of forcing ahead.
The Observe, Reason, Act Loop
The core execution mechanism is the Observe, Reason, Act loop. The three steps have different responsibilities. Mixing them leads to problems such as changing code without reading logs or making changes without re-running checks.
1. Observe: Collect Only Verifiable Environment Facts
Observation reads environment feedback rather than asking the model to recall what something “should” look like. Typical inputs include exit status and failure summaries from checks or tests, relevant file fragments, API response bodies and status codes, configuration differences, and error stacks in runtime logs. The observation phase should follow several principles.
Keep the scope small. Take only the fragments relevant to the current hypothesis at one time. Avoid placing an entire repository or extremely long logs into context. That wastes capacity and dilutes the key signal.
Separate facts from interpretation. Raw errors, returned fields, and file paths are facts. Statements such as “it may be a null pointer” or “perhaps permissions are insufficient” are reasoning. They should not be written into observation results as if they were facts.
Prefer structured information. Information that can be expressed as status codes, assertion names, file paths, and line numbers should not be rewritten as vague natural language. Structured feedback is easier for the next reasoning step to reference and easier to audit.
Maintain freshness. After an action, the agent must observe again. It cannot reuse conclusions from the previous round. The environment has changed after tool execution, and stale observations can lock the loop into an outdated state.
2. Reason: Turn Facts into an Executable Next Step
Reasoning analyzes the observation results and decides the next action. It should not attempt to answer “what is the complete root cause?” Instead, it should answer “what is the single most valuable hypothesis to test now, and what is the smallest action that can test it?”
Effective reasoning usually contains four layers, though it does not need to produce a long output every time:
- Symptom summary: What is the failure point, and how large is the impact scope?
- Hypothesis ranking: List a small number of mutually exclusive hypotheses and explain which one is most easily falsified by the next step.
- Action selection: Choose one tool or one file change and state the expected result. If the expected result does not match the subsequent observation, the hypothesis is rejected.
- Risk assessment: Is this step reversible? Does it touch production data or permission boundaries? High-risk actions should be downgraded to read-only verification or handed to a human for confirmation.
A common reasoning failure is planning too far ahead. Environment feedback can overturn the first half of a plan, making later steps invalid commitments. A safer approach is short planning and fast verification, committing only to the next step in each round.
3. Act: Change or Probe the Environment Through Tools
Action executes operations through tools and then returns new results to observation. Actions should be as atomic as possible: read a section of code, apply one patch, run one relevant group of checks, or send one read-only query. Atomic actions provide three benefits: when something fails, it is clear which step introduced the failure; rollback cost is low; and the context retains a clear trace rather than a mixed bundle of output.
Consider an example of automatically fixing a failing check. A reasonable trajectory is: read the failure summary and relevant source files, locate the branch that is inconsistent with the assertion, make the smallest change, re-run the same group of checks, and then decide whether to continue or stop based on the new pass or fail result. The loop continues until the task is complete, an unsolvable problem is encountered, or an execution limit is triggered. The agent must not declare completion without re-verification.
What the Execution Framework Must Add Beyond the Model
An LLM does not inherently provide a reliable clock, permissions, persistent state, or hard limits. These must be supplied by the execution framework.
State and memory. The loop needs short-term working memory: the current goal, attempted steps, rejected hypotheses, and unverified points. For long tasks, key conclusions should also be recorded in the task record to avoid repeating mistakes after context truncation. Memory should distinguish “confirmed” from “pending verification” so the model does not treat its previous guesses as facts.
Permissions and sandboxing. Tools should be exposed with least privilege. During a read-only investigation phase, write access and external side effects should not be open. Writes should be limited to specific directories and file types. Calls to external systems should distinguish between queries and changes. The framework is responsible for authentication, parameter validation, and auditing, rather than expecting the model to “remember not to exceed its authority.”
Stop conditions. These should include at least: goal achieved (checks pass, deliverables complete), clearly unreachable (missing permissions, dependencies absent, contradictory requirements), budget exhausted (turn, time, token, or cost limits), and repeated failure (the same error occurs consecutively with no new information). A loop without stop conditions will exhaust resources in low-value retries.
Human gates. Irreversible actions such as deleting data, changing production configuration, or sending external messages should pause at the framework layer and request confirmation. The confirmation information should include an action summary and expected impact, not a vague “continue?”
Tools and Skills Have Different Responsibilities
Tools are the execution framework’s external capability interfaces. They answer “can this be done?” Typical categories include file read/write, command execution, retrieval, API calls, and ticket or message writes. Each tool should have a clear input/output contract, error semantics, and side-effect description. What the model sees should be a stable, narrow interface, not all underlying parameters exposed as-is.
Skills are task-oriented process knowledge. They answer “how should this be done?” A skill packages the observation order, reasoning points, completion criteria, and prohibitions for a type of work so the loop can load it when entering that task type. For example, “fix a failing check” can specify: first read the failure summary, then read the relevant implementation and tests, prohibit broad rewrites without reproducing the failure, and define completion as the same check changing from fail to pass without introducing unrelated changes.
The two should not be mixed. Putting process instructions into tool descriptions makes tools bloated and hard to reuse. Putting specific interface parameters into skill text makes the skill fail when the environment changes. A sound division is: skills describe strategy and acceptance, tools provide actions and facts, and the loop decides when to call which one based on observations.
Skills should also be composable and trimmable. General skills should stay short, for example: “read-only first, then hypothesize, then make the smallest change, then verify again.” Domain skills should add only the checks for that domain, such as API contracts, data consistency, or permission models. Loading too many skills consumes context, and the result is often worse than a single clear completion criterion.
How Context Serves the Loop
Context is not a copy of the repository. It is the evidence package needed for the current decision. Assemble it in priority order:
- The current goal and acceptance criteria, placed first to keep the loop from drifting.
- The latest observations, including failure summaries and key fragments, so reasoning faces fresh facts.
- Attempted actions and results, to avoid repeating the same patch.
- Short constraints from relevant skills, not the full manual.
- Background documents only when necessary.
When context approaches its limit, compress history rather than dropping the latest failure information. Compression should retain the goal, open hypotheses, rejected hypotheses, and the raw error from the last action. Losing these causes the model to retry as if it had lost memory.
Failure Modes and Countermeasures
Premature action. The agent modifies the environment with insufficient observation. Countermeasure: the framework checks whether relevant evidence has been read before a write, or the skill makes “read before write” a hard step.
Hypothesis stickiness. New observations have already rejected an old hypothesis, but reasoning continues patching along the old approach. Countermeasure: explicitly mark hypothesis status in the record. If two consecutive rounds produce no new evidence, force a hypothesis change or escalate to a human.
Tool misuse. Parameters are correct but semantics are wrong, for example executing in the wrong directory or querying an outdated environment. Countermeasure: tool returns should include the actual target object and environment identifier so the observation phase can detect that the wrong target was hit.
False completion. The model announces success in natural language, but checks still fail. Countermeasure: completion is determined by the framework based on acceptance signals, not by the model’s self-report.
Infinite loops and cost overruns. The same error appears repeatedly. Countermeasure: turn limits, error fingerprint deduplication, and cooldowns for identical actions.
Context contamination. Irrelevant logs, secrets, or oversized responses remain in the conversation. Countermeasure: truncate and redact during the observation phase. Secrets should enter reasoning only as conclusions such as “exists” or “does not exist.”
Observability and Evaluation
After an agent is deployed, it should be possible to answer: why did this round take this action, and which observation was it based on? It is recommended to record the goal, observation summary for each round, selected hypothesis, tool name and parameter summary, result status, and stop reason. Logs are for review, not for leaving sensitive raw text scattered in uncontrolled locations long term.
Evaluation should not look only at the final success rate. Process metrics are equally important: average number of turns, invalid retry ratio, human intervention rate, scope of unintended changes, and whether acceptance signals actually flipped. Using a fixed task set to compare “with and without skill constraints” and “whether observations are structured” is more reliable than subjective impressions. The task set should cover the happy path, insufficient information, insufficient permissions, and contradictory requirements. Avoid proving the agent only on simple examples.
A Minimal Closed Loop for Implementation
Start with a narrow task rather than building a general assistant from the beginning. Select a single acceptance signal, such as a specific group of checks that must pass. Expose only read-only tools and one controlled write location. Write one short skill: read the failure, locate the relevant files, make the smallest change, and re-run the check. Set a turn limit and confirmation for irreversible actions. After this works, add retrieval, more file types, or a second task domain.
Each time a new tool category is added, error semantics, permissions, and logging must be added at the same time, not just a new name the model can call. The depth of the execution framework determines whether the LLM’s reasoning can become repeatable engineering results.
Conclusion
The value of an agent comes from separation of responsibilities: the LLM performs short-range reasoning under incomplete information, while the execution framework ensures that observations are real, actions are controlled, results are verifiable, and failures can stop. Observation provides facts, reasoning produces a falsifiable next step, and action changes or probes the environment and immediately returns to observation. Tools answer “what can be done,” while skills answer “how this type of task should be done and what counts as done.” Building along this boundary allows a system to evolve from fluent text generation into auditable, iterable task execution.
