Why the Same LLM Performs Differently: Understanding the Agent Harness

    This article explains why an unchanged model can behave very differently across applications. It breaks an agent application into model inference, the harness that organizes execution, and external data and runtime environments, then walks through the role of each layer: the LLM, prompts, context, RAG, tools, agents, and the harness itself. It also gives a minimal control loop, a practical checklist for diagnosing inconsistent results, and the layered evaluation and security measures needed to move from a demo to production.

    1. The Model Did Not Change, So Why Did the Experience Change?

    Many developers have run into this: a model understands requirements precisely in a chat interface, then frequently misreads code once it is wired into a coding tool; the same model moved into a different application can handle more complex tasks.

    This difference does not necessarily mean the model itself changed. What users actually interact with is usually not an isolated model but a complete application system. The system decides what information reaches the model, which tools the model may call, how execution results are handled, and when the model keeps reasoning or stops.

    The runtime and control layer that organizes these parts is commonly called a Harness; this article refers to it as the harness layer.

    A simplified relationship helps:

    Agent application = model inference capability + harness organization capability + external data and execution environment

    This is not a strict formula but a way to decompose a system. The model supplies understanding, generation, and reasoning; the harness connects those capabilities to a real task and controls the execution process.

    “The model sets the ceiling, the harness determines how much of it you get” is a useful engineering intuition, but not an absolute rule. Retrieval, computation tools, extra reasoning turns, and external verification can all expand the range of tasks the system can complete. A more accurate statement is: the final result depends on the combined effect of the model, the information, the tools, and the control strategy.

    2. The LLM: Reasoning and Generation, Not a Complete Application

    An LLM, or large language model, generates by predicting subsequent tokens from an input sequence. A token is the basic unit the model processes information in, and it does not always correspond to one word.

    Through training, the model acquires language understanding, knowledge expression, code generation, and a degree of reasoning. But there is still a clear gap between “can produce a solution” and “can complete a real task.”

    2.1 Parametric Knowledge Is Not Live Business Knowledge

    Knowledge formed during training cannot be guaranteed to cover the latest events, internal company documents, or the current state of a particular repository.

    For example, a model may know general principles of access control but not know that an enterprise just changed its approval workflow. Without external material, it may fill in the answer from common patterns rather than give a conclusion that matches actual policy.

    So whether the model answers correctly often depends first on whether the system supplied the right evidence.

    2.2 Model Calls Do Not Come With Persistent Memory

    With common stateless inference APIs, the model does not automatically retain the previous request. The application must resubmit the relevant history or retrieve the necessary information through a session store.

    Some services do offer session management, but that is a surrounding service capability; it does not mean the model itself has unlimited, permanent, reliable memory.

    2.3 Emitting a Tool Call Is Not Executing a Tool

    A model can propose “read the config file” or produce a structured call request, but the component that actually reads files, runs programs, or queries databases is usually the external runtime.

    Modern model APIs are not necessarily “text in, text out” either. They may support structured messages, multimodal input, or tool call descriptions. Still, an API that can express intent to call is a different thing from an application that has safe, reliable execution capability.

    3. Prompt: Specifying the Goal, Not Casting a Spell

    A prompt is the instruction and task description the application passes to the model. It includes more than user input: it may also contain system rules, output format, examples, and tool usage constraints.

    An effective prompt usually answers four questions:

    • What task must be completed?
    • Which constraints must not be violated?
    • Which information and tools may be used?
    • What counts as a finished result?

    For instance, “help me fix the program” has no clear boundary. A more actionable task description would be:

    Analyze why the tests in the specified module fail, and change only the code directly related to the problem. After the change, run the relevant tests and describe what was changed and what was verified. If the tests cannot be run, say so explicitly; do not claim verification passed.

    The value of such a prompt is that it reduces ambiguity and turns “produce an answer” into “deliver a verifiable result.”

    A prompt cannot replace real access control. Even if it says “do not delete important files,” the execution environment must still block dangerous operations. Behavioral instructions guide; permission mechanisms constrain. The two must not be conflated.

    4. Context: What the Model Actually Sees This Turn

    Context is the set of information visible to the model in a single inference call. It typically includes:

    • System rules and developer instructions;
    • The current user request;
    • Retained conversation history;
    • Retrieved document fragments;
    • Tool descriptions and tool return values;
    • Current task state or a stage summary.

    The prompt is usually part of the context, but the context also contains a large amount of non-instructional information.

    4.1 The Same Task With Different Context Is a Different Input

    Suppose users in both cases ask to “fix the error.” One application supplies only the error description; another supplies the stack trace, the relevant functions, the test code, and runtime information. The actual difficulty the model faces is completely different.

    Much of what looks like “the model got dumber” is really missing context: a key definition absent, a file truncated, tool results not returned, or a previously confirmed constraint dropped.

    4.2 More Context Is Not Always Better

    The context window has capacity limits, and input also affects latency and cost. Pushing every file, message, and retrieval result into it can create duplication, contradictions, and diluted attention.

    Effective context management prioritizes:

    1. The current task goal and hard constraints;
    2. Evidence directly relevant to the problem;
    3. The most recent execution results;
    4. Unresolved questions;
    5. User decisions that must keep being honored.

    History can be compressed, but the summary must retain important facts. For example, “the user asked not to change the public interface” must not be compressed into “the user wants the code changed.”

    4.3 Memory Should Distinguish Purpose and Lifetime

    In engineering terms, short-term session state, task state, and long-term preferences can be separated. Their reliability requirements differ.

    User preferences can serve as supporting information; permission configuration and financial data should come from authoritative systems, not from a model-generated summary. Memory also needs rules for updates, expiry, deletion, and access so that stale information does not keep influencing decisions.

    5. RAG: Retrieve Evidence First, Then Compose the Answer

    RAG, or retrieval-augmented generation, retrieves relevant information from external knowledge sources before generating an answer and adds it to the context.

    A typical flow:

    User question → query processing → document retrieval → relevance filtering → context assembly → model generation → grounding check

    It usually does not require changing model parameters; it changes the evidence available when the model answers.

    5.1 Retrieval Augmentation Is First a Data Engineering Problem

    For a model to answer enterprise policy questions accurately, the documents must be complete, clearly versioned, parseable, and subject to correct access permissions.

    Chunking also affects quality. Fragments that are too small may lose conditions and exceptions; fragments that are too large may pull in irrelevant content. Policies, code, and tables each call for handling that fits their structure.

    Retrieval can use keyword search, semantic search, or a hybrid. Reranking can then prioritize the more valuable evidence.

    5.2 Retrieved Does Not Mean Correct

    Retrieval augmentation can still fail:

    • The question has several conditions but retrieval covers only one;
    • An outdated document version is returned;
    • Similar wording maps to different business scenarios;
    • When evidence is insufficient, the model keeps filling in unsupported conclusions.

    The harness therefore needs to preserve sources, versions, and necessary locators, and to allow the system to answer “the available material is not enough to confirm this.”

    Permission filtering should happen before material enters the model context, not after sensitive content has been handed to the model with an instruction not to leak it.

    6. Tools: Connecting Language Reasoning to Real Operations

    A tool is an external capability the model or application can call, such as reading a file, querying a database, running tests, or submitting a business operation.

    Reliable tool design specifies:

    • Functional boundary and input requirements;
    • Output structure and failure types;
    • Required permissions;
    • Whether there are side effects;
    • Timeout, retry, and resource limits.

    For example, “perform any operation” is a broad tool that is hard to control; “read a file under the specified directory” makes it much easier to establish a permission boundary.

    6.1 Tool Output Should Support the Next Decision

    If a tool returns only “failed,” the model can hardly tell whether to retry, change parameters, or stop.

    A more useful result includes execution status, the relevant error, necessary output, and whether a side effect already occurred. For code tests, it should provide the failing cases and their locations where possible, not just a messy log.

    6.2 Side-Effecting Operations Need Special Handling

    Querying data and deleting data are not the same risk level. Operations that modify files, send notifications, or change permissions should have approval, confirmation, or isolation mechanisms matched to their risk.

    Retry is not unconditionally safe either. Read requests can usually be re-executed, but resubmitting a business operation that already went through can create duplicate records. The tool layer should account for idempotency, operation identifiers, and result reconciliation.

    7. Agent: A System That Keeps Acting on Feedback

    An agent is a system that selects actions around a goal, uses tools, and adjusts subsequent steps based on execution feedback.

    It does not need intent in the human sense, nor does it mean unlimited autonomy.

    A typical loop:

    Understand the goal → choose the next step → call a tool → observe the result → update state → continue or stop

    To fix a failing test, an agent might first read the error, then locate the function, change the code, and run the tests; if the tests still fail, it continues analyzing based on the new result.

    Compared with one-shot question answering, the key difference is: the output is not the end of the task; external feedback re-enters the next decision.

    Not every scenario needs such an autonomous loop. For tasks with stable processes and strict audit requirements, a fixed workflow that uses the model only in some steps is an option. It is often easier to control risk, cost, and execution path.

    8. Harness: The Layer That Organizes the Whole Run

    There is no fully unified industry definition of Harness. Different systems may use it for a surrounding execution framework, an evaluation framework, or a control environment. This article discusses the harness layer in agent runtime scenarios.

    Its responsibilities typically include:

    8.1 Assembling Model Input

    Deciding which rules to apply, which history to keep, which material to retrieve, and how to organize information within the context budget.

    8.2 Scheduling Tools and Execution Flow

    Parsing the call requests the model proposes, checking parameters and permissions, running the tools, and feeding results back to the model.

    8.3 Maintaining Task State

    Recording completed steps, open questions, and key constraints so that multi-turn execution does not restart from scratch.

    8.4 Managing Budget and Stop Conditions

    Limiting call turns, execution time, output length, and tool resources to prevent repeated calls or futile retries.

    8.5 Verifying Results

    Using tests, structural checks, business rules, or human confirmation to decide whether the task is done, rather than trusting the model’s claim that it is.

    8.6 Providing Observability and Safety Controls

    Logging the input, output, duration, and status of each step, and protecting sensitive data and high-risk operations.

    Prompt, context, RAG, and tools can be organized by the harness but are not necessarily implemented by it. Retrieval may be a separate service, and tools may live in a controlled execution environment. The point of the harness is coordination, not doing everything itself.

    9. A Minimal Runtime Loop: Control Matters More Than Code Length

    The following is conceptual pseudocode, not the API of any specific service:

    1. state = initializeTask(userGoal, permissions, budget)
    2. while budget not exhausted:
    3. evidence = fetchRelevantMaterial(state, permissions)
    4. context = assembleInput(rules, state, evidence, recentExecutionResults)
    5. modelResult = callModel(context)
    6. if modelResult proposes a tool call:
    7. validateCallFormatAndPermissions()
    8. if operationRisk is high:
    9. obtainRequiredConfirmation()
    10. executionResult = runToolInControlledEnvironment()
    11. updateState(executionResult)
    12. continue
    13. if modelResult proposes a final answer:
    14. verification = checkTaskRequirementsAndEvidence()
    15. if verification passes:
    16. return answer
    17. else:
    18. writeMissingItemsToState()
    19. return incompleteNoticeWithKnownResults

    A real system must also handle execution timeouts, cancelled requests, partial success, unavailable tools, and state recovery. Model output format needs validation too; you cannot assume it always matches the contract.

    10. How to Diagnose “Same Model, Different Results”

    First, confirm that the comparison conditions really are the same. The same API credentials do not necessarily mean the same model version, routing, inference configuration, or server-side policy.

    A suggested order of investigation:

    10.1 Compare the Actual Input, Not Just the User Question

    Record and compare system rules, history summaries, retrieved fragments, tool definitions, and tool outputs. Privacy data in logs should be masked.

    If one system provides the full error information and the other does not, the difference in results cannot simply be attributed to model capability.

    10.2 Check Whether the Context Is Complete and Consistent

    Look closely at file truncation, lost history, conflicting document versions, and key constraints dropped by summarization.

    10.3 Check Whether the Tool Chain Really Works

    A tool name existing does not mean permissions are correct, execution succeeded, or results reached the model. Also distinguish the model not choosing a tool, wrong call parameters, and the tool itself failing.

    10.4 Check the Definition of Done

    If the system lets the model finish without running tests, you easily get results that look fixed but were never verified.

    10.5 Evaluate Differences With Repeated Trials

    Model output is stochastic, and a single run does not prove one configuration is better. Use a fixed task set, multiple runs, and consistent judging criteria, and evaluate accuracy, completion rate, latency, cost, and safety behavior separately.

    11. From Demo to Production: What Engineering Is Needed?

    Before shipping, establish layered evaluation instead of judging only whether answers read smoothly.

    The retrieval layer is evaluated on whether the right material was found, whether permissions were correct, and whether old versions were excluded.

    The generation layer is evaluated on whether conclusions are supported by evidence, whether the format is respected, and whether uncertainty is stated clearly.

    The execution layer is evaluated on tool selection, parameter accuracy, exception handling, and side-effect control.

    The system layer is evaluated on task completion rate, stability across repeated runs, resource consumption, and the share of cases needing human intervention.

    Prompt injection risk also deserves attention: external web pages, documents, and tool outputs may contain inducing instructions. The system must separate trusted control instructions from untrusted material and avoid treating text inside material as a high-priority command. A single sentence saying “ignore malicious content” is not enough for safety; permission isolation, output validation, and operation approval are still required.

    Architecture choices should stay restrained. A document Q&A task may need only retrieval and generation; a business task with a clear process may suit a fixed workflow; only tasks that require exploration, iteration, and handling environment feedback are a better fit for an agent loop.

    Conclusion: Application Performance Is a System Capability, Not Only a Model Capability

    These concepts line up along a clear chain:

    The LLM provides reasoning and generation, the prompt describes the goal and constraints, the context carries this turn’s information, RAG adds external evidence, tools perform real operations, the agent keeps going based on feedback, and the harness organizes and controls the whole process.

    The same model API shows different results largely because the surrounding system changed what information the model can see, what actions it can take, and how results get verified.

    For developers, what is worth optimizing is not one “magic prompt” but the full chain from information retrieval and context management to tool execution and result verification. Only when that chain is reliable can the model’s capability turn consistently into real task outcomes.