The Title

    The Summary

    The Content

    1. The Starting Point: A Strong Model Does Not Guarantee a Strong System

    The same foundation model can show a dramatic jump in success rate on long-horizon tasks, multi-file changes, and complex debugging once it is wrapped in a well-designed agent shell — while plugging that same model into a bare, generic interface call produces markedly worse results. That gap exposes a frequently overlooked fact: agent capability = model capability × engineering coefficient, where the coefficient is determined jointly by how context is supplied, how instructions are organized, and what runtime constraints the model operates under.

    So the right way to judge an agent is not “which model did you wire in,” but three questions: how does it talk to the model, what does it let the model see, and what kind of runtime does it give the model. Those three questions map to three layers of engineering.

    2. Defining the Three Layers and How They Stack

    Layer Core question Main techniques Typical gain
    Prompt engineering How to say it Role, task contract, output format, examples About 70/100 on its own
    Context engineering What to let the model see Retrieval, pre-injection, compression, isolation Pushes it to 80–85
    Harness engineering What environment it runs in Tools, loop, verification, permissions, observability Pushes it to 90–95

    These numbers are not precise metrics, but they reflect an engineering reality: context sets the ceiling, prompts set the wake-up rate, and the runtime sets reliability. The three layers are not interchangeable — more wording cannot fix missing information, and more retrieval cannot fix a model that does not know how to check its own work.

    3. Prompt Engineering: Static Contracts and Dynamic Assembly

    3.1 Organize in layers rather than piling up text

    A stable prompt is usually built from four layers: identity (“you are an engineering assistant working inside a local terminal”), contract (task boundaries, forbidden actions, when to ask), standards (code style, dependency choices, change granularity), and tooling (the semantics of each tool and when to call it). Layering means a local change does not disturb the whole, and it makes it easy to inject different combinations per task.

    3.2 Dynamic assembly: the environment is part of the prompt

    Production-grade implementations tend to splice variable information into the prompt at the start of every session: the current working directory, time and timezone, operating system and shell, version-control branch and status, platform-specific notes, and user rule files. The value of this information is not “politeness” — it is eliminating the model’s guesswork, so it does not have to fill gaps with prior assumptions.

    1. <system>
    2. Identity + contract + standards (static, cacheable)
    3. </system>
    4. <environment>
    5. Working directory / branch / platform / time (dynamic per session)
    6. </environment>
    7. <rules>
    8. User project rules (change with the repository)
    9. </rules>

    3.3 Anti-patterns in wording

    Only a stable static section yields cache hit benefits; repeatedly stuffing dynamic content into static blocks breaks the cache and dilutes attention. Also avoid replacing a positive contract with a list of negations — instead of enumerating ten “do not” rules, give two “do it this way” rules plus one hard boundary.

    4. Context Engineering: Treat the Window as a Budget, Not a Warehouse

    4.1 Trade-offs among three supply strategies

    Pre-injection suits short, certainly relevant information; retrieval suits large corpora with variable relevance; on-demand expansion (tool reads, chunked viewing) suits high-volume information that needs to be confirmed step by step. Mature agents rarely rely on a single strategy; they use “a little pre-injection + precise retrieval + a lot of on-demand reading.”

    4.2 Compression and summarization

    Long-horizon tasks inevitably hit window pressure. Common practices are rolling summaries (keep decisions, constraints, unfinished tasks, and rejected options; drop process detail), externalizing structure (write long content into intermediate files and keep only paths and key points in context), and importance-ranked eviction. The key point: a summary should preserve “why,” not “what was done” — otherwise the model loses the reasoning basis behind its earlier choices.

    4.3 Context rot and instruction drift

    As turns accumulate, early instructions lose weight, contradictory information builds up, and the model redoes work that is already finished. These are observable forms of degradation. Mitigations include periodically restating the goal, explicitly maintaining a task-list state, and clearing history unrelated to the current subtask at phase transitions.

    4.4 Subtask isolation

    Handing exploratory work (heavy searching, trial and error, log digging) to a separate sub-session and returning only conclusions to the main context is a strategy that trades parallelism for cleanliness. It reduces both the context footprint of a single run and attention pollution on the main thread.

    5. Harness Engineering: From “It Runs” to “It Runs Reliably”

    5.1 Tools are interface design

    A tool’s atomicity, naming semantics, and return structure directly determine how accurately the model uses it. Rules of thumb: error messages must be diagnosable (state the failure reason and the suggested next step); output must be truncatable and come with a way to continue reading; destructive operations must be previewable and confirmable; and the same intent should not be served by several near-synonymous tools.

    5.2 Execution loop and objective verification

    The core of a reliable agent is not one-shot generation but a closed loop of “plan — execute — verify — correct.” What matters is that the verification signal be objective and automatically obtainable: compilation, static analysis, unit tests, type checks, formatting diffs. Such external signals give the model a feedback channel that needs no human in the loop, and that is the root cause of why long-horizon tasks can self-correct.

    1. loop:
    2. observe(context + recent tool results)
    3. plan(todo list, mark the current step)
    4. act(call tools, advance step by step)
    5. verify(compile / test / diff check)
    6. if failed: attribute cause -> back to act, and write it into the summary
    7. else: submit conclusion + change description

    5.3 Permissions, sandboxes, and approvals

    A tiered permission policy (read-only allowed, writes restricted to specific directories, dangerous operations require confirmation) both reduces mistakes and reduces the workarounds a model invents to get around restrictions. Isolation of the execution environment itself (temporary directories, containerized build environments) is the foundation of reproducibility.

    5.4 Observability

    Log every turn’s prompt version, tool calls and arguments, return length, latency, and failure reason, and keep trajectories as replayable assets. If generic cloud capabilities such as a logging service, monitoring and alerting, and object storage are already in place, they can be used for trajectory archiving and failure-rate dashboards; this turns “did the prompt change help?” from a subjective impression into a measurable conclusion.

    6. Failure-Mode Diagnosis: Localize First, Then Optimize

    • Goal drift, expanding scope on its own → a contract and boundary problem; go back to the prompt layer.
    • Repeatedly missing key information, ignoring known constraints → a supply and positioning problem; go back to the context layer.
    • Correct instructions but wrong execution, no self-checking → a tooling and verification-loop problem; go back to the harness layer.
    • Quality dropping late in a long session → a compression and isolation strategy problem.

    The recommended engineering order is to first complete the objective verification in the harness layer (lowest cost, most certain return), then optimize context supply, and only then polish prompt wording. Reversing the order traps you in a loop of endless rewording with limited gains.

    7. Shipping Checklist and Evaluation Method

    1. Maintain a real evaluation set of 10–50 cases for every high-frequency task, with both positive and negative examples.
    2. Evaluate on three levels: result accuracy, trajectory soundness (did it take unnecessary detours), and cost (turns and context consumption).
    3. After every prompt or tool change, run the same evaluation set for a regression comparison, to avoid “local improvement, overall regression.”
    4. Externalize user project rules and code standards as version-controlled configuration that evolves with the repository.
    5. Force preview and confirmation for irreversible operations, and keep a rollback point.

    8. Conclusion

    The gap between “can finish” and “finishes reliably” almost always lies in the engineering layer, not the model layer. Prompt engineering makes the intent clear, context engineering puts the right information in the right place, and harness engineering puts execution inside a verifiable, rollback-able, observable loop. Only when the three are stacked together do you get a methodology that moves an agent’s score from the passing line into the high range on complex, long-horizon tasks.