
Structure context and intent for your coding agents
Context files often add cost without raising success. See how to separate intent from context and load only what each task needs, with Kiro on AWS.
Series: A study on AI in the product lifecycle (8 articles)
- …
- 4Structure context and intent for your coding agents This article
Global Sr. Solutions Architect, Private Equity
Does giving your coding agents more context make them better? In a 2026 study from ETH Zurich and LogicStar across several coding agents and models, context files didn't generally raise task success and added more than 20% to inference cost. A smaller study of 124 pull requests found that having an
AGENTS.md , a Markdown file of project instructions that coding agents read before they start, was associated with about 29% lower median runtime. Neither study settles how much to write.My view is that an agent needs two things it can't find on its own, the intent behind the work and the relationships across the code, and the rest should load only when a task needs it. In a test I ran, replacing a long context file with a short map cut the median task's cost by 38% with no loss in first-pass success. In this article, I separate intent from context, show how to lay out a repository so each task loads only what it needs, and cover where a code graph helps and how to measure the result.
Context and intent are different jobs
Context is what an agent could find by reading the repository, such as the stack and the build commands. Intent is why the work exists and what counts as done, including acceptance criteria and the reasons behind design decisions. The ETH Zurich authors found that agents followed the instructions in context files but gained nothing from repository overviews. Kiro splits the two in its steering files, with
product.md for purpose and goals and separate files for the stack and structure. Write down only what the agent can't infer, and put intent in specs and decision records, where each task can load it.Five layers, loaded when a task needs them
Each layer loads at a different time (Figure 1). Standing rules such as
AGENTS.md and steering files load on every turn, and an always-loaded token is paid for again on every later turn of the session. Prompt caching, which reuses input a provider has already processed, lowers that price but doesn't remove it. Keep standing rules to the non-standard practices and constraints a reviewer would otherwise catch.
Figure 1. Five layers of context and intent, sorted by when each one loads
Live AWS context comes through Model Context Protocol (MCP) servers such as the AWS Knowledge MCP Server , and any server that reads your account should get least-privilege credentials. Review the rules agents learn in pull requests, and delete the ones that no longer apply.
How should you lay out the repository?
Lay it out for progressive disclosure, which part 1 recommended for team knowledge. Keep the root
AGENTS.md to non-standard rules plus links to a docs folder that holds decision records and the design. In Kiro, AGENTS.md files load on every turn, including ones in subdirectories, so nesting them doesn't reduce what loads. Steering files choose when they load, by file pattern, by name, or when a request matches their description (Figure 2). Move each area's rules into a steering file with a file pattern, so they load only when the agent works on matching files.
Figure 2. A repository laid out for progressive disclosure, with the Kiro steering mode that decides when each file loads
Where does a code graph help, and where does search still win?
A code graph maps the calls and imports between the functions and files in a codebase, so it can answer who calls a function or what a change touches. The one controlled comparison I found, a paper by the author of codebase-memory-mcp , shows the trade-off (Figure 3). Across 31 repositories, the graph used about a tenth of the tokens of an agent that reads files, but scored 83% on overall answer quality against that agent's 92%.

Figure 3. A code graph cut tokens about tenfold but scored lower overall, in a paper by the tool's own author
Use a graph for impact and dependency questions, a language server for precise symbols such as go-to-definition, and search for exact lookups. The Kiro command line interface (CLI) provides language server symbols through its code intelligence , and a graph can join through an MCP server.
Linking code back to intent
Graphify , an open-source code graph, turns WHY comments, which record the reason behind a choice, and decision record citations into nodes linked to the code they explain, and its git hook rebuilds the graph on every commit. The AI-Driven Development Lifecycle writes the intent side, as it asks for missing decisions before work moves on and keeps learned rules and an audit trail in the repository. Write the reason next to the code, so the graph can link to it.
Keep context clean and safe
The security article in this series puts steering files, hooks, and rule files under code owner review, and context carries three more risks.
- Researchers have shown that injected rules can steer agents to attacker-controlled packages, so check lockfiles, which pin each dependency's version, and dependency allowlists in a hook.
- A nested
AGENTS.mdadded in a pull request becomes live context, so the code owner rule needs a pattern such as**/AGENTS.md.
- Context reaches the model as plain text, so reference secrets by name in AWS Secrets Manager and scan steering, spec, and memory files for secrets.
How do you know it's helping?
I tested this on a fictional retailer's review pipeline of about 3,500 lines of Python, with 10 tasks run twice each in the Kiro CLI on Claude Opus 4.8. The repository's
AGENTS.md and memory files loaded about 11,800 tokens on every turn, and I replaced them with a 246-word map of the project and the rules a reviewer would flag. With the map, the median task used 38% fewer Kiro credits, and 14 of 20 runs passed every check on the first pass, against 11 of 20 with the long file. The long file also changed what the agent thought the task was, and in one run a request to support Spanish led it to rewrite docs and fixtures the change didn't need.That's one repository, one model, and tasks I wrote. The map also stated rules the long file left out, so the result supports a short map that states those rules, and it doesn't show that length alone drives the cost. A July 2026 study of Claude Code and Codex on 17 tasks also found that context strategy didn't measurably change correctness. Consider running the same test on 20 of your own recent tasks before and after you trim the standing rules, and again after each model change.
Where does your team keep intent for its coding agents today, in specs, in steering files, in pull request descriptions, or not yet?
Further reading
- Part 1: Measure AI developer productivity from idea to production (AWS Builder Center)
- Secure AI-generated code across the SDLC on AWS (AWS Builder Center)
- Which SDLC checks the AI-Driven Development Lifecycle moves (AWS Builder Center)
- Build a knowledge graph before you fine-tune the model (AWS Builder Center)
- Agent steering (Kiro documentation)
About the author
Michael Purpura is a Senior Global Private Equity Solutions Architect at AWS. He works with private equity firms and their portfolio companies to structure AI adoption around measurable business outcomes.
Series: A study on AI in the product lifecycle (8 articles)
- …
- 4Structure context and intent for your coding agents This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article