Why the Same LLM Performs Differently Across Frameworks: A Complete Guide to the Harness

    This article explains why an identical large language model can appear "smarter" or "dumber" when moved between products and runtime environments. The cause is usually not model degradation but the orchestration layer around the model, known as the Harness. You will learn how Prompt, Context, RAG, Tool, and Agent fit together as composable parts, the key variables that change real-world output, a pseudocode walkthrough of how an Agent Harness runs, engineering practices for building a reproducible and testable system, and a practical checklist for diagnosing inconsistent behavior.

    Many developers have run into the same pattern: an LLM exposed through an API performs reliably inside one chat product, seems to “get dumber” when moved to another tool, and then suddenly “gets smart” again in a different runtime. If you only look at the model name and the endpoint URL, it is easy to blame “model degradation” or “hidden API limits.” A more common explanation is that the model did not change; the runtime and orchestration layer around it did.

    That layer can be called the Harness (also translated as the runtime framework, the driving layer, or the execution shell). It does not train the model. Instead, it places the model inside a usable system: how input is organized, how context is managed, whether a knowledge base is connected, whether tools can be called, whether calls are retried after failure, whether output is validated, how state is persisted, and how results are evaluated. The conclusions up front:

    • The model sets the ceiling of capability; the Harness decides how much of that capability is actually delivered on real tasks.
    • An Agent is not a “stronger model.” It is an automated execution system formed by the model together with the orchestration layer.
    • Prompt, Context, RAG, and Tool are not isolated magic. They are parts the Harness can schedule and combine.

    1. The Symptom: Why One Model Feels Like a Different “Brain”

    First, clear up a common misconception: the “same model” may not actually be identical. Different providers may use different model versions, quantization, sampling parameters, context length limits, safety policies, or routing strategies. A chat product may also embed system prompts, formatting rules, history summaries, and tool chains that users never see. Even if you assume the model snapshot, parameters, and API are exactly the same, the experience can still differ dramatically. The cause usually comes from four kinds of differences.

    The first is input differences. For the same question, a chat product may automatically add a system role, answer style, formatting requirements, relevant conversation history, and even retrieved material; another tool may send only the user’s current sentence. Different context produces different output.

    The second is action-space differences. Some Harnesses only allow the model to output text; others let it query databases, search documents, run calculations, read files, and call business APIs. Whether tools can be called affects complex tasks far more than tweaking a single prompt.

    The third is feedback-loop differences. A mature Harness parses, validates, repairs, and retries the model’s output: it asks for a rewrite when the format is wrong, fills in missing tool arguments, and rewrites the query when retrieval results are irrelevant. A crude integration often calls the model once and hands the raw output straight to the user.

    The fourth is product-experience differences. Streaming output, progress indicators, citations, error messages, and layout all shape a user’s judgment of “how smart” the system is. Some tools do not make the model stronger at all; they simply make results look more reliable through better decomposition, presentation, and validation.

    So when investigating “different results from the same model,” you cannot compare only the model name. You have to compare the entire execution site.

    2. LLM and API: The Engine and the Interface Are Not the Whole Car

    The LLM (Large Language Model) is the core source of capability in the system. Its basic mode of operation is to predict the next token from existing text and generate results token by token. It can summarize, rewrite, reason, generate code, classify, and extract, but it is not a complete application by itself.

    When understanding an LLM, keep its capability boundaries in mind:

    Capability boundary How it shows up Common ways to compensate
    Stateless Each call does not remember the previous turn unless history is passed in again Context, Memory, conversation summaries
    Knowledge cutoff New knowledge beyond training data and internal enterprise documents is not natively known RAG, search, business APIs
    Text-only output Cannot directly read or write external systems or perform actions natively Tool, Agent, workflows
    Probabilistic output The same input can produce different phrasing; format and facts can be unstable Parameter control, structured output, validation and retry

    The essence of an LLM API is also simple: it wraps a single text input into a network request and returns generated text or a structured result. At the API level, it typically handles only common concerns such as authentication, transport, rate limiting, and billing. It does not natively include complete Agent logic, nor does it automatically handle context management, tool orchestration, and evaluation for you. The API is the “engine interface,” not the “whole car.”

    3. Connecting the Concepts: A Layered Model from Prompt to Harness

    1. Prompt: Turning Intent into an Executable Instruction

    A Prompt is the input instruction sent to the model, including system-level constraints, the task description, examples, output format, tool descriptions, and boundary conditions. Its value is reducing ambiguity so the model knows “what to do, by what standard, and in what form to output.” But a Prompt is not a knowledge base or an executor. It cannot guarantee the model knows facts you did not provide, nor that it will always follow the format. In engineering, treat the Prompt as a versionable, testable code asset, not a one-off handwritten string.

    2. Context: Everything the Model Actually “Sees” This Time

    Context is larger than the Prompt. In a single model call, all tokens the model can see belong to the Context, including the system prompt, the user question, conversation history, memory summaries, RAG-retrieved fragments, tool return values, and output constraints. The core of context engineering is not “stuff in as much as possible” but “put the most relevant, most reliable, highest-priority information within a limited budget.” Too much context brings noise, higher cost, and truncation risk; missing context causes the model to overlook key premises. Real systems need budget allocation, deduplication, ordering, compression, and source labeling.

    3. RAG: Connecting the Model to Updatable External Knowledge

    RAG (Retrieval-Augmented Generation) addresses the model’s limited knowledge and lagging updates. A typical flow includes document chunking, index building, query rewriting, recall, reranking, context injection, and citation generation. The hard part of RAG is not “pasting documents into the Prompt” but retrieval quality. Inappropriate chunk granularity, semantic mismatch between query and documents, too much noise in recall, stale indexes, and missing reranking all give the model context that looks relevant but is actually useless. RAG must be evaluated separately for recall and answer faithfulness; you cannot judge only whether the final answer “looks decent.”

    4. Tool: Moving the Model from “Can Talk” to “Can Act”

    A Tool is an external capability the model can call, such as querying a database, reading a business system, running a calculation, creating a ticket, or sending a notification. Integrating a tool is not just handing the model a function name; it requires a clear parameter schema, permission boundaries, timeout policy, error codes, idempotency rules, and result compression. The stronger the tool, the greater the risk. For high-risk actions such as writes, financial operations, and permission changes, add least-privilege control, secondary confirmation, and audit logs.

    5. Agent: An Automated Executor with Goals, Loops, and Tools

    An Agent can be understood as a system that loops through “observe, decide, call tool, read result, continue or stop” under a goal. Its capability depends not only on the underlying model but also on how the Harness decomposes tasks, selects tools, limits steps, validates intermediate results, and handles failures. An Agent with no stopping condition, no budget control, and no validator easily falls into loops, hallucinated calls, and error accumulation.

    6. Harness: The Master Control Layer That Assembles Parts into a Runnable System

    The Harness is the runtime and orchestration layer outside the model. It typically includes session management, a model gateway, Prompt management, Context assembly, RAG retrieval, tool registration and execution, output parsing, validation and retry, safety policies, memory management, observability, and an evaluation system. It decides what the model sees, what it can do, how it recovers from mistakes, and how results are finally presented to the user. The relationship can be summarized as:

    Effective output ≈ f(model capability, input information, tool capability, orchestration strategy, validation feedback, evaluation iteration)

    The ceiling of this function is set by model capability, but the real output is decided by the Harness.

    4. Key Variables Behind Different Results from the Same Model

    Key variable Typical mechanism Common symptom How to investigate
    Hidden system prompt Different products embed different roles, styles, and safety rules Different tone, format, and refusal boundaries Print the actual full Prompt
    Context assembly Different selection and ordering of history, memory, and retrieved fragments Missing premises, citing the wrong material, off-topic answers Log the token budget and truncation points
    Memory strategy Different session memory, long-term memory, and summary compression Inconsistency, forgetting key constraints Replay session state and compare summaries
    RAG quality Different chunking, recall, reranking, and injection Answers lack grounding or cite irrelevant content Test recall and reranking separately
    Tool configuration Different tool count, schema, permissions, and timeouts Fails to call, wrong arguments, tool failures Log the tool-call trace
    Agent loop Different planning, step limits, stopping conditions, and validators Repeated attempts, premature ending, error accumulation Limit the budget and replay step by step
    Output parsing Different regex parsing, structured validation, and repair/retry Unstable format, missing fields Validate output against a schema
    Model parameters and routing Different sampling parameters, max output, model snapshot, and routing Changes in randomness, length, and style Fix the version and parameters for comparison
    Safety and guardrails Different content filtering, permission checks, and sensitive-data masking Some questions are blocked or rewritten Check policy-hit logs
    Observability and evaluation Presence or absence of a regression set, traces, metrics, and A/B testing Hard to reproduce issues, easy to regress changes Build a replayable evaluation system

    These variables often stack. Users see the final answer, but engineering must localize the issue to a specific stage: was the Prompt unclear, was the Context incomplete, did RAG fail to retrieve, did the Tool lack permission, or did the Agent fail to stop?

    5. How a Harness Works: A Pseudocode Walkthrough

    A typical Agent Harness can be abstracted into the following flow:

    1. User input
    2. -> Load session and relevant memory
    3. -> Assemble system policy, task description, history, retrieved results, tool list
    4. -> Call the LLM
    5. -> Parse output
    6. -> If final answer: validate format and factual constraints, return if it passes
    7. -> If tool call: check permissions and arguments, execute the tool, compress the result
    8. -> If parsing or validation fails: append feedback, enter repair or retry
    9. -> If the stopping condition is reached without completion: degrade, escalate to a human, or return an explainable error

    The corresponding pseudocode:

    1. function run_agent(task, user_input, session):
    2. memory = load_relevant_memory(session, user_input)
    3. context = build_context(
    4. system_policy,
    5. task,
    6. user_input,
    7. memory,
    8. available_tools = list_tools(task),
    9. output_constraints = task.constraints
    10. )
    11. for step in range(MAX_STEPS):
    12. context = enforce_token_budget(context)
    13. raw_output = call_llm(
    14. messages = context,
    15. params = model_params,
    16. timeout = step_timeout
    17. )
    18. action = parse(raw_output, tool_schema)
    19. if action.type == "final":
    20. if validate(action.content, task.constraints):
    21. return action.content
    22. context.append(feedback = "Output failed validation; fix missing fields and format")
    23. continue
    24. if action.type == "tool":
    25. if not allowed(action.name, session):
    26. context.append(observation = "Insufficient permission; use an allowed tool")
    27. continue
    28. result = execute_tool(
    29. action.name,
    30. action.args,
    31. permission_scope = session.scope,
    32. timeout = tool_timeout
    33. )
    34. context.append(observation = compress(result))
    35. else:
    36. context.append(observation = "Action could not be parsed; output again")
    37. return fallback_answer_or_escalate()

    This pseudocode reveals several key points: the model is only the decision component inside the loop. What really determines system stability is the context budget, tool permissions, output parsing, validation and retry, stopping conditions, and fallback strategy.

    6. Engineering Practice: Building a Reproducible, Testable Harness

    First, unify the model gateway. Consolidate model calls into a single entry point and centrally manage model versions, parameter presets, timeouts, retries, rate limiting, billing, and auditing. Do not scatter different sampling parameters across business code, or problems become very hard to reproduce.

    Second, version the Prompt and Context. Prompt templates, context assembly strategies, retrieval configuration, and output schemas should all carry version numbers. Production logs should record the version actually used, token usage, truncation points, and retrieved-result identifiers, so runs can be replayed.

    Third, manage the context budget well. Layer by priority: safety and system constraints first, the current user request next, high-confidence retrieved fragments after that, and recent conversation and summaries after that. Deduplicate and compress low-relevance fragments, and summarize or structurally trim tool return values.

    Fourth, evaluate RAG in stages. Evaluate query rewriting, recall, reranking, injection, and final answer faithfulness separately. Document chunking should preserve semantic boundaries and metadata; retrieval can combine keyword and vector recall, then use reranking to improve relevance.

    Fifth, engineer the tools. Tool descriptions should be clear, parameter schemas strictly validated, read/write permissions minimized, and write operations should support idempotency and human confirmation. When a tool fails, return an understandable error rather than pushing the raw exception back into the context.

    Sixth, give the Agent stopping conditions. Set a maximum number of steps, a maximum token budget, a deadline, repeated-call detection, and validators. For tasks that need multiple steps, validate the plan, intermediate results, and final answer separately to avoid errors amplifying inside the loop.

    Seventh, put security and permissions first. Treat both retrieved documents and tool return content as untrusted input, and guard against prompt injection. Mask sensitive data, isolate cross-tenant access, and audit high-risk actions with support for human intervention.

    Eighth, build an observability and evaluation loop. Record a complete trace: user input, the actual Prompt, a Context summary, retrieved-fragment IDs, tool calls, model output, validation results, latency, and errors. Evaluation metrics should cover task success rate, factual faithfulness, citation accuracy, tool success rate, format pass rate, latency, cost, and human-intervention rate. Validate against a fixed regression set before release, and observe with A/B testing and canary rollouts after release.

    Ninth, control cost and latency. You can cache retrieval results, run independent tools in parallel, compress history, route different models by task complexity, and stream responses. But optimization must not sacrifice testability; any strategy change should enter regression testing.

    7. A Checklist for Diagnosing “Dumber / Smarter” Behavior

    1. Fix the model identifier, version, sampling parameters, and maximum output length so comparison conditions are consistent.
    2. Print the full Prompt and Context actually sent, and check for hidden constraints, truncation, or ordering problems.
    3. Test RAG recall in isolation: is the correct material retrieved, is the ordering reasonable, and does it get drowned out by noise after injection?
    4. Test tools in isolation: is the schema clear, can arguments be generated, and do permissions, timeouts, and error handling work?
    5. Replay the full trace and compare the two Harnesses item by item across system prompts, history summaries, retrieved results, tool lists, and validators.
    6. Run A/B tests changing only one variable at a time; do not adjust the Prompt, retrieval, and tool configuration simultaneously.
    7. Build a golden set covering real scenarios, including normal questions, boundary conditions, tool failures, long context, and format constraints.
    8. Classify failure samples: missing input, retrieval error, tool error, parse failure, missing validation, policy block, or insufficient model capability.

    8. Conclusion

    Different performance from the same model across different Harnesses is not magic. The LLM is the capability engine, the API is the interface, the Prompt is the task description, Context is the information the model can see this time, RAG is the external knowledge channel, Tool is the action capability, Agent is the goal-driven execution loop, and the Harness is the master control layer that organizes these parts into a stable system.

    The truly mature approach is not to keep swapping model names, but to treat the Harness as a first-class engineering object: observable, testable, rollback-able, and iterable. In actual deployment, whether you build your own service or use cloud infrastructure such as the general compute, storage, logging, and monitoring offered by Baidu AI Cloud, these are only the carrying layer. What determines whether model capability is delivered reliably is still the Harness’s systematic design of context, tools, feedback, and evaluation.