AI-Driven Development in Practice: A Four-Stage Workflow
This article presents a practical four-stage workflow for AI-driven development that closes the gaps between code-generating models and real engineering work: context gaps, process gaps, and acceptance gaps. It shows how to turn requirements into structured specs, supply context in layers, break work into small tasks executed by an agent loop, and automate verification through a unified check entry point. It also covers common anti-patterns, rollout metrics, and optional cloud hosting of the pipeline. The workflow is product-agnostic and can be built with common AI coding clients, spec conventions, and script orchestration.
1. Background: Why a Model That Can Write Code Is Not AI-Driven Development
Over the past two years, the capability boundary of AI coding tools has been pushed steadily higher: code completion, single-file generation, unit test drafts, and log summarization are all fairly mature scenarios. Yet when teams try to adopt them in real projects, three kinds of gaps show up repeatedly.
The first is a context gap. A model only sees the prompt you give it, while correctness in a real codebase depends on directory conventions, dependency versions, past decisions, interface contracts, and production constraints. Without these, generated code often “looks right but breaks at runtime.”
The second is a process gap. When people write code, they implicitly follow a flow of “think it through, break it into small steps, verify as you go.” A single one-shot prompt compresses the whole process into one step, which amplifies errors and makes them hard to locate.
The third is an acceptance gap. Once generation gets faster, the bottleneck quickly shifts to review and regression. Without checks that can run automatically, the more you produce, the faster debt accumulates.
So the core of AI-driven development is not “switch to a stronger model.” It is making the development process explicit, turning context into engineering artifacts, and automating acceptance. The rest of this article describes a four-stage workflow that does not depend on any specific commercial product. You can build it yourself with common AI coding clients, spec document conventions, and script-based orchestration.
2. Overall Architecture: A Four-Stage Loop and Three Asset Types
Divide the process into four stages and accumulate three types of versionable assets.
The four stages are:
- Intent clarification and specification: turn vague requirements into a structured spec document.
- Solution design and constraint fixing: define architecture boundaries, interface contracts, and acceptance criteria.
- Task breakdown and automated execution: split work into small tasks and run them in an agent loop.
- Verification, review, and knowledge feedback: run automated checks, sample manually, and write lessons back into the asset library.
The three asset types are:
- Spec assets: requirement specs, interface contracts, data dictionaries, and acceptance cases, all under version control.
- Context assets: project convention docs, directory structure docs, dependency lists, glossaries, and decision records.
- Execution assets: task lists, automation scripts, check rules, and a failure case library.
The key judgment behind this structure is: anything the model needs to know should become a file; any rule for deciding right from wrong should become an executable command. The former addresses the context gap; the latter addresses the acceptance gap.
3. Stage One: Intent Clarification and Specification
A spec file is the intermediate layer that converts natural-language requirements into a machine-consumable structure. A minimal usable template looks like this:
# Change Spec: Rate Limiting for Order Export## BackgroundExport jobs during peak hours overload the query layer.## GoalsPer-tenant export concurrency must not exceed 2; requests beyond that return a clear error code.## Non-GoalsDo not change billing logic.## Interface ContractPOST /exports -> 202 {taskId} | 429 {code, message}## Data and StateTask states: PENDING/RUNNING/SUCCEEDED/FAILED## Acceptance Cases1. With concurrency of 3, the third request returns 4292. Failed tasks can be retried within 24h## Risks and RollbackRoll out gradually via a config switch; disable the entry point if anything goes wrong.
The important parts are the “Non-Goals” and “Rollback” sections. They significantly suppress scope creep from the model (changing things that should not be changed) and give later reviews something concrete to rely on. Spec review should be done by people; the model is only responsible for turning spoken descriptions into structure and proactively asking about missing items.
4. Stage Two: Solution Design and Context Engineering
The actionable principle of context engineering is layered supply with on-demand loading:
- L0 global conventions: directory responsibilities, naming rules, logging and error code conventions, commit conventions, kept within roughly a thousand words and always loaded.
- L1 module docs: one doc per module covering responsibilities, dependency direction, and prohibited actions.
- L2 contract files: interface definitions, message formats, and database table schemas.
- L3 retrieved snippets: use keyword or vector search to fetch relevant past decisions and similar implementations.
You also need a “prohibited list,” for example: do not introduce new runtime dependencies, do not modify generated directories, do not change the semantics of shared error codes. Constraints written as negative sentences get noticeably better compliance from models.
The solution design stage should also fix the acceptance commands so that “done” has an objective definition:
# Unified check entry point (illustrative)make lint && make typecheck && make test && make contract-test
5. Stage Three: Task Breakdown and Automated Execution
A good breakdown granularity is “a single task can be completed within one session and verified independently.” Task template:
Task: Add a concurrency gate to the export APIInputs: spec file path, module doc pathConstraints: only modify the src/export directorySteps: read contract -> write implementation -> add tests -> run checksDefinition of done: make test is fully green and new cases cover the 429 branch
Automated execution can be driven by an outer script that runs the agent loop: read the task queue, execute one by one, and on failure feed the check output back to the model for a retry; if the threshold is exceeded, suspend and wait for a human. Pseudocode:
for task in load_tasks("tasks.yaml"):for attempt in range(3):result = agent.run(task, context=load_context(task.scope))if run_checks(task) == 0:commit(task); breakagent.feed(result.log_tail) # feed failure info backelse:escalate_to_human(task)
Three engineering details decide success or failure. First, small commits: one commit per task, which makes bisection easy. Second, truncated failure feedback: avoid overly long logs crowding out the context. Third, a circuit breaker threshold: consecutive failures must escalate to a human to prevent wasted loops from burning quota.
6. Stage Four: Verification, Review, and Knowledge Feedback
Build verification as a pyramid: static checks and type checks at the bottom, unit tests in the middle, and contract tests plus end-to-end smoke tests at the top, all invoked through a unified entry point. Human review focuses on only three things: spec conformance, boundaries and security, and maintainability.
Knowledge feedback is the most easily overlooked step and the one with the highest payoff: classify each failure cause into the failure case library, and add newly established conventions into the L0/L1 docs. The thicker the assets, the higher the first-pass success rate of later generations, forming a positive loop.
7. Common Anti-Patterns
- One-shot giant prompt: cramming ten requirements into a single conversation, making errors impossible to attribute.
- Generation without acceptance: no executable checks, so review costs exceed the benefits.
- Unbounded context: stuffing the whole repository into the prompt, diluting key constraints.
- Skipping specs and coding directly: requirement ambiguity gets “rationalized” by the model on its own.
- Unattended long runs: no circuit breaker or budget cap.
8. Rollout Advice and Cloud Support
For rollout, start with a pilot on low-risk modules for two to three weeks and measure four metrics: first-pass success rate, average rework rounds, review time, and defect escape rate, then expand the scope gradually.
If a team wants to host this pipeline, a combination of general cloud capabilities works: code hosting and pipeline services for commits and checks, a container platform to run stateless executors, object storage for specs and artifacts, a message queue for task distribution, and logging plus monitoring and alerting to observe success rates and quota consumption, with unified identity and access control for access boundaries. Baidu AI Cloud offers corresponding capabilities in these general categories, and you can select and combine them according to your own compliance and network requirements.
The final criterion is simple: only when specs, context, and checks are all written down as files and commands does AI truly enter the main development workflow, instead of staying at the level of a completion tool.
