How AI Agents Helped Rewrite 40,000 Lines of Ancient Energy Code

Mistral AI built a structured workflow of AI agents to modernise a European energy company's 1970s-era simulation software. Here is what worked, what failed, and what it means for industries still running on decades-old code.

AI2Day Newsdesk5 min read
A close-up, news-editorial photograph of a large printed spreadsheet covered in red negative numbers and cost figures, lying on a polished boardroom table
Share

Key points

  • Mistral AI used AI agents to migrate 40,000 lines of Fortran 77 code, a programming language standardised in 1977, to modern C++ for a European energy operator.
  • Two fully autonomous approaches failed before the team settled on a human-supervised workflow combining a planner, coder, tester, and reviewer agent working together on each section.
  • The 40,000 lines completed represent the first sprint of a 300,000-line codebase.
  • Engineers built a numerical verification system before writing a single line of new code, which they say was the single most important step in the project.
  • Mistral says the three-agent-plus-human-review structure outperformed both full automation and manual coding sessions.

Deep inside a European energy company's computer systems, a physics simulation has been running for decades on code written the same year Star Wars first appeared in cinemas. The language is Fortran 77, a programming language standardised in 1977 that most working software engineers have never touched. The company needed it modernised. Mistral AI took on the job.

The result, detailed in a post on the Mistral AI blog, is a case study in what AI agents (software programs that can plan and carry out multi-step tasks on their own) can and cannot do when the problem is genuinely hard.

Why is old code so difficult to update?

Fortran 77 was built for a world without many features programmers now take for granted. Variables had no declared types; a single mistyped letter would silently create a new variable instead of throwing an error. Shared data lived in something called a COMMON block, essentially one giant pool of memory that every part of the program read from and wrote to at once. There were no tidy, self-contained modules.

Moving that structure to C++, a modern language built around reusable objects and explicit data types, is not a straight translation. It is closer to rebuilding a Victorian house to modern safety codes while keeping the family inside. The shapes do not match line for line, which makes checking the work extremely difficult.

The project also had no test suite (automated checks that confirm the software behaves correctly) and no centralised documentation. Knowledge about what the code actually did sat in old PDFs and in the heads of engineers who had long since moved on.

What did the AI agents actually do?

Mistral tried three approaches before finding one that worked.

The first: give each AI agent a single Fortran subroutine (a self-contained chunk of the program) and let it translate freely. A week later, the output was functional but embarrassing. The agents had essentially retyped Fortran in C++ clothing, preserving all the old bad habits.

The second: use a team of four agents (planner, coder, tester, reviewer) working together. Code quality improved. But when agents hit a complex bug, they would loop through fixes and stall with no way out.

The third attempt, the one that shipped, kept the four-agent team but put a human engineer in the loop to unblock stuck agents and approve each section before it merged into the main codebase.

Attempt Structure Outcome
1: Full autonomy One agent per subroutine Functional but not modernised
2: Agent teams, no human Planner, coder, tester, reviewer Better quality, agents got stuck
3: Human-supervised teams Agent teams plus human review gates Mergeable, modernised code

What should other organisations take from this?

Mistral draws three lessons it says apply to any large legacy migration project.

Build verification first. Before touching the old code, the team built a system that could dump the Fortran program's internal state at key moments and compare those numbers against the new C++ version. If the outputs matched, the migration was provably correct. This step, they argue, is the cheapest insurance available.

Document before you automate. The team used over a hundred AI agents to read the codebase and old PDFs (using Mistral's own OCR tool to extract text from scanned documents) and write proper documentation. Agents cannot migrate code they cannot understand, and neither can humans.

Keep a human in the loop at scale. Full autonomy sounds efficient but produces code that looks modernised without being modernised. Full manual review defeats the purpose. The middle path, structured agent workflows with human checkpoints, is where the productivity gains actually land.

For businesses running legacy software in energy, manufacturing, finance, or healthcare, the practical message is straightforward. AI agents can accelerate this kind of work significantly, but they are not a hands-off solution. The 40,000 lines completed here came from a codebase of 300,000. The work continues.

Common questions

Does this mean AI can automatically modernise any old software?

Not yet. This project started with a codebase that was self-contained and could actually run, which Mistral describes as a favourable condition. Code that depends on external systems or encodes physics documented nowhere would be harder still.

Who does this affect outside the energy industry?

Any organisation running software written before the 1990s faces the same core problem: the people who understood the code have gone, and the code itself does not explain its own logic. Industries including banking, aviation, and public health services carry significant amounts of this kind of legacy software.

© 2026 AI2Day