Agentic Coding Assistants: From Prompting to Context Engineering and System Design

    Reliable agentic coding requires more than well-written prompts. This article presents a six-layer architecture and a five-surface troubleshooting framework for managing context, tools, skills, hooks, subagents, and verification. It also explains how prompt caching affects system design and how concise project instructions, purposeful isolation, and rollback capabilities make coding workflows more dependable.

    Over the past six months, I have used LLM-based coding assistants extensively across two accounts. Along the way, I have encountered plenty of failures and developed a clearer understanding of what makes these tools useful. This article is not about a particular product. It addresses a broader question: how should you use agentic coding tools without losing control of the workflow?

    Initially, I treated them as advanced chatbots: paste in code, ask a question, and request a solution. The limitations soon became apparent. Longer conversations produced more confused context. Adding tools sometimes made results worse. Expanding rule files did not make their instructions more likely to be followed.

    After considerable experimentation and a closer look at how these systems work, I realized that the problem was not simply poor prompting. Their operating model requires them to be managed as systems, not used merely as chat interfaces.

    That means understanding the agent loop, governing context, designing skills and hooks, using subagents selectively, accounting for prompt caching, and writing project instructions that are actually useful.

    1. Start with a Six-Layer Architecture

    A practical way to understand an agentic coding system is to divide it into six layers:

    1. Project instructions, rules, and memory: Maintain long-lived context and explain what the project is and which conventions apply.
    2. Tools and external capabilities: Define the actions the agent can take.
    3. Skills: Provide task-specific methods loaded on demand.
    4. Hooks: Enforce behavior at defined points without relying on the model to decide whether to act.
    5. Subagents: Perform bounded, autonomous work in isolated contexts.
    6. Verification: Make outputs testable, reversible, and auditable.

    The value of this model is that it explains why strengthening one layer in isolation can make the overall system less effective.

    • Overlong project instructions clutter persistent context, dilute attention, and bury relevant constraints.
    • Too many tools expand the selection space before every action, increasing the likelihood of choosing an unsuitable tool or supplying incorrect arguments.
    • Excessive use of subagents allows their working states to diverge and makes it harder for the main session to maintain a coherent view.
    • Missing verification makes failures difficult to diagnose. Without knowing which stage failed, restarting can become the only apparent option.

    These layers form an engineering system. Overinvesting in one layer—or leaving another out entirely—can undermine the whole workflow.

    2. Understand the Agent Loop

    The core of an agentic coding assistant is not question answering. It is an iterative loop:

    Gather context → Take action → Verify results → Finish or gather more context

    Several supporting structures surround this loop:

    • Project instructions supply background.
    • Hooks, permissions, and sandboxes impose constraints.
    • Skills and tools provide methods and actions.
    • Memory supports continuity across sessions.

    Over time, I found that most obstacles were not caused by a lack of model intelligence. They came from two recurring system-level failures.

    Failure 1: Supplying the Wrong Context

    Sometimes essential information was missing: build commands, coding conventions, or directory organization. At other times, hundreds of lines of largely irrelevant rules buried the constraints that actually mattered.

    Both are context failures. More information is not necessarily better information.

    Failure 2: Producing Changes That Cannot Be Verified or Reversed

    The agent generates code, but there are no tests to establish whether it works. It damages a file, but no version snapshot exists to restore it.

    Under these conditions, even a capable model is making guesses without a reliable way to check them.

    3. Troubleshoot Across Five Surfaces

    When an agent behaves unexpectedly, rewriting the prompt should not be the automatic first response. Instead, inspect five surfaces.

    1. Context Surface

    Which information is always present, and which is loaded on demand? Is persistent context concise? Can task-specific information be found when needed?

    This surface includes project instructions, rules, memory, and skills.

    2. Action Surface

    What actions can the agent currently perform? Are built-in tools, external tool protocols, and plugins redundant or conflicting? Has the tool set grown beyond what the agent can reliably choose among?

    3. Control Surface

    Which actions must be restricted, blocked, or audited?

    Check whether permissions, sandboxing, and hooks cover high-risk operations such as deleting files, running arbitrary commands, and accessing external networks.

    4. Isolation Surface

    Which tasks require separate contexts and permissions?

    Subagents, separate working directories, and forked sessions should address an actual isolation requirement rather than serve as default workflow components.

    5. Verification Surface

    How do you establish that a task is complete and its output is trustworthy?

    Tests, static analysis, build artifacts, logs, and continuous integration should form a complete feedback loop.

    In my experience, most cases of an agent “not following instructions” can be traced to these surfaces: incorrect context, missing controls, or an incomplete verification loop.

    4. Practical Design Guidelines

    Keep Project Instructions Minimal

    A project instruction file should contain the smallest set of information needed in nearly every session:

    • A concise description of the project structure.
    • Build and test commands.
    • Non-negotiable project conventions.

    Move other material into skills that can be loaded when relevant.

    A useful rule of thumb is that an instruction unused in 80% of sessions probably does not belong in persistent context.

    The goal is not to document everything in one file. It is to make the information needed every time immediately available without burying it in occasional-use guidance.

    Load Methods Through Skills

    Procedural knowledge belongs in independently maintained skills. Examples include:

    • How to review code.
    • How to refactor a legacy module.
    • How to write migration scripts.

    Each skill should have a clear description of when it applies, so the model can load it for relevant tasks rather than carry it through every interaction.

    This preserves the context budget while making the methods themselves easier to maintain and reuse.

    Use Hooks for Rules That Cannot Depend on Model Discretion

    Hard safety and quality requirements should be enforced through hooks rather than left as reminders in a rule file. Examples include:

    • Running static checks before a commit.
    • Preventing modifications to protected directories.
    • Requiring human confirmation for dangerous commands.

    A model may or may not remember to follow a written instruction at the right moment. Hook execution provides a deterministic enforcement point within the configured workflow.

    The distinction matters: guidance tells the model what it should do; enforcement determines what the system permits or requires.

    Use Subagents When Context Needs Isolation

    Subagents are especially useful when a task should not fill the main session with intermediate material. Typical cases include:

    • Searching a large codebase: Return findings to the main session rather than the entire search history.
    • Exploring alternative implementations: Investigate multiple approaches separately.
    • Running output-heavy tasks: Keep extensive intermediate output, such as a full test run, out of the main context.

    Be cautious about treating subagents as the default way to introduce concurrency. Their working states are not automatically shared, and coordination overhead can grow rapidly as their number increases.

    The important question is not “Can this task run in another agent?” but “Does this task benefit from isolated context?”

    Account for Prompt Caching in the Architecture

    Prompt caching can have a substantial effect on both cost and latency.

    Requests in these systems often include a large repeated prefix containing system instructions, tool definitions, and project instructions. When that prefix remains stable, it can benefit from caching, reducing cost and time to first token.

    The architectural implications are straightforward:

    • Place stable content near the beginning of the context and avoid changing it unnecessarily.
    • Keep frequently changing conversation state toward the end.
    • Avoid inserting values that change on every request, such as timestamps, into system instructions.
    • In long sessions, favor reusing existing context over repeatedly rebuilding it.

    Caching is therefore not just a billing detail. It is another reason to distinguish stable instructions from changing task state.

    Make Verification and Rollback Mandatory Parts of the Workflow

    A mature agentic workflow needs automated ways to evaluate its output. Depending on the task, these may include:

    • Unit tests.
    • Type checking.
    • Successful builds.
    • Continuous integration checks.

    It also needs a recovery path. Work under version control, and commit or create a snapshot before substantial changes.

    Without verification, the agent can modify the codebase without a reliable way to establish correctness. Without rollback, even a detected mistake may be expensive to undo.

    Verification and reversibility belong in the workflow itself, not as optional cleanup after the agent has finished.

    5. From Prompting to System Engineering

    Agentic coding assistants have substantial potential, but realizing it requires treating them as systems that need deliberate architecture—not as chat windows controlled by increasingly elaborate prompts.

    The principles are consistent:

    • Govern context.
    • Keep the capability set focused.
    • Enforce critical constraints deterministically.
    • Use isolation for a clear purpose.
    • Close the loop with verification and rollback.

    The six-layer architecture explains where responsibilities belong. The five-surface framework helps locate failures when the workflow breaks down.

    Once you examine agentic coding through these lenses, many seemingly unpredictable problems become identifiable engineering issues. Prompt writing remains a useful foundation, but context engineering and system design are what make these tools dependable in practice.