Skip to content

Designing Context Packages for Coding Agents

Interactive Diagram

새 탭 ↗

“Ask clearly,” “assign a role,” “request things step by step”: most advice on working with coding agents focuses on polishing the prompt sentence. That advice isn’t wrong, but it doesn’t solve the actual problem this series has been building toward: how do you hand a coding agent the artifacts already produced (architecture decision, user story, acceptance criteria) without losing information along the way?

Look again at the artifacts produced so far in this series.

- Architecture Decision: a design decision like "double-guarded by a DB unique constraint"
- User Story: "As a registrant, I want to know immediately whether a team name is
already taken when I type it"
- Acceptance Criteria: verification conditions in Given-When-Then form

Hand these three over as a natural-language paragraph and a coding agent will drop or reinterpret some of it. Unstructured text gives the agent no way to tell what’s a hard constraint versus what’s merely background information.

This article proposes building a structured input (a Context Package) instead of a natural-language prompt. A Context Package has four fields.

task:
# exactly what this piece of work does (keep the scope narrow)
title: "Implement the team name duplicate check API"
scope: "Implement only the POST /api/registrations/check-team-name endpoint"
out_of_scope: "Registration form submission and file upload are not part of this task"
context:
# background the agent should reference (quote prior artifacts verbatim)
architecture_decision: |
- Team name duplicate check is double-guarded by a frontend real-time check
plus a DB unique constraint
- File storage is kept separate with direct URL access blocked (unrelated to
this task)
related_story: |
Story: Team name duplicate check
"As a registrant, I want to know immediately whether a team name is already
taken when I type it, so that I don't get rejected at submission time and
can complete my registration."
constraints:
# non-negotiable rules
- "Follow the existing code style (the project's ESLint config)"
- "DB access must go through the repository layer (no direct queries in the controller)"
- "This endpoint must be reachable without authentication (it runs before registration)"
acceptance:
# bring acceptance criteria over verbatim, don't re-summarize them
- "Given a team name input, When the name already exists, Then return a 409 response with an error message"
- "Given a team name input, When the name does not exist, Then return a 200 response"
- "When two requests submit the same team name concurrently, only one may
ultimately succeed due to the DB unique constraint"

The reason this structure beats a natural-language prompt is simple. task makes the boundary of what the agent may touch explicit; context gives the reasoning behind the design; constraints highlights the non-negotiable rules; acceptance gives the agent a standard to verify its own output against. The fact that these four fields stay separate, instead of blending together, is the whole point.

Older prompt engineering advice frequently recommends asking a model to “think step by step” (chain-of-thought). That pattern isn’t applied as-is to coding agents in this series.

The reason is straightforward. Chain-of-thought output shows how the agent thought, but what a human actually needs to verify is what changed and whether it satisfies the acceptance criteria. A narrated thought process is not a verifiable deliverable.

Instead, this series fixes the coding agent’s output structure itself as follows.

## Output structure (coding agent response contract)
1. Decision summary
- The key design/implementation decisions made in this task and why (1-3 sentences)
2. Changed file list
- File path and change type (added/modified/deleted)
3. Verification command
- An actually runnable command to verify this change
(e.g. npm test -- --grep "team-name", a curl command, etc.)
4. Execution result
- The actual result of running the verification command (pass/fail, relevant logs)
5. Unresolved items
- Anything the agent is unsure about or that needs human confirmation

This structure connects directly to the Human Gate principle covered in Agile Delivery and AI Role Boundaries. A response with an empty “unresolved items” section should actually raise suspicion: it likely means the agent overlooked something it wasn’t sure about, rather than confirming there was nothing left to resolve.

Comparing actual outcomes with a Context Package example

Section titled “Comparing actual outcomes with a Context Package example”

The difference becomes visible when you compare requesting the same task as a natural-language prompt versus as a Context Package.

Natural-language prompt (not recommended):

Build an API that checks for duplicate team names. It should error if the
name already exists, and it needs to handle multiple people registering at
the same time without issues.

This prompt forces the agent to guess where the endpoint should live, whether authentication is required, and what layering it should follow. If the guess diverges from the architecture decision made earlier in this series, the code may work but risks getting merged in a state that contradicts the team’s design principles.

Context Package (recommended): the YAML above, verbatim. The agent stays inside scope, doesn’t violate the constraints, and reports a self-verified result measured against the acceptance criteria.

Not every task needs a Context Package. Typo fixes or simple refactors that have no relation to any architecture decision or acceptance criteria don’t need to be wrapped in this structure. Reserve the Context Package for work that spans multiple screens or layers, must follow the team’s design principles, or produces a result a human will need to verify later.

Once implementation is done via a Context Package, the next step is proving through testing that the implementation actually satisfies the acceptance criteria. The next article covers a two-pass test design: document-first test scenarios written before code exists, and code-grounded refinement once it does.

→ From User Stories to Test Scenarios and Test Code

PlantUML Diagram