With Agentic Engineering there's an opportunity for refactoring of legacy code, but this aspect of AI isn't that that much talked about and seems to be overlooked by teams out there. So far, the main thing with AI and agents has been to build new things in a fast pace.
After several months of practicing Agentic Engineering, I've realized that code quality - or code health - is more important than ever. Agents get confused by complexity, just like humans. You've probably seen it (I have too) and now there is also research backing it up. Keeping code simple is a good guideline also in the agentic era.
This is where I believe the Polylith Architecture is a good fit, for both humans and agents. The original idea of Polylith was to keep things simple and great Developer Experience for Humans. As a nice side effect, Agents will probably like this setup too. An agent will have the context it needs to build new features from the existing well-organized code in the Monorepo.
Since before, the Polylith tool for Python includes a set of agent skills about the commands and about Polylith in general. But what about migrating an entire existing single-repo project into a Polylith Monorepo? With AI, many steps could be automated here.
I recently added additional skills to the Polylith tooling that are focused on migrating and refactoring an existing Python project into a Polylith Monorepo. The migration skills handles the extracting of application code, restructuring and also refactoring of large components into smaller ones.
The agentic flow for the migration of a project is:
- discover
- analyze-imports
- extract-to-base
- update-imports
- prepare-project
- verify-stability
- isolate-base-and-big-component
- split-big-component
- extract-standalone-modules
- isolate-shared-and-project-logic
- distribute-wiring
- split-component-internals
- refactor-tests
- definition-of-done
Also, the project-specific tooling (such as Project & Dependency management, linting and type checking) is migrated and converted according to what’s already in the monorepo.
Example: you use uv and ruff in the Polylith Monorepo, and migrate a project that uses Poetry and flake8. The migration will convert those to uv and ruff.
I have tested the skills with Claude (Opus 4.7 and 4.8) and Mistral (mistral-large and devstral). One of the tests I ran was converting the FastAPI repo (just for fun and to test the skills out) into Polylith.
Before running the prompt, I copied the contents of the FastAPI repo into the Polylith projects folder. I also removed the existing .git folder in there, to avoid any confusion during the agentic work.
Hint: the more unit tests the project to migrate has, the better!
The skills are part of the polylith-cli, and you can copy the contents of the .agents file or use a tool like library-skills to add them to your monorepo. Agents are unpredictable and different models behave differently. If you decide to try this thing out, please let me know how the skills works for you.
You'll find info about Polylith for Python here.

No comments:
Post a Comment