Introduction
AI coding agents are changing how developers approach software development. Instead of generating a function from a single prompt, an agent can inspect a repository, reason about the existing code, call tools, modify files, run tests, and iterate on the result.
That additional capability also introduces a new class of engineering problems.
An agent can spend substantial compute repeatedly processing context. It can invalidate useful cached context when the conversation or working state changes. It can also make tool calls that fail and then retry, increasing latency and compute consumption.
These problems are especially important in large repositories and long-running agent sessions.
The key lesson is simple: improving an AI coding agent is not only about selecting a better model. Context management, cache reuse, tool reliability, and retry behavior can have a major effect on the overall workload.
This article looks at practical techniques for improving those areas when building or evaluating coding-agent workflows.
How an AI Coding Agent Differs From a Chat Assistant
A conventional coding assistant usually follows a relatively simple interaction:
Developer
|
v
Prompt
|
v
LLM
|
v
Code suggestion
An agentic coding workflow is more iterative:
Developer
|
v
Agent
|
+--> Inspect repository
|
+--> Read files
|
+--> Call tools
|
+--> Modify code
|
+--> Run tests
|
+--> Inspect results
|
+--> Call more tools
|
v
Completed change
Every additional step can introduce more context, more model calls, and more opportunities for tool failure.
For this reason, measuring only response latency or code-generation quality gives an incomplete picture.
The Three Workload Problems to Watch
A coding agent typically has three related efficiency problems.
Context Growth
As an agent reads files, command output, test failures, and tool responses, the amount of context available to the model can grow significantly.
A simplified session might look like this:
Request
|
+-- Repository instructions
|
+-- Project files
|
+-- Tool output
|
+-- Compiler errors
|
+-- Test results
|
+-- Previous reasoning context
|
v
Large working context
More context is not automatically better. Irrelevant or duplicated information can increase processing requirements without improving the next decision.
Cache Invalidation
Modern inference systems can reuse portions of previously processed context.
Conceptually:
Request 1
|
v
[Context A][Context B][Context C]
|
v
Cached
Request 2
|
v
[Context A][Context B][Context D]
If a change causes previously reusable context to become invalid, the system may need to process more data again.
That creates a cache cold-start effect.
The practical objective is therefore not simply:
Minimize context
but:
Keep useful context stable
+
Remove unnecessary context
+
Avoid needless invalidation
Tool Failures and Retries
Agents depend heavily on tools.
Examples include:
File search
File editing
Shell commands
Build commands
Test execution
Version-control operations
External APIs
Repository metadata
A failed tool call may cause the agent to retry.
For example:
Agent
|
+--> Run test
|
X
Failure
|
v
Retry
|
X
Failure
|
v
Diagnose
|
v
Retry again
The original task has now generated several additional operations.
This is why tool reliability is an important part of agent performance.
Designing Stable Agent Context
One of the best ways to improve an agent workflow is to separate stable context from frequently changing context.
Stable context can include:
Repository instructions
Coding conventions
Architecture rules
Build commands
Testing conventions
Directory structure
Dynamic context can include:
Current compiler errors
Recent test output
Modified files
Tool responses
Temporary investigation results
Keeping these concepts separate makes it easier to control what should remain available throughout a session.
Keep Repository Instructions Focused
A repository instruction file should explain information the agent genuinely needs.
For example:
Build:
dotnet build
Test:
dotnet test
Architecture:
API -> Application -> Infrastructure
Rules:
- Do not access the database directly from controllers.
- Add tests for application services.
- Keep public API contracts backward compatible.
Avoid filling the instructions with repetitive explanations that can be inferred from the codebase.
The goal is to provide high-value context rather than maximum context.
Avoid Repeating Large Tool Outputs
Consider a command that produces thousands of lines:
dotnet test
If the agent receives the entire output after every iteration, the working context can become unnecessarily large.
A better approach is to expose the relevant failure information:
Test summary:
Failed: 2
Passed: 187
Failures:
OrderServiceTests.CreateOrder_WhenInventoryIsEmpty
PaymentServiceTests.ProcessPayment_WhenGatewayTimesOut
The agent can then inspect the relevant test output when necessary.
This pattern is useful beyond testing. Logs, database queries, static-analysis results, and build output should be filtered when full output is not required.
Context Compaction
Long-running sessions eventually need context compaction.
Compaction attempts to replace a large collection of historical information with a smaller representation.
For example:
Before:
Task
|
+-- 20 tool calls
+-- 8 file inspections
+-- 4 test runs
+-- 3 failed attempts
+-- 2 architectural decisions
After:
Task summary
|
+-- Files changed
+-- Decisions made
+-- Current failure
+-- Remaining work
This can reduce the amount of context that must be carried forward.
However, compaction has a trade-off.
If too much information is removed, the agent may need to rediscover it.
That can create another cycle of:
Compact
|
v
Information lost
|
v
Agent investigates again
|
v
Additional tool calls
The best compaction strategy preserves information that is expensive to rediscover.
What Should Survive Compaction?
A useful compacted state should retain:
| Information | Preserve? | Reason |
|---|---|---|
| Original task | Yes | Defines objective |
| Architecture decisions | Yes | Prevents repeated reasoning |
| Modified files | Yes | Defines current state |
| Known failures | Yes | Avoids repeating failed approaches |
| Test results | Usually | Helps maintain progress |
| Large raw logs | Usually no | Can be regenerated |
| Temporary search results | Usually no | Often inexpensive to reproduce |
| Repeated explanations | No | Adds little value |
The important principle is to preserve state, not every historical message.
Tool Calls Need Failure-Aware Design
A coding agent should not treat every tool failure as a generic retry opportunity.
Consider:
Tool call
|
+--> Success -> Continue
|
+--> Temporary failure -> Retry
|
+--> Invalid arguments -> Fix request
|
+--> Permission failure -> Change authorization
|
+--> Deterministic application failure -> Diagnose
Blind retries can waste compute.
Join the conversation! Your thoughts help the community grow.