How Can AI Write Software Specifications? An Agent That Interviews Engineers
How can AI write software specifications? An AI context generator interviews an engineer, verifies the answers against the codebase and turns that knowledge into a structured specification that other AI agents can build from. Our agent asks one question at a time, follows a strict 13-section template and never writes a file without human approval. It never writes code. For one billing module it produced 65 documents and about 11,400 lines of context.
Engineers hate writing specs. So we built an AI agent that asks the questions, checks the answers against the real code, and writes the spec for us.
Why specifications don’t get written
Every engineering team agrees that good specifications matter. Very few teams write them.
The reasons are familiar. Writing a spec from a blank page is slow. It’s hard to know what to include. The person who knows the most about a feature is usually the busiest person on the team. And when a spec is written, it’s often vague in exactly the places that matter: the edge cases, the permission rules, the behaviour when a third-party service fails.
For human developers, a vague spec is an inconvenience. They ask a colleague, read the code, or make a sensible assumption. For an AI coding agent, a vague spec is an invitation to guess. And an agent’s guesses look confident even when they’re wrong.
We needed specifications that were complete, precise and consistent, without turning our engineers into full-time technical writers.
The idea: let the AI do the asking
Instead of asking engineers to write specs, we built an agent that interviews them.
The engineer describes the feature in their own words, as they would to a new teammate. The agent does the rest: it explores the relevant code, works out what it can, and asks about everything it can’t. Then it writes the specification in a fixed format and asks for approval before saving anything.
The agent has a single purpose. It documents; it never writes application code. That separation matters, because it keeps the agent focused on understanding rather than on producing output.
How the interview works
It asks one question at a time
The agent never sends a wall of questions. It asks one, waits for the answer, then moves on. Long questionnaires get skimmed; single questions get thought about.
It works through a fixed order of topics, skipping anything the code already makes clear:
- Which module does this belong to?
- What is the flow, step by step?
- Who can access it, with which role, and scoped to what?
- What validations exist?
- What are the key business rules?
- What are the edge cases and error scenarios?
- Which other modules does it depend on?
- Does it send any email or notification, and if so, what exactly?
It checks answers against the code
When an engineer says “only practice admins can do this”, the agent reads the route’s dependencies to confirm it. When the engineer names a file, the agent checks the file exists. Every path in the final document is a real path.
This catches a surprising number of mistakes in both directions: engineers misremember their own code, and code sometimes doesn’t do what everyone believes it does. Finding that out during specification is far cheaper than finding it in production.
It plays back its understanding
Before writing anything, the agent summarizes what it understood in plain English and asks the engineer to confirm or correct it. This single step removes most misunderstandings.
It never acts without approval
The agent announces exactly what it will create or change (“I’m going to create subscriptions/cancel.md, proceed?”), then shows the full diff and proposes a commit message. Each step needs an explicit “yes”.
The template: 13 sections, none optional
Every document follows the same structure, in the same order.
| Section | What it captures |
|---|---|
| Module | Where the flow belongs |
| Gist | Two or three sentences: what it does and why |
| Key files | Every file involved, verified |
| Authentication | Token type and auth dependency |
| Permissions | Roles, role checks, scope |
| Validations | Every check in order, each with a unique code |
| Flow | Step-by-step behaviour, with branches |
| Business rules | Every rule, each with a unique code |
| Test hints | Each rule and validation mapped to a test case |
| External calls | Each third-party call, when it happens, failure behaviour |
| Edge cases and error handling | What happens when things go wrong |
| Dependencies | Links to the other modules involved |
| Changelog | Who changed what, and when |
The rule is simple: never skip a section. If it doesn’t apply, write “N/A”. An empty section is a decision the AI will otherwise make for you.
A short example
Here is an abbreviated, illustrative document for a simple flow. It’s not taken from a real codebase.
# Apply coupon
## Gist
Applies a discount coupon to an active subscription. The discount
takes effect from the next billing cycle and never on the current one.
## Validations
- BILL-SUBS-COUP-APPLY-VAL-001: coupon code must exist and be active
- BILL-SUBS-COUP-APPLY-VAL-002: coupon must not be expired
- BILL-SUBS-COUP-APPLY-VAL-003: subscription must be in ACTIVE status
## Business rules
- BILL-SUBS-COUP-APPLY-BR-001: only one coupon per subscription at a time
- BILL-SUBS-COUP-APPLY-BR-002: percentage discounts round to the nearest cent
Test hints
| Code | Test case | Expected outcome |
|---|---|---|
| VAL-002 | apply an expired coupon | 400, “coupon expired” |
| BR-001 | apply a second coupon | 409, existing coupon kept |
External calls
| Service | Call | When | On failure |
|---|---|---|---|
| Stripe | update discount | Step 4 | roll back, return 502 |
Structure that machines can navigate
Structure isn’t only about the inside of a document. It’s also about where documents live and what they’re called.
- Every flow lives exactly three levels deep: module, feature, sub-feature, then the flow file. Consistency matters more than saving one folder level.
- One flow per file, capped at about 300 lines. Longer flows are split and linked.
- File names never repeat the folder path. Inside
subscriptions/, the file iscancel.md, notcancel-subscription.md. - Rule codes come from the path.
staff/billing/subscriptions/cancel.mdproduces codes likeSTAF-BILL-SUBS-CANCEL-BR-001. Every code is unique across the whole repository.
Plain English, on purpose
The agent is required to write in short sentences, in the active voice, without jargon. Our test: a developer joining on day one should understand the flow without asking anyone.
Compare:
- “The subscription entity undergoes a state transition upon receipt of the webhook payload.”
- “When Stripe sends a payment webhook, the subscription status changes to
active.”
The second is better for people, and it’s better for AI agents too.
Lessons baked into the questions
Some of the agent’s questions exist because we learned the hard way. Whenever a flow creates a payment invoice, the agent always asks: “How is this invoice actually paid?” It refuses to document invoice creation without the payment step. Similarly, for any email it asks about the subject, preview text, recipient, branding, links and attachments.
We’ll come back to this idea, turning past mistakes into permanent questions, in a later article.
What we learned
- Interviewing beats writing. Engineers find answering questions far easier than facing a blank page.
- Verification against code is essential. It catches errors in people’s memory and in the code.
- A fixed template removes decisions. Nobody debates what a spec should contain.
- The agent can’t replace knowledge. It can only extract it. If nobody knows how something should behave, the interview exposes that, which is valuable in itself.
The forward deployed angle
A forward deployed engineer’s most important skill is drawing knowledge out of the people who know the domain. The context generator turns that skill into a repeatable process: the engineer brings the client conversation, the agent asks the follow-up questions, checks the answers against the code and writes them down in a form other agents can build from. We cover this in more depth in our article on forward deployed engineering in the age of AI agents.
Key takeaways
- Don’t ask engineers to write specs; have an agent interview them.
- Ask one question at a time, in a fixed order.
- Verify every answer against the actual code.
- Use a strict template where no section is optional.
- Require human approval before anything is saved.
Read the approach behind this workflow: Context Is the New Code: How We Ship Production Features with AI Agents.
Frequently asked questions
What is an AI context generator?
A context generator is an AI agent that turns an engineer’s knowledge of a feature into a structured specification for other AI agents. It interviews the engineer, checks the answers against the codebase and writes the result in a fixed template.
Does the agent write documentation for existing code or for new features?
Both. For existing code it reads the implementation and asks about the gaps. For new features the engineer describes the intended behaviour, and the specification becomes what the coding agent builds from.
Why ask one question at a time?
Single questions get careful answers. A long list of questions gets skimmed, and the answers that matter most, about edge cases and failures, get the least attention.
How long does a typical document take?
It depends on the flow’s complexity. Simple flows take minutes; complex ones with several external calls take longer, mostly because they raise questions the team hadn’t fully answered.
