Índice do artigofaltam 17 min de leitura
Summary in one sentence: a software factory with agents does not come from a better agent, but from a pipeline in which the brief becomes a specification, the specification becomes tasks, tasks become pull requests, and a pull request only reaches the client after passing through gates the AI cannot open on its own.
There is a big difference between using AI to code and running a software production line with agents. The first speeds up one person inside the editor. The second changes the unit of work: the input stops being the prompt and becomes the specification, and the product stops being a snippet of code and becomes the reviewed, tested and published delivery.
This article is the construction manual for that second thing. It describes the layers of a software factory operated by multiple agents, what each one needs to produce, where the human approval gates sit, and how to measure cost, quality and time without fooling yourself.
The conceptual foundation is in orchestrating AI agents with governance, which covers when multi-agent systems are justified and which risks come with them. Here the focus is operational: how to build the pipeline.
Article summary
- The factory has four layers: specification, breakdown into tasks, execution by specialized agents, and integration with the repository, CI/CD and hosting.
- The quality gain comes from taking decisions away from the agent, not from giving it more freedom: contracts, scaffolds, the design system and architecture tests define the path before the first line of code.
- Four human gates hold the pipeline: specification, contracts, pull requests for sensitive code, and production release.
- The metric that matters is cost per accepted delivery, which includes tokens, review time and rework. Cost per token on its own is a misleading number.
What a software factory with agents is
A software factory with agents is a pipeline in which demand comes in as natural language and goes out as published software, with a decision trail at every step. What defines it is not the number of agents but three properties:
- A declared unit of work. There is a formal artifact, the specification, between the client's request and the code. Without it, each agent reinterprets the brief in its own way.
- Boundaries the agent cannot move. House standards, API contracts, the design system and architecture rules live outside the agent and are enforced by machine.
- Exit gates. Nothing reaches the client without passing deterministic tests and, at critical points, a person.
If any of the three is missing, what you have is a team using AI fast, which is already valuable, but it is not a factory. The difference shows up the day the same demand needs to be reproduced, audited or redone by someone else.
The full flow, from brief to the client's link
The diagram below is the whole pipeline. We call Forge the orchestration layer that covers steps 2 to 6: it turns requests into plans, plans into tasks and tasks into work distributed among agents.
Notice that AI produces the work in four of the ten steps: specification, tasks, implementation and pull request. The other six are the client's demand, the four human approval and review gates, and staging with client validation. That proportion is what separates a factory from a demo.
Layer 1: the specification agent
The most underrated role in the pipeline is the first one. The specification agent does not write code: it turns an ambiguous request into a document another agent can execute without guessing.
What it always needs to return:
- Negative scope, what is explicitly not part of this delivery. It is the field that prevents the most rework.
- Contracts, the format of the data and routes before any implementation exists, because that is what lets front-end and back-end move forward in parallel.
- Acceptance criteria, written as verifications, not wishes. "The user can export" does not work; "when clicking export with a filter applied, the CSV contains only the filtered rows" does.
- Risks and open decisions, the list of what it could not resolve on its own and needs a human answer for.
- Impact on what already exists, which screens, routes and tables will be touched.
The last item is usually the one that fails. A specification agent that has only read the brief produces a beautiful specification disconnected from the real system. It needs read access to the repository, the database schema and the architecture documentation to say where the change touches.
Layer 2: breaking work into tasks
Once the specification is approved, the orchestrator breaks the work down. Task size is an engineering decision, not a detail: a task that is too big produces a pull request nobody reviews, and a task that is too small multiplies context and coordination costs.
The practical yardstick we use:
| Criterion | Target |
|---|---|
| Diff size | Reviewable by one person in less than 20 minutes |
| Surface | One layer per task, unless the contract is already locked |
| Dependency | Declared, never implicit: front-end does not start before the contract exists |
| Definition of done | Verifiable by a command, not by opinion |
| Reversibility | One task, one logical commit, one possible rollback |
Declared dependency is what enables real parallelism. When the API contract exists as a versioned artifact, the front-end agent can work against a mock generated from it while the back-end agent implements the other side. Without that contract, both guess, and they only meet at integration, which is the worst place to discover a mismatch.
Layer 3: executing agents and distribution across models
This is where the most debated decision comes in: use the same model for everything or route by competence.
Routing pays off for two independent reasons. The first is competence: front-end and design reward visual consistency, interface reading and fidelity to a design system, while back-end rewards reasoning about state, data, concurrency and business rules. These are different skills, and models are not equally good at both. The second is price: within the same project, there is expensive thinking work and cheap repetitive work, and paying the price of the first for the second is pure waste.
The routing criterion that works is not "which model is best" but:
- Is an error here visible to the client? If yes, use the strongest model available. Screens and text the client sees leave no room for savings.
- Is the task repetitive and verifiable by tests? If yes, use the cheapest model that passes the tests. CRUD, pattern migration and component variation fall into this line.
- Does the task require understanding the whole system? If yes, the cost is in the context, not the model. Before switching models, reduce what it needs to read.
That last point deserves its own section, because it is where most of the money leaks.
Skills, scaffolds and the problem of rereading the whole project
An agent that needs to reread the repository for every task is expensive and imprecise. Expensive because context is paid per token. Imprecise because the more irrelevant text enters the window, the greater the chance the model anchors on the wrong part.
The solution is not a model with a bigger window. Anthropic itself describes the phenomenon as context rot: as the window grows, performance degrades, because the model's architecture creates pairwise relationships among all tokens present. More context is not more competence; it is more noise, with a cost.
The way out is to structure the house knowledge into pieces the agent loads on demand:
| Piece the orchestrator connects | The problem it solves |
|---|---|
| Repository | Source of truth for code and contracts |
| Skills catalog | Reusable instructions by task type, loaded on demand |
| Design system | Components and tokens the agent composes instead of recreating |
| Scaffolds | Project skeleton already in the house standard, so no agent starts from a blank slate |
| CI/CD | Deterministic gate between the agent and production |
| Usage meter | Tokens and cost attributed by project from day one |
Each piece solves a specific problem:
Repository instructions. A conventions file at the root, read automatically, with what applies to any task in that project: how to run, how to test, what never to touch, what the commit convention is. It is the context that should not need to be rediscovered. Anthropic's official recommendation for this file is to keep it under 200 lines, precisely because a bloated file consumes context and reduces adherence to the very instructions it carries.
Skills, or reusable instructions by task type. "How to create an endpoint in this project", "how to add a screen to the dashboard", "how to write a safe migration". The agent loads only the skill matching the task, not the whole manual. It is the same principle as a standard operating procedure: whoever is changing the tire does not read the engine manual.
The mechanism has a name and a number. In Anthropic's implementation, a skill presents itself at three levels: only the name and description are always loaded, at a cost of roughly 100 tokens per skill; the body of the instructions only comes in when the skill is triggered, in the range of a few thousand tokens; and attached files cost zero until they are read. With ten cataloged procedures, the agent pays a thousand tokens to know they exist and loads only what the task requires. It is the difference between a library with an index and a pile of paper.
Scaffolds. A project or module skeleton already in the standard, generated by a command. Much of an agent's bad architectural decision-making happens on a blank slate, when it has to invent structure. A scaffold removes the blank slate.
Design system as code. If the components exist, are typed and documented, the agent composes instead of recreating. If they do not exist, it invents a new button for each screen, and the inconsistency only shows up in visual review, too late.
How to prevent bad architectural decisions
The temptation is to solve this with a prompt: politely ask the agent to follow the standard. It does not work reliably, because a natural-language instruction is a suggestion, and suggestions fail at scale.
What works is taking the decision away from the agent. Four mechanisms, from cheapest to strongest:
- Generation from the contract, types and API clients generated from OpenAPI or the schema, not handwritten. The agent cannot diverge from a file it does not write.
- Architecture tests, executable rules such as "the domain layer imports nothing from the infrastructure layer". If it breaks, CI fails, and the agent receives the error and fixes it on its own.
- Short ADRs and a project constitution, the record of why a decision was made and the short list of non-negotiable principles, read before any iteration. The concept appears under that name in specification-driven development tools such as GitHub's Spec Kit, and it serves to keep the next agent from reopening a discussion that has already been closed.
- Permission boundary, the agent implementing a screen has no write access to the migrations directory. Least privilege applies to agents just as it does to people.
The rule that sums up all four: the agent proposes, the system decides. Every time the factory depends on the model's goodwill, it will fail at some point without warning.
It is worth noting that Claude Code's own documentation is explicit on this point: instruction files and memory are treated as context, not as mandatory configuration, and to block an action regardless of what the model decides there is a lifecycle hook that runs before the tool is used and can reject the call. In other words, those who designed the tool already assume that a text instruction is not a guarantee. A serious factory works on the same premise.
The human approval gates
Full autonomy is a bad goal. The right goal is autonomy on rails, with gates at the points where an error is expensive or hard to reverse. There are four.
-
Specification approval
It is the cheapest and most profitable gate. Fixing scope here costs a conversation; fixing it after the deploy costs a sprint.
-
Contract approval
Data model, routes and formats. Once front-end and back-end are built on top of them, changing a contract becomes a cascading change.
-
Pull request review
Mandatory for authentication, permissions, billing, personal data and database migrations. In other areas, CI decides and review becomes sampling.
-
Deploy release
Staging publishes on its own. Production requires recorded approval, with a rollback plan ready.
The detail that makes the difference is where these gates live. If they exist only as a team agreement, they give way under deadline pressure. If they live in the platform, as branch protection rules, mandatory review by code owners, mandatory status checks and environments with approval, they do not give way. It is worth treating the repository configuration as part of the product.
Repository, CI/CD and hosting: where the factory touches the world
The agent's delivery is not the code: it is the pull request. And the pull request only becomes value when the pipeline around it is ready.
The minimum setup:
- One branch per task, named after the task identifier, so the trail from brief to commit can be reconstructed.
- Pull request with context, containing what was requested, what was done, what was left out and how to test. An agent PR without this description transfers archaeology work to the reviewer.
- CI that fails early, with lint, types, tests and architecture checks running before human review. The reviewer should not be the first to discover the test broke. How to speed up this step is in CI/CD for small teams.
- A preview environment per PR, published automatically, with its own address. That link closes the loop with the client, and it is the piece that turns "it's ready" into "see it working".
- Real separation between staging and production, a topic covered in staging and production environments.
It is worth copying the decisions the platforms themselves made, because they work as a best-practices manual. GitHub, when it launched its coding agent, set three rules: the agent works on a branch with its own prefix, the pull request workflows stay frozen until a person with write permission clicks to allow them to run, and the agent cannot approve or merge its own pull request, a restriction that extends to whoever asked it to do the work. These are exactly the three controls missing in improvised factories.
It is also worth noting a risk that appears right here: an agent with repository access reads issues, comments and dependencies, and all of these are channels through which malicious instructions can come in. This is no longer a hypothesis. In June 2026, a security study published an attack chain that starts with opening a public issue on GitHub and ends with malicious code in the repository of a widely used action, combining a permission-check flaw with prompt injection to steal runner credentials. A variant of the same insecure configuration had been exploited for real against another project months earlier.
Treating content the agent reads as data, and never as a command, is a security requirement, not a refinement. In practice this means not letting an agent be triggered by third-party content without review, using short-lived federated identity instead of an API key stored as a repository secret, and granting the agent's app the minimum set of permissions. The topic is detailed in how to protect chatbots and agents against prompt injection.
How to measure cost, quality and time
A factory without measurement becomes an expensive bet. And the most used metric, cost per token, is precisely the most misleading, because a cheap delivery that comes back twice costs more than a correct delivery the first time.
The calculation that matters is cost per accepted delivery:
| Component | How to get it |
|---|---|
| Model consumption | Separate key or project per client, with usage reports by period |
| Human review time | Time between opening and merging the PR, excluding queue time |
| Rework | Fix commits on the same task after the merge |
| Pipeline infrastructure | CI minutes, preview environments and storage |
The first row of the table is usually treated as impossible, and it is not. The main vendors now expose administrative usage and cost APIs: Anthropic has usage report and cost endpoints in its Admin API, with filtering and grouping by key, workspace and model, and OpenAI exposes costs per project in an equivalent endpoint. Both require an admin key, different from the key used by the application. The practical consequence is simple: create one key or one project per client from day one. Separating consumption later, with everything mixed in a single account, is impossible.
There is an even more direct path for those using agent tools in the terminal: exporting telemetry via OpenTelemetry. Claude Code, for example, publishes metrics such as cost in dollars per session, token counts, lines of code, number of commits, number of pull requests and even permission decisions on editing tools, which work as a record of the human gates. With this, cost and deliveries sit in the same time series, without depending on manual reports.
Three quality indicators are worth more than any dashboard:
- Rate of PRs accepted without rework. The percentage of agent pull requests that go in without requiring a second round. It is the direct thermometer of specification quality.
For this first metric there is even an external benchmark. An empirical study analyzed thousands of pull requests opened by agents in public GitHub repositories and measured the merge rate by tool:
| Agent | PRs merged |
|---|---|
| Cursor | 71.5% |
| Codex | 71.1% |
| Claude Code | 61.0% |
| Copilot | 58.7% |
| Devin | 53.6% |
Source: empirical study of 9,799 agentic pull requests reviewed by humans on GitHub, 2026.
Two details from the same study matter more than the ranking. Only 35.7% of rejections reflected a clear agent failure: 31.2% were rejected due to process or workflow constraints, and the rest lacked sufficient evidence. And among approved PRs, 15.4% required explicit human involvement to get there. Translation: much of what the factory loses is not lost in code quality but in the design of the process around it. It is also worth remembering that the sample is open source, which tends to be more favorable than a proprietary, legacy codebase.
The other two indicators:
- Post-merge regression. How many incidents came from code that went through the pipeline. If it goes up, the CI is loose, not the model.
- Review queue time. As soon as the factory works, the bottleneck migrates to human review. Measuring this early avoids the illusion that you just need to generate more.
The honest counterweight
An article about an agent factory that only shows the gains is a marketing piece. It is worth recording what public evidence does not yet support.
First, speed gains are neither automatic nor uniform, and the most uncomfortable data point is about perception. METR's randomized trial, published in 2025, followed 16 experienced developers on 246 real tasks inside mature repositories they had worked on for years. Before starting, they estimated AI would reduce their time by 24%. After finishing, they still thought they had saved 20%. The measured time was 19% longer.
It is worth reading this number with the same care the authors ask for: they state explicitly that the study is not evidence that AI does not speed up most developers, nor in other contexts, nor in the future. The scenario was precisely the hardest: a large, mature codebase with high quality standards and developers who already knew it well. It is the worst case, and it is useful precisely for that reason. Research presented by Stanford and cited by the DORA report points to the same pattern: a gain of 35% to 40% on new, simple code, and 10% or less on complex legacy code. These percentages were presented at a conference and not yet published in a paper, so they count as an indication of a pattern, not a settled measurement.
Second, code volume is not delivery. The 2025 DORA report, with nearly 5,000 respondents, finds a positive relationship between AI adoption and throughput, and at the same time a positive relationship between AI adoption and delivery instability. The 2026 report names the hidden cost: verification tax, the extra time invested in testing and review to cope with the higher volume of output, and describes adoption as a J-curve, with a temporary drop in productivity before the return.
In the same spirit, GitClear, which analyzes code changes at scale, reports in 2026 a significant drop in lines classified as refactoring and a rise in duplicated blocks compared with 2023. These are data from a commercial company, not peer-reviewed, and should be read as a trend signal rather than causal proof. But the direction matches what we describe in vibe coding and regressions: maintenance debt scales with the factory if nobody is watching it.
Third, multi-agent cost is superlinear, and there is a public number for it. When Anthropic described its own multi-agent research system in June 2025, it recorded that architectures of this type consume around 15 times more tokens than a regular chat interaction, while a single agent already consumes about 4 times more. The context is replicated in each branch, and someone pays for it.
Two cautions when using this figure: it came from an internal evaluation, with the model generation of that time, and it dealt with research tasks, not software engineering. The conclusion that travels well is not the exact multiple but the direction: multi-agent is an explicit trade of cost for quality. It is justified when the work is genuinely parallelizable, exceeds what fits in a single agent and produces a verifiable result. It is not justified for simple tasks, where a single well-instructed agent delivers the same for a fraction of the price.
Fourth, autonomy without gates is accumulated risk. An agent that opens a pull request, approves its own pull request and deploys is not an advanced factory: it is a factory without quality control.
A 90-day rollout plan
Nobody builds the whole pipeline at once. The order below is the one that delivers results earliest with the least risk.
Weeks 1 to 3. Put the house in order before putting an agent in it: repository instructions, test commands that work from scratch, CI that really fails, branch protection and mandatory review turned on. In this phase no agent writes to production. What you gain here is the floor everything else will use.
Weeks 4 to 6. A single task type, chosen because it is repetitive, well tested and low risk. You create the first skill, the first scaffold and the first agent pull request flow. The goal is not speed: it is reaching a stable rate of acceptance without rework before expanding.
Weeks 7 to 10. The specification agent and task breakdown come in. This is when the pipeline starts receiving briefs instead of ready-made tasks. Here the first versioned contracts appear, along with the preview environment per pull request, which closes the loop with the client.
Weeks 11 to 13. Routing between models by task type, measuring consumption by project and expanding to a second team. Only now does it make sense to discuss cost per delivery, because only now is there a basis for comparison.
Checklist before calling it a factory
- There is a specification approved by a person before any code
- Data and API contracts are versioned and generate types automatically
- CI automatically fails anything that breaks the architecture standard
- No agent can merge or deploy to production without recorded approval
- Token consumption is attributed by project, not in a single account
- There is a number for the rate of acceptance without rework, and it is tracked
If all six items are checked, you have a production line. If three or more are missing, what you have is a fast team using AI, which is a good place to be, but it will not survive the first audit or the third simultaneous client.
Frequently asked questions
It is a pipeline in which the demand comes in as a brief, an orchestrator turns the request into a specification and tasks, specialized agents implement each task within the company's standards, and the result comes out as a pull request, tests, deploy and a validation link for the client.
Using AI to code speeds up the developer inside the editor. A factory changes the unit of work: the input stops being the prompt and becomes the specification, and the product stops being a snippet of code and becomes the reviewed, tested and published delivery.
It is not mandatory, but it usually pays off. Front-end and design reward visual consistency and interface reading, while back-end rewards reasoning about state, data and rules. Routing by competence and price reduces cost without losing quality where it is visible.
By taking the decision away from the agent. Contracts, ADRs, scaffolds, the design system and architecture tests define the path before the task starts, and CI blocks anything that breaks the standard. The agent chooses the implementation within boundaries it cannot move.
At four points: approval of the specification, approval of the data and API contracts, review of the pull request for sensitive code, and release of the production deploy. These are exactly the points where an error is expensive or hard to reverse.
By measuring cost per accepted delivery, not cost per token. That requires attributing consumption by project with separate keys, adding human review time and counting rework, because a cheap delivery that comes back twice costs more than a correct delivery the first time.
No. It moves the work from writing code to specifying, reviewing and designing the system's boundaries. Human review becomes the pipeline's bottleneck, which increases, rather than decreases, the importance of senior people on the team.
Conclusion
The question that opens a software factory project with agents is not "which model will we use". It is: what needs to be true in our repository for an agent to work here without breaking anything?
Whoever answers this question first discovers that much of the work is classic engineering: contracts, tests, environments, permissions and review. AI comes in afterward, and it comes in better, because it finds rails instead of open ground.
The end goal remains the same as before agents: turning a business demand into software that works, with predictable cost and no surprises in production. The difference is that now you can do it with a pipeline, not with heroics.
References
- How we built our multi-agent research system, Anthropic Engineering
- Effective context engineering for AI agents, Anthropic Engineering
- Writing tools for agents, Anthropic Engineering
- Agent Skills: overview and progressive disclosure
- Claude Code: subagents, memory and repository instructions and hooks
- Usage & Cost Admin API, Anthropic
- Measuring the impact of early-2025 AI on experienced open-source developer productivity, METR and the paper on arXiv
- DORA, State of AI-assisted Software Development 2025 and The ROI of AI-assisted Software Development, 2026
- GitClear, research on code quality and maintainability with AI
- GitHub: available rules for branch rulesets and environments with approval
- OWASP Top 10 for LLM Applications
Documentation and figures verified on August 6, 2026; pipeline diagram and Anthropic documentation references reviewed on November 11, 2026. The data on Anthropic's multi-agent system are from June 2025 and refer to the model generation of that date.





