AWS Builder Center
Teach Kiro to learn from it's own mistakes

Teach Kiro to learn from it's own mistakes

How to use Agent Steering files to prevent Kiro from repeating mistakes

In software engineering we proudly use all kinds of processes to learn from each other and to prevent making the same mistakes again and again: Knowledge sharing sessions ("brown bags"), post-mortems, code reviews... Wouldn't it be nice to enable your AI pair-programming buddy to continuously learn as well?
When I do spec-based development with Kiro, there are some commands that Kiro needs to use multiple times. Probably you put them on the allow-list because you want Kiro to implement all the tasks quickly. But what if Kiro keeps running into the same problem and you have to manually intervene every time? In my latest project Kiro would often run
Bash
npm run dev
which started an Express.js development server in the foreground of the active terminal. Which made Kiro wait forever instead of continuing the task implementation. Or if it opens a new terminal it would try to start the server again on the same port and run into
port in use error


Agent Steering

Not only is this frustrating but it prevents Kiro from working autonomously and slows you down. Let's ensure Kiro learns from these mistakes by prompting it like the following:
You keep running  npm run dev  which runs a server in the foreground of the terminal, blocking you from continuing your work. Create an Agent Steering file called "lessons-learned" and add this as a lesson, preventing you from making the same mistake again.
 Agent Steering  is additional context that Kiro will keep in mind in every interaction. Think of it like long-term memory. In my case, Kiro generated a really good  lessons-learned  file describing the issue, making examples and documenting solutions. And most importantly, it prevented Kiro from running into the same issue.
The lessons-learned agent steering file Kiro generated

Now every time you encounter repeated issues like this, you can simply tell Kiro:
Add a lesson to the  lessons-learned  agent steering file: Do/Don't do XYZ
You can go even further and create multiple lessons-learned files for different situations (like sub-projects in a monorepo or application code versus infrastructure code). To achieve this you define when to include the file in the header:
YAML
---
inclusion: fileMatch
fileMatchPattern: "iac/**/*.ts"
---
Agent Steering files will be stored alongside specs in the  .kiro/steering  directory of your project. This allows you to share them with your team mates through version control. Which probably makes a lot of sense because you don't want them to run into the same issues, right? 😇

And what about Amazon Q Developer?

Lastly, if you use Amazon Q Developer, you can achieve the same by using  Project Rules !
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article