Oh hey there!
Since you are here, I assume one of the following things:
- Your codebase doesn't feel like yours
- The complexity is just blowing through the roof
- One tiny change, and everything starts collapsing like dominos.
In that case, I have got you covered! This blog tells you few of the many ways you can use to ensure your code makes sense after an agent has finished doing its magic.
The current slop scenario
I bet you have heard this a lot: "AI is your friend", "AI helps you get your things done 100x faster", "AI helps you stay ahead in the race". Well, sadly, our friendly AI is more of a blocker in our journey unless it is used mindfully. Try throwing random commands at it, and it starts loading up its slop canon.
Here's a diagram to help you understand how AI starts producing slop;
This is the result of poor context establishment and bad prompts. With more turns (prompts you send in), the agent gives slightly worse response than before. The fancy term for this is entropy, which states: "the inevitable tendency of a codebase to drift into disorder, complexity, and disorganization as it is modified and scaled over time"
Entropy is imminent, and it will happen, no matter how careful you are. But, you can slow down its rate. In current time, software development is on steroids - everything is fuelled by AI. Be it implementing a new feature, or fixing a bug, or helping people understand what a part of the code does.
Developing the AI-driven mindset
LLMs are trained on gigantic datasets. Unlike humans, it knows what comes after a particular step. But, it decides the 1st step based upon the best possible token given certain context about the problem. For example, AI completion of “The sky is ___” will almost always be “blue”, and hardly ever “starry”. But, prepend “During the night” to the sentence, and the answer now will always be “starry”. This is how context works. Attention to the necessary details matters the most whenever we are prompting the agents to get work done.
Hopefully, you have heard people saying how important it is to understand the basics of software engineering, here's why:
AI agents know the solution, but, they need guidance. It is never a good idea to let AI do its job without supervision. Hence, just like the old days when we used to spend considerable time in planning and brainstorming before actually starting the work, it holds true today too!
But, now it's computers we are talking about. Hence, we could diversify our approach a little bit to still use the power of AI while ensuring solid responses.
What works for me
Here is a list of things I do in my everyday development to generate reasonable code.
Plan your changes first
I can't stress on this enough, but this is the most important part of this entire blog. DO NOT LET AI DO THE THINKING ON YOUR BEHALF. Instead of saying, "Build me a login system", be more specific with what you exactly want. A prompt like "Build me the backend of a login system that accepts a username and password, performs lookup from the database, matches password using BCrypt, and responds in 200 Success if the result is found, 401 Unauthorized otherwise" is guaranteed to give you better results.
LLMs are great at understanding structured texts. So, always try to get your plan summarized into a markdown file before sending it in.
Another trick I use is, given the rough sketch of a plan, I ask the agent to grill me with my plan and establish all the necessary details that should be added into the prompt. Besides strengthening your prompt, it also helps you understand your idea better.
Use clear instructions in every prompt
LLMs have the tendency to think through their actions. The more abstract terms you shove into your prompt, the harder time the LLM faces, and it includes irrelevant context into the turn. This ultimately spoils the outcome.
Instead, stick to this:
- crisp, short sentences
- 0 ambitious words
- remove invalid references
Break down your task into multiple steps
A few modern coding agents already can split up the work into chunks and attempt them serially. But, it is always a good idea to split up your work yourself. This is especially true for feature implementations. Instead of having a massive prompt for the entire feature, break it down into the following blocks:
- the actual feature
- tests
- documentation changes
- compliance and adherence to business logic
You can be even more creative and split up your task into modules, rather than layers. Whatever suits your purpose.
LLM as a judge and a continuous feedback loop
This is my personal favourite. If you are an AI engineer you have certainly came across this challenge, and it's a quite interesting beginner level project to solve.
But this can be applied to your software development flow aswell!
Create two skills locally:
-
/evaluate-turn: This skill will go through the changes made by the agent in your feature prompt (or prompts if you have broken down your task), and look for defects in it. This might include missing test coverage, divergence from business logic, code smells, and many more. Here's an example skill. The response of this skill invocation then can be saved into a markdown file for future use. -
/judge-evaluation: The previous skill might generate too many issues, and it can be difficult to go through them one by one. This skill will judge the report generated from the evaluation, and flag the actually worthy issues. Then, we can just go through the ones that are finally flagged as worthy. You can get a look at the skill here.
Instead of having just a single (or multiple step-wise) prompt implement your task, pair it up with two more prompts.
Notice how we have now formed a continuous feedback and development loop, powered by AI and having human in the loop:
Until next time :D
That's it! I'm sure there are a ton of other approaches that can make your code even better, but this is just enough to reduce the rate of entropy we talked about earlier.
I tried to keep it as short as possible while trying to convey all the important stuff. You are welcome to grill me in the comments ;)


Top comments (0)