Why the Same LLM Behaves Differently: Understanding the Harness Layer

    A single LLM can appear more capable in one application than another because the surrounding harness changes the inputs, tools, state, permissions, feedback loops, and verification. This article explains the distinct responsibilities of the LLM, prompt, context, RAG, tools, agents, and harness, then offers engineering guidance for diagnosing whether a performance gap comes from the model or from the execution pipeline, with an order-calculation example and an evaluation checklist.

    1. The Same API Does Not Mean the Same Task

    Developers often encounter a familiar pattern: a model answers clearly in a chat interface, but after it is connected to an AI coding tool, it repeatedly edits the wrong files. Switch to another application, and the same model can locate the problem accurately and complete verification.

    This does not necessarily mean the model’s capability has changed. More often, the model is receiving different information, has access to different tools, and operates within a different post-response execution flow.

    For example, suppose the user only says, “Fix the order amount calculation error.” Different applications may handle that sentence in very different ways:

    • Application A sends only that sentence to the model and asks for a suggested fix.
    • Application B includes the current file but does not provide related tests or call relationships.
    • Application C first searches for the calculation logic, reads the relevant files, asks the model for a modification plan, runs tests, and sends failure information back to the model for further repair.

    Even with the same underlying model, the task completion rate can differ significantly across these three approaches. The model did not become smarter out of nowhere; the third application gave it more sufficient evidence and a more complete feedback loop.

    The runtime mechanism surrounding the model is commonly called the Harness, which can be understood as a “harness layer” or “runtime control framework.” It is not a fully standardized component with a single definition. Rather, it is a set of engineering mechanisms responsible for organizing input, scheduling execution, maintaining state, and validating results.

    It is also important to note that a chat interface and an API call may not actually use the same model version, inference configuration, or additional capabilities. When analyzing differences in experience, first confirm the underlying conditions, and then evaluate the influence of the harness.

    2. Clarify the Responsibility of Each Concept

    The most effective way to understand LLM applications is not to memorize terms one by one, but to clarify what problem each concept solves.

    Concept Primary responsibility Not simply equivalent to
    LLM, large language model Generate content, perform reasoning, and propose actions based on input A complete business system
    Prompt Describe the task, constraints, role, and output requirements All input information
    Context Provide instructions, history, materials, and tool results visible to the current call Permanent memory
    RAG, retrieval-augmented generation Retrieve external material and use it as the basis for generation Retraining the model
    Tool Perform operations such as querying, reading, calculating, or writing A capability of the model itself
    Agent Choose actions around a goal and continue execution based on feedback A single ordinary chat call
    Harness Organize the model, state, tools, permissions, and execution flow Just a system prompt

    These concepts are not strictly mutually exclusive “seven layers.” For example, retrieval can be called by an agent as a tool, or it can be completed by a fixed workflow before the model is invoked. Both prompts and retrieval results can become part of the context.

    One useful way to understand the relationship is:

    1. User goal
    2. ↓
    3. Harness: state management, context construction, execution control, permissions, and verification
    4. ├─ Prompt and task constraints
    5. ├─ History and persistent memory
    6. ├─ Retrieved external material
    7. ├─ Callable tools
    8. └─ Large language model
    9. ↓
    10. Answer or action proposal
    11. ↓
    12. Execute, verify, continue, or stop

    3. LLM: The Core of Generation and Reasoning, but Not the Whole System

    From a generation perspective, a large language model typically predicts the next token based on the existing sequence. A token is the basic unit used by the model when processing text; it does not necessarily correspond to one Chinese character or one complete word.

    This mechanism can support question answering, code generation, summarization, and multi-step reasoning, but it does not mean the model inherently has a complete runtime environment.

    3.1 Conversational memory must be provided by the system

    In common stateless API calls, the model works only with the information provided in the current request. If something discussed in a previous turn is not passed in again or provided through another state mechanism, the application cannot assume the model still knows it.

    Therefore, the application must decide which history to retain, which to compress, and which to persist. What is often called “memory capability” frequently comes from storage and retrieval at the application layer, not from a change in the model’s parameters.

    3.2 Training knowledge is not the same as real-time facts

    A model may possess general knowledge, but it cannot accurately know the latest business rules, private codebase, or recent events solely from its training parameters. When such information is involved, external data is needed as evidence.

    Even if the model answers fluently, that does not mean the answer has a reliable source. Fluency and factual accuracy must be evaluated separately.

    3.3 Generating an action description is not executing an action

    A model can output a suggestion such as “read the configuration file” or “run the tests,” and it can also generate a structured tool-call request. However, actual file reading, command execution, and database access are still performed by external programs.

    Therefore, “the model says it has fixed the issue” and “the system verifies that the fix succeeded” are two different things. A reliable application must distinguish between them.

    4. Prompt and Context: Clear Instructions Plus Sufficient Evidence

    A prompt answers “what to do and by what rules”; context answers “what information can be used to complete the task.”

    4.1 Prompts should define verifiable task requirements

    “You are an experienced developer” provides only broad role guidance; it cannot replace a specific task definition.

    More effective requirements usually include:

    • Goal: what symptom to fix and what the expected behavior is.
    • Scope: which files may be modified and which interfaces must not change.
    • Constraints: whether new dependencies are allowed and whether sensitive data is involved.
    • Verification: which tests or checks must pass.
    • Handling uncertainty: when information is missing, query first rather than inventing it.

    The value of a prompt is not in its length, but in reducing ambiguity, clarifying boundaries, and making the output subject to inspection.

    4.2 More context is not always better

    Dumping an entire codebase or a large volume of documentation into the model at once can increase noise, raise costs, and dilute important information.

    A more reasonable approach is to organize context by task. For example, when fixing an amount calculation issue, prioritize the calculation function, call sites, amount type definitions, failing tests, and business rules rather than a large amount of unrelated page code.

    Context management should also consider the freshness of information. Modified files, old test results, and expired task summaries may cause the model to continue working from an incorrect state if they are not updated.

    4.3 Long-term memory should retain sources and scope

    Project conventions, user preferences, and historical decisions can be persisted, but it is better not to store only unverified natural-language summaries. Important memories should ideally record their source, time, applicable scope, and invalidation conditions.

    For example, “amounts keep two decimal places” may apply only to the presentation layer, not to internal calculations. Losing that scope turns helpful memory into an incorrect constraint.

    5. RAG: Turn External Knowledge into Usable Evidence

    RAG, or retrieval-augmented generation, usually includes the following process:

    1. Question parsing → retrieve candidate material → filter and rank
    2. → assemble context → generate answer → check evidence

    Retrieval can be keyword-based, semantic, or a combination of both. The core issue is not which algorithm is used, but whether the system can find information that is relevant to the task, trustworthy, and within the user’s access permissions.

    5.1 Chunking should preserve semantic relationships

    If business rules are split too finely, retrieval may return only a conclusion while missing premises and exceptions. For code material, function signatures, type definitions, and necessary call relationships should be preserved as much as possible.

    Chunking is not simply splitting by a fixed length; it is a trade-off between length limits and semantic completeness.

    5.2 Retrieval results need quality judgment

    Finding material does not mean the material is correct. Outdated specifications, duplicated fragments, and contradictory explanations can all contaminate the answer.

    Therefore, the system should preserve document versions, update times, and source locations where possible, and handle conflicts when necessary. For questions without sufficient evidence, the system should be allowed to answer “insufficient to determine” rather than forcing a conclusion.

    5.3 Permission filtering should happen before material enters context

    The model should not be given all material simply because it “seems unlikely to leak information.” During retrieval, visible content should be restricted according to user and task permissions.

    In addition, retrieval augmentation does not inherently eliminate hallucination. Material may be retrieved incorrectly, and the model may misread it. Citation checks and result verification are still necessary.

    6. Tools: Connect Model Suggestions to the Real Environment

    Tools translate language-level intent into actual operations, such as searching files, reading content, running tests, or querying business state.

    Tool design should focus on three questions.

    6.1 Is the input clear?

    Tools need clear input structures and field constraints. When reading a file, the path should be explicit; when modifying a file, the target and changes should be explicit; when executing a command, the working directory and allowed scope should be restricted.

    Structured input can reduce ambiguity, but it cannot replace parameter validation.

    6.2 Is the output sufficient for the next decision?

    Tool results should distinguish between success, failure, and partial completion, and provide necessary error information. For overly long output, the system can return a summary while preserving a way to read the full content later.

    “Execution failed” alone is usually not enough for the model to locate the problem; conversely, returning a large amount of irrelevant logs in full also increases the burden of understanding.

    6.3 Is the operation controllable?

    Reading a document and deleting a file carry different risks. Tool permissions should follow the principle of least privilege, with approval or confirmation mechanisms for writes, deletions, external sending, and other high-risk actions.

    For operations that may be repeated due to retries, idempotency also needs to be considered. A model call timeout does not necessarily mean the external operation did not occur.

    7. Agent: The Feedback Loop Matters More Than the Role Name

    An agent typically runs an action loop around a goal:

    1. Understand the goal and current state.
    2. Determine what information or operation is needed next.
    3. Call a tool.
    4. Read the tool feedback.
    5. Update state and continue, or finish the task.

    “Agent = LLM + Harness” can serve as a memory aid, but it is not a strict definition. Fixed workflows, single model calls, and autonomous agents exist on a continuum; the main differences lie in who decides actions, whether the execution path is dynamic, and whether the system continuously adjusts based on feedback.

    Not all tasks require an agent. When the process is clear and the steps are fixed, a deterministic workflow is usually easier to test, audit, and cost-control. The agent loop is more valuable only when a task requires dynamic exploration, tool selection, or plan adjustment.

    At the same time, an agent must have stopping conditions, such as reaching the goal, hitting a budget, repeated failure, missing permissions, or requiring human decision-making. A loop without boundaries can easily produce ineffective retries and uncontrollable costs.

    8. Harness: Organize Components into a Reliable System

    The key value of the harness is not to stack more components, but to define how components work together.

    A relatively complete harness usually includes:

    • Context construction: select relevant information, control length, and annotate sources.
    • State management: save plans, completed steps, tool results, and unresolved issues.
    • Execution scheduling: decide call order, concurrency, retries, and timeout handling.
    • Permission control: check whether tool calls comply with user authorization and task boundaries.
    • Result verification: determine whether output meets factual, format, and business requirements.
    • Observability: record call chains, errors, latency, and resource consumption.
    • Termination and escalation: stop execution when the task cannot be completed reliably and hand it over to a human.

    Thus, “the model sets the ceiling, and the harness determines how much of that ceiling is reached” is a helpful summary, but not an absolute law. External retrieval and tools can expand the overall capability of the system; at the same time, incorrect context, permission configuration, and verification mechanisms can also hold back a strong model.

    More precisely, application performance is the combined result of model capability, input quality, external capabilities, and execution control.

    9. A Complete Execution Example for a Coding Task

    Take “fix the order amount calculation error” as an example. A reasonable flow could be:

    Step 1: Define acceptance criteria.
    Confirm whether the error occurs in calculation, rounding, storage, or presentation. If the expected behavior is unclear, ask the user for clarification first.

    Step 2: Locate evidence.
    Search for the relevant functions and read callers, type definitions, and tests rather than guessing based only on file names.

    Step 3: Create a minimal modification plan.
    Explain the cause of the issue, the proposed scope of changes, and the potential impact. If public interfaces or data migration are involved, escalate for confirmation.

    Step 4: Apply changes and verify.
    Run relevant tests and necessary static checks; when conditions allow, add a regression test that reproduces the issue.

    Step 5: Revise based on feedback.
    When tests fail, send meaningful error information back to the model rather than simply repeating the original instruction.

    Step 6: Output verifiable conclusions.
    Report what was changed, which verifications were run, and which risks remain uncovered. If tests were not actually run, state that clearly and do not claim that “everything passed.”

    The following pseudocode illustrates control logic only; it is not an interface from any specific product:

    1. state = initialize_task(user_goal)
    2. while budget_available and task_not_finished:
    3. context = assemble_relevant_evidence(state)
    4. decision = request_model(task_constraints, context)
    5. if decision_requests_tool:
    6. validate_parameters_and_permissions
    7. request_human_confirmation_if_needed
    8. result = execute_tool_and_record_state
    9. update_task_state(result)
    10. else if decision_requests_finish:
    11. if result_meets_acceptance_criteria:
    12. finish
    13. else:
    14. add_feedback_or_escalate
    15. if budget_exceeded or unrecoverable_error:
    16. stop_and_report_completed_work_and_blocking_reason

    10. How to Determine Whether the Problem Is the Model or the Harness

    Do not compare only the final answers. Also compare the inputs the model actually received and the execution trace.

    A recommended troubleshooting order is:

    1. Check model conditions: confirm whether the model version, generation configuration, output length limits, and available capabilities are consistent.
    2. Check the prompt: are there conflicting instructions, and is the task goal clear?
    3. Check the context: are key files missing, is content truncated, and is history outdated?
    4. Check retrieval: was relevant material found, and are there permission or version issues?
    5. Check tools: are parameters correct, are errors fully returned, and does the execution environment match expectations?
    6. Check the feedback loop: does the system stop too early, or retry repeatedly without new information?
    7. Check verification mechanisms: is the model’s self-report being treated as evidence of success?

    For evaluation, use a set of tasks with clear acceptance criteria and repeat tests under the same conditions. Record task success rate, tool-call error rate, human intervention rate, total latency, and resource consumption. Metric definitions need to align with business goals; do not judge effectiveness only by answer length or language fluency.

    By gradually disabling or replacing modules such as retrieval, history compression, and tool feedback, you can observe which part brings actual benefit. This kind of controlled analysis is more diagnostic than “feeling that one tool is smarter.”

    11. Reliability and Security Must Be Designed Together

    The harness connects the model to the real environment, and it also expands the risk surface.

    External documents, web content, and code comments may contain persuasive instructions. The system should treat this content as data to be analyzed, not as an authorized source that can override task rules.

    In particular, merely stating in a prompt that “do not perform dangerous operations” is not enough. Permission checks, execution isolation, sensitive-information filtering, and confirmation for high-risk operations should be enforced by programs outside the model.

    Likewise, unverified model output should not be written directly into critical business systems. For content involving amounts, permissions, production configuration, and similar areas, deterministic validation, approval, or human review should be used.

    Conclusion: Optimize More Than the Model

    The same model can perform differently across applications because it receives different information, can execute different operations, and is judged differently on success and failure.

    Understanding the relationships among the LLM, prompt, context, RAG, tool, agent, and harness ultimately serves three engineering questions:

    • Did the model see the evidence needed to complete the task?
    • Did the system provide safe, clear, and feedback-enabled action capabilities?
    • Was the result independently verified, rather than relying only on the model’s self-report?

    By embedding these questions into architecture, logs, and evaluation, teams can gradually turn occasional useful LLM calls into reproducible, controllable, and maintainable technical systems.