AI Agent Architecture: How LLMs and Execution Harnesses Work Together

    Reliable AI agents depend on more than a capable language model. This article explains how an execution harness turns model decisions into controlled actions through an observe–reason–act loop, context and tool management, persistent state, and verification. A code repair example illustrates the workflow, followed by practical considerations for termination, security, recovery, and system-level evaluation.

    1. Understanding AI Agents: The Model Decides, the Harness Executes

    “Agent = LLM + Harness” is a useful shorthand for understanding AI agents. A large language model interprets tasks, analyzes information, and selects actions. An execution harness turns those decisions into controlled, traceable operations.

    Here, harness refers to the runtime support mechanisms built around the model, not a particular tool. It typically includes context organization, tool integration, permission checks, task state management, execution budgets, error handling, and result verification.

    This is not a strict mathematical equation, nor does it imply that connecting a model to a few tools automatically produces a reliable agent. It highlights two complementary layers:

    • Model layer: Understands the goal and proposes the next action based on available evidence.
    • Execution layer: Determines whether an action is allowed, executes it, records the result, and decides whether execution should continue.

    For example, a model may decide that a function needs to be modified. Reading the file, checking write permissions, applying a patch, saving the change, and running tests are responsibilities of the harness. If the proposed operation violates permission or parameter constraints, the harness should reject it rather than execute it unconditionally.

    An agent’s practical performance therefore depends not only on model capability, but also on the information it can access, the tools it can use, and how effectively its execution is managed.

    2. The Core Mechanism: An Observe–Reason–Act Feedback Loop

    An agent’s workflow can usually be described as Observe, Reason, Act.

    Observe: Turn Environmental Changes into Usable Evidence

    Observation gathers information relevant to the current task, such as file contents, test reports, API responses, permission status, and the results of previous operations.

    Observation does not mean placing all available data into the model’s context. The harness must select information according to the task goal, preserve important evidence, and identify its source and timestamp. Excessive logs and irrelevant text can obscure the actual problem while increasing processing costs.

    For code repair, useful observations typically include failing test cases, error locations, relevant functions, and recent changes—not the entire codebase. Truncated logs, unreadable files, and incomplete responses should be explicitly marked so that the model does not treat missing information as verified fact.

    Reason: Select the Next Action Based on Evidence

    The purpose of reasoning is to choose the next executable action, not to produce a seemingly complete plan in a single pass.

    When information is insufficient, the appropriate next step may be to read additional files. When the cause is reasonably clear, the model may propose a focused change. When an operation carries significant risk, it should request human approval.

    Hypotheses must remain distinct from conclusions. For example, “a boundary condition may be missing” is a hypothesis to test, not proof that the root cause has been found. A more reliable process forms a hypothesis and then selects an action that can support or disprove it.

    Auditing should not depend on the model exposing detailed internal reasoning. More useful operational records include a concise rationale for each action, the evidence cited, execution results, and verification conclusions.

    Act: Execute Operations and Generate New Feedback

    During the action stage, tools interact with the environment—for example, by reading files, applying targeted changes, running tests, or querying business process status.

    A tool call is not proof that the task is complete. A “successful” tool response may mean only that a file was written, not that the modification is correct. Similarly, acceptance of an API request does not establish that the corresponding business process has finished.

    Action results must therefore feed back into observation. The agent should revise its decisions based on new evidence rather than mechanically follow its original plan.

    The complete loop can be represented as:

    Task goal → Gather environmental information → Select an action → Validate and execute → Collect results → Update state → Continue or terminate

    3. Key Responsibilities of the Execution Harness

    Context Management: Keep Information Accurate and Relevant

    Context capacity is limited, while real tasks may run for extended periods. The harness must manage the task goal, operation history, important evidence, constraints, and unresolved questions.

    A practical approach separates information into three categories:

    • Persistent constraints: Task goals, authorization boundaries, prohibited operations, and acceptance criteria.
    • Current working set: File excerpts, error messages, and tool results needed for the current decision.
    • Historical summaries: Approaches already attempted, reasons for failure, and confirmed facts.

    Summaries should preserve the relationship between facts and supporting evidence. “The configuration has been checked” is too vague. “The timeout setting has been read from the configuration, but its use in the actual runtime environment has not been confirmed” provides a better basis for subsequent decisions.

    Context management must also prevent external content from being mistaken for system instructions. Files, logs, and API responses may contain directive language. Such text should be treated as data to analyze, not as authority to change the agent’s permissions or safety rules.

    Tool Management: Define Capabilities, Inputs, and Side Effects

    Tool descriptions should explain each tool’s purpose, input requirements, output meaning, and potential side effects.

    Read-only and write-capable tools require different controls. Reading logs generally does not alter the environment. Modifying files, sending messages, or updating data can have real consequences and requires stricter permission checks.

    Before execution, the harness should check:

    • Whether parameters satisfy format and value requirements.
    • Whether the target resource is within the permitted scope.
    • Whether the operation requires human approval.
    • Whether the current environment is suitable for execution.
    • Whether there are risks involving timeouts, duplicate submissions, or unrecoverable effects.

    For operations that support idempotent semantics, mechanisms such as task identifiers can help reduce the impact of repeated execution. Non-idempotent operations require cautious retry handling: an uncertain result should not trigger an immediate duplicate submission.

    State Management: Make Long-Running Tasks Recoverable and Explainable

    Agent state should not exist only in conversation text. Important state should be stored in a structured form, including the current phase, completed steps, hypotheses awaiting validation, tool execution records, budget consumption, and the latest valid result.

    Persistent state allows a task to resume after a process interruption, supports troubleshooting when an operation fails, and helps avoid repeating work across attempts.

    However, recovery cannot rely on historical records alone. The external environment may have changed. Before resuming, the harness should recheck critical assumptions, such as whether someone else has modified a file, whether a data version has changed, and whether permissions remain valid.

    4. Practical Example: A Code Repair Workflow

    Consider the task: “Fix the test failure caused by an input validation function and confirm that the change does not introduce related regressions.”

    Step 1: Define the Goal and Boundaries

    The harness first establishes which directories may be modified, which testing capabilities are available, whether external network access is prohibited, and whether test files may be changed.

    Acceptance criteria should also be defined upfront. At a minimum, the original failing test must pass, related regression tests must pass, and the changes must remain within the authorized scope. “No error was observed” is not an adequate completion criterion on its own.

    Step 2: Gather Evidence of the Failure

    The agent reads the failure report, identifies the difference between actual and expected output, and inspects the relevant function and necessary calling context.

    If the report shows that empty input triggers an exception, the investigation should focus on the input-handling path rather than immediately rewriting the module. Specific evidence makes subsequent changes easier to control.

    Step 3: Propose the Smallest Necessary Change

    Based on the evidence, the model proposes a repair, such as adding missing boundary handling. Before execution, the proposed behavior should be checked against the function’s contract and any caller dependencies on the existing behavior.

    A “minimal change” is not simply the change with the fewest lines. It minimizes changes unrelated to the task while fully resolving the confirmed issue.

    Step 4: Validate in Stages

    First, run the directly relevant tests to determine quickly whether the original issue has been resolved. Then run regression tests for the affected module to assess the impact. Expand the validation scope when necessary.

    If tests still fail, the new results become evidence for the next observation cycle. The agent should revisit its hypothesis rather than repeat the same modification without justification.

    Step 5: Report Verifiable Results

    The final report should describe the changes, validation scope, test results, and remaining risks. If environmental constraints prevent a full test run, that limitation must be disclosed. Partial verification must not be presented as comprehensive success.

    5. Termination: Completing a Task Is Not the Same as Stopping Execution

    A reliable agent needs explicit termination mechanisms.

    Successful completion should depend on observable acceptance evidence: the target tests pass, an output file exists and its contents have been validated, or a business process reaches the expected state. The model’s statement that it has finished cannot replace this evidence.

    Execution may also stop because:

    • A time, call-count, or cost budget has been reached.
    • Required permissions or essential inputs are missing.
    • Repeated attempts produce no meaningful progress.
    • A high-risk or irreversible operation is detected.
    • Environmental problems prevent reliable result verification.

    Lack of progress can be assessed using repeated operations, recurring errors, and changes in task state. The specific rules should match the task type.

    After stopping, the system should distinguish between statuses such as completed, awaiting human intervention, insufficiently verified, and execution failed. These distinctions prevent users from mistaking a stopped run for a successful outcome.

    6. Security and Reliability Must Be Enforced by the Harness

    Least Privilege and Environment Isolation

    An agent should receive only the permissions needed for its task. A need to read files does not justify default write access to the entire workspace. A need to validate code does not justify default access to production systems.

    Operations that may affect system state should preferably run in an isolated environment with resource, network, and file-access boundaries. The model’s ability to propose an operation does not mean it should be authorized to execute it.

    Protection Against Misleading External Content

    Logs, documents, and tool responses may contain misleading instructions. The harness should preserve boundaries between instruction sources and use trusted rules for authorization decisions. External text claiming that an operation “must be executed” must not expand the agent’s permissions.

    Audit Records and Sensitive Data Controls

    Audit records should capture operation times, target resources, execution status, and important results. They should not indiscriminately retain all raw content.

    Sensitive information should be redacted as needed. High-risk data such as credentials should not be placed directly into model context or ordinary logs.

    Recovery Strategies That Match the Operation

    Temporary errors such as network timeouts may justify retries. Permission denials and invalid parameters usually require a change in conditions or a stop.

    For write operations with uncertain outcomes, the agent should check the current state before deciding whether to retry. This reduces the risk of duplicate side effects.

    7. Evaluating Whether an Agent Is Reliable

    Evaluation should focus on the performance of the complete task system, not just the fluency of the model’s responses.

    Useful evaluation dimensions include:

    • Task quality: Whether acceptance criteria are met and results can be verified.
    • Execution efficiency: Whether tool calls and repeated attempts are productive.
    • Security boundaries: Whether unauthorized actions or unapproved high-risk operations occur.
    • Recovery capability: Whether execution can resume after interruption and revalidate environmental state.
    • Cost control: Whether time and resource consumption remain acceptable.
    • Result transparency: Whether validation scope, uncertainty, and unresolved issues are clearly disclosed.

    These dimensions should be considered together. A fast execution with inadequate verification is not necessarily better than a slightly slower execution supported by complete evidence.

    8. Conclusion: From Answer Generation to Controlled Execution

    The core value of an AI agent is its ability to advance a task using feedback from the environment, rather than merely generate a one-time answer. The LLM provides understanding and decision-making capabilities. The execution harness places those decisions within explicit permission, state, budget, and verification controls.

    Observation, reasoning, and action form the basic feedback loop. Context management determines evidence quality, tool management defines action boundaries, state management supports ongoing execution, and acceptance and termination mechanisms provide an evidence-based way to end the task.

    Building reliable agents begins with clear task goals and acceptance criteria, followed by the design of tools, permissions, and feedback mechanisms. Model capabilities become dependable engineering value only when every action can be constrained, every result can be verified, and every stop can be explained.