Sub topic 1
How Coding Agents Read and Use Context
Prerequisites
Assume you know one programming language, use Git, understand basic automated tests, and have tried an AI coding assistant. This chapter focuses on controlling the information an agent uses before implementation begins.
How Coding Agents Read and Use Context
A coding agent builds a working context from several sources:
- Your current request
- Project instruction files such as
AGENTS.md - Relevant source files and tests
- Existing specifications and task lists
- Tool results, such as search and test output
The agent uses this context to infer constraints, conventions, and dependencies. It may not read every file in a repository. It usually selects files that appear related to the request, so clear filenames and focused instructions improve its choices.
Why Prompts Alone Drift
An open-ended prompt often leaves important decisions unstated. The agent then fills gaps using assumptions, nearby code, or common patterns. Two agents may produce different behavior from the same prompt. A long conversation can also bury earlier constraints, and an implementation may gradually solve a broader problem than the one requested.
A specification reduces this drift by recording the intended behavior outside the conversation. It gives the agent and reviewer a stable reference.
The Spec-Driven Workflow
A spec-driven workflow moves from intent to implementation:
- Requirements state what the system must do.
- Design records important technical choices and boundaries.
- Tasks divide the design into small, ordered changes.
- Implementation completes one task at a time.
- Verification checks the result against the requirements.
Keep review gates between these stages. Resolve unclear requirements before design, and check each completed task before starting unrelated work.
Writing Requirements with Testable Acceptance Criteria
Use observable conditions rather than vague goals. EARS-style phrasing commonly uses WHEN or IF, followed by THEN, and names the required system behavior.
### Requirement: Password reset
1. WHEN a registered user requests a reset
THEN the system SHALL send a link that expires after 30 minutes.
2. WHEN an unregistered user requests a reset
THEN the system SHALL return the same response as for a registered user.
3. IF a reset link was used
THEN the system SHALL reject another use of that link.Each criterion describes a behavior that a test can exercise. Later, map each criterion to a task and at least one automated check.
Exercise
What is missing from the requirement “The reset process should be secure”?
Show answer
It lacks an observable condition and expected result. Replace it with testable behavior, such as an expiration rule, single-use rule, or response rule.