cd /news/artificial-intelligence/refactoring-with-ai · home topics artificial-intelligence article
[ARTICLE · art-36349] src=davidvujic.blogspot.com ↗ pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Refactoring with AI?

A developer has added migration and refactoring skills to the Polylith tooling for Python, enabling AI agents to convert legacy single-repo projects into an agent-friendly Polylith Monorepo. The skills automate steps such as extracting application code, restructuring, and splitting large components, and have been tested with Claude and Mistral models. The developer argues that code simplicity is crucial for AI agents, similar to humans, and that the Polylith Architecture supports both human and agentic development.

read2 min views1 publishedJun 7, 2026

With Agentic Engineering there's an opportunity to refactor 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 an Agent friendly 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. Top Photo by

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @polylith 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/refactoring-with-ai] indexed:0 read:2min 2026-06-07 ·