Together with two partners I am currently building a proof of concept for something we call an agentic legacy rewrite: instead of migrating an old codebase line by line, we let AI agents rebuild it based on what the old software actually does. It runs under a company name that is still being set up, and I am deliberately writing this before the result is in.
Because the PoC is not finished. What I can say after a few months: most mistakes do not happen while generating code. They happen before and after.
TL;DR: Legacy modernization with AI agents works in four phases: Clarify (pull the business logic out of the old system, write a PRD), Define (architecture and guard rails), Generate (code in small, testable units), Validate (check at every transition, not just at the end). The three mistakes I see most often: generating without a PRD, no guard rails, pushing validation to the end. A realistic expectation is a clear efficiency gain in implementation, not a one-click rewrite. The result of our PoC is open.
Why legacy software is the topic at all
Anyone working with mid-sized companies or PE-backed software firms knows the picture: codebases that are 15 or 20 years old. Knowledge that lives in the heads of two people. A large share of the development budget going into maintenance instead of anything new. A classic rewrite takes years and often fails because nobody knows anymore what the old system actually does.
AI agents change one thing fundamentally: writing code got cheap. That sounds like the solution, but first of all it is a new problem. When code is cheap, wrong requirements get very expensive very quickly, because they get implemented immediately.
–> The bottleneck is no longer implementation. The bottleneck is specification.
The four-phase approach
The model we work with is not my invention. It emerged in earlier projects of my partners, and in the PoC we are testing whether it transfers to a different system.
Phase 1: Clarify
Before any agent writes code, the old system gets understood. Concretely: existing code, database and old documentation are translated into readable files, and a PRD is written from that. Not “the system should generate invoices”, but capabilities with scenarios: what happens when an invoice is cancelled after a reminder has already gone out.
This is where the real value sits. Implicit business logic that has lived only in code for 15 years becomes explicit. An agent helps with the reading. The decision about what belongs in the new system is made by a product manager together with the domain experts.
Phase 2: Define
The PRD becomes an architecture document: system boundaries, interfaces, data model, integration points. And, this gets underestimated a lot, the guard rails. Those are rules in text files that every agent reads on every task: which architecture patterns apply, how a module is structured, what is forbidden, which tests are mandatory.
Experienced developers become more valuable here, not redundant. They write the guard rails, not the code.
Phase 3: Generate
Only now do agents generate code. In small, testable units, capability by capability, test-driven. Frontend and backend with different constraints, each with templates so the results look consistent.
Phase 4: Validate
Every transition gets checked: is the PRD complete? Is the architecture document right? Does the generated code do what the scenarios describe? Automated tests, code review, and when something is wrong, the rule I consider the most important in the whole approach applies: do not fix the code by hand, improve the guard rails or the prompt. Otherwise the system learns nothing and the next agent makes the same mistake.
The three mistakes I see most often
We made all three in some form ourselves in the PoC or watched others make them.
Mistake 1: Generating without a PRD
The temptation is obvious: old code into the agent, “rebuild this in modern stack X”, done. The result looks impressive and is usually unusable. The agent adopts every historical workaround as a feature, guesses at ambiguities and invents behaviour wherever the old system is hard to read.
What helped: taking the Clarify phase seriously even when it feels slow. In our PoC, considerably more time goes into understanding and the PRD than into generation.
Mistake 2: No guard rails
Without guard rails, every agent run produces a different architecture. Module A uses one pattern, module B another, and after two weeks you have a new legacy system. This time without the excuse that it grew over 15 years.
What helped: not writing the guard rails perfectly in theory up front, but deriving them from mistakes. Every time an agent got something wrong, the rule was extended instead of the code corrected. After a few weeks the mistakes become noticeably fewer.
Mistake 3: Pushing validation to the end
The classic project mistake, just faster: generate for weeks, test at the end, discover that the PRD described one capability wrongly and everything builds on it. With AI-generated code that is more expensive than before, because in the same time you have produced far more code that is now wrong.
What helped: review at every transition, especially between PRD and architecture. And a prototype the domain experts use to validate the PRD before anything productive gets built. AI output is a hypothesis, not a result.
What a realistic set of expectations looks like
Honest, because the promises in the market are fairly big right now.
- No one-click rewrite. Generation is fast, understanding the old system is not. If you have a 20-year-old codebase, Clarify and Define take months, not days.
- Considerably higher implementation efficiency once the structure is in place. In my partners’ earlier projects the gain was noticeable, but I will not put a number here before our own PoC confirms one. The variance is large and depends heavily on how many touchpoints a feature has with the old system.
- Experienced developers remain necessary. Contrary to what is often claimed, not fewer, but in a different role: architecture, guard rails, review.
- The method needs time to settle. The first weeks are enablement, not productivity. Anyone expecting results after two weeks will be disappointed.
- Not every system qualifies. Where cloud models are ruled out for data protection reasons, the setup is considerably weaker today. That is a real limitation, not a footnote.
One reference that puts the discussion in context: a controlled study by METR from 2025 showed that experienced open-source developers using AI tools took longer on complex tasks, not shorter, because prompting and correcting ate up the time saved. That matches what I see: the gain does not come from the model, it comes from the structure around it. Without the four phases, AI in a legacy rewrite is more of a risk than a lever.
Where the PoC stands
Open. Clarify and Define are done, Generate is running, validation is at the first capabilities. What I can already say: the three mistakes above are real, and the guard-rail rule (“improve the system, do not fix the code”) is the part that makes the biggest difference.
Whether the overall result justifies the effort, I will know in a few months. Then I will write part two, with numbers.
FAQ
What does legacy modernization with AI agents mean?
An old system is not migrated line by line but rebuilt based on its documented business logic. AI agents help understand the old system and generate the new code within defined architecture rules. Product managers and experienced developers steer the process.
How long does a legacy rewrite with AI take?
It depends less on generation than on understanding the old system. For older systems, Clarify and Define take months. Implementation afterwards is considerably faster than a classic rewrite, but not “days”.
Do you still need developers?
Yes, but in a different role. Experienced developers write the architecture and the guard rails, review the generated code and improve the system when agents make mistakes. Less typing, more deciding.
What is the biggest mistake in legacy modernization with AI?
Letting agents generate directly without first extracting the business logic and capturing it in a PRD. The result looks good and adopts every historical workaround as a feature.
Further reading
- Interim Product Manager: specification and prioritisation for product teams
- Fractional Product Manager for software companies
- Agentic engineering: definition, practice and cost
Transparency
This text was written with AI assistance. The content, experience, assessments and final editing are mine, Raimund Herms.
