← все видео

Self-Validating AI agentic Loops - The 10 x "Ralph Wiggum" Pattern

Rasmus Widing · 2026-01-09 · 25м 2с · 1 671 просмотров · YouTube ↗

Топики: ai-loop-engineering

🎧 Аудио

📝 Summary

model=deepseek-v4-flash · prompt=summary-v7 · 7 160→2 617 tokens · 2026-07-20 11:49:43

🎯 Главная суть

RALF-цикл — метод, в котором AI-агент многократно реализует задачу и сам себя проверяет через набор критериев (юнит-тесты, линтинг, пользовательские скрипты), пока все проверки не пройдены. В этом видео автор интегрирует RALF-цикл в свой CLI-инструмент Kiro (разрабатываемый для хакатона) и одновременно переводит проект Shards с прототипа на вертикальную архитектуру. По ходу решаются проблемы совместимости промптов с Kiro (отсутствие аргументов в командах, краши на длинных сообщениях) и создаётся собственный RALF-генератор на основе PRP.

RALF-цикл: принцип самовалидации

Основная идея — не просто дать агенту задачу, а обеспечить его способностью самостоятельно проверять результат. Цикл устроен так: сначала пишется PRD (Product Requirements Document), затем он конвертируется в JSON-структуру задач (user stories). После этого агент берёт одну задачу, реализует её, коммитит изменения, обновляет файл прогресса и проверяет, все ли проверки пройдены. Проверками могут быть любые инструменты: CLI-команды, MCP-серверы, юнит-тесты, линтинг, тайпчекинг. Если что-то не прошло — цикл повторяется. Как только все критерии успеха выполнены, агент переходит к следующей задаче. В итоге система сама гарантирует, что код соответствует заявленным требованиям.

Связь с PRP framework

Автор ранее создал PRP (Prompt Replay Protocol) — собственную систему промптов для кодинг-агентов. RALF-цикл стал одним из ключевых источников вдохновения для PRP. В PRP уже давно использовалась концепция самовалидации, но без детерминированных скриптов — только через промпты. Теперь в репозиторий PRP добавлена явная команда RALF, которая реализует полноценный цикл: разбивает PRP на задачи и гоняет агента, пока всё не станет зелёным. Этот же подход автор переносит в Kiro.

Проект Shards: от POC к вертикальной архитектуре

Shards — CLI-инструмент для запуска кодинг-агентов в изолированных рабочих деревьях, позволяющий выполнять задачи параллельно. Днём ранее был создан POC (proof of concept), который умеет запускать команды, выводить список шардов и показывать информацию о них. В этом видео автор решает полностью переписать код с нуля, используя вертикальную архитектуру (Vertical Slice Architecture). Он подаёт агенту свою статью о вертикальной архитектуре и другую заметку о принципах старта проектов, просит создать файл architecture.md и затем на основе этого плана удалить старый source и пересоздать проект. Такой подход позволяет избежать рефакторинга и сразу получить код, соответствующий желаемой структуре.

Проблемы Kiro CLI и адаптация команд

В процессе работы выявились ограничения Kiro CLI:

Чтобы обойти это, автор модифицирует все свои промпты (createPRD, executionReport, implementPlan и другие): вместо указания аргумента в команде, сам промпт теперь инструктирует агента сначала спросить пользователя, что именно нужно сделать. Например, при вызове plan feature агент сам задаёт вопрос: «Какую фичу вы хотите реализовать?». Аналогично для файлового ввода — агент спрашивает «Какой файл выполнить?». Таким образом, все команды становятся совместимыми без изменения архитектуры CLI.

Разработка RALF-цикла для Kiro

Для интеграции RALF в Kiro автор создаёт две ключевые сущности:

В процессе тестирования цикл столкнулся с зависаниями и путаницей агента в директориях. Автор несколько раз прерывает, перезапускает, редактирует промпты, чтобы убрать лишние механизмы (например, Talk Hook). В итоге ему удаётся запустить рабочий, хотя и неидеальный цикл. Он отмечает, что RALF-цикл сжигает много токенов, поэтому его стоит применять осознанно.

Текущее состояние и планы

К концу видео RALF-цикл в Kiro запущен, но требует доработки: промпты для Kiro ещё не отлажены до конца. Автор обещает продолжить доработку и опубликовать готовые промпты в своём репозитории. Он также фиксирует прогресс в devlog, отмечая, что многое из тестов не попало в запись. Основной фокус следующего дня — стабилизация RALF и дальнейшее развитие функциональности Shards.

📜 Transcript

en · 4 417 слов · 55 сегментов · clean

Показать текст транскрипта
Hello, everyone. Today we are looking at if Kiro can RALF. What we're doing today, really, we're building out more of our shards project, and we're building a RALF loop into the Kiro CLI. And here's a little bit of a walkthrough of what RALF is. So if you have followed along at all in AI on X or Twitter for the last few weeks, you have certainly seen about the RALF loop. Basically, it's a loop that helps the AI agent self-validate. So similar things as my PRP system is based on is this now. It's created by a guy called Geoffrey Huntley. I think he created it way back in like March or February or something. I came across it first time in April, have some prompts based on it. And my PRP framework has some learnings from there for sure. and yeah i'm just going to go through a little bit here how it works so i'm going to link to all of this in the description ryan carson here has written like a step-by-step guide how to get it up and running with amp and there's like a full repo here so i'll link that as well and i'm just going to go through this flow diagram here in this video later on you can see the timestamps we recreate this flow in kiro step by step so we write a prd We convert that PRD to this kind of JSON structure. Then we run a script. That script breaks down of our user stories inside of our PRD into individual stories. AMP, or in our case, then Kiro picks up a story, implements it, commits those changes, updates that PRD.json, logs what it did into a progress file, checks if there was more stories, and then it just loops. At some point, it's done. So what really allows this to run for so long and so reliably is that you have to give it criteria. Success criteria, acceptance criteria, ways to self-test, self-validate. We have been through this before. If you have followed me, PRP is based on this concept as well. Give the AI agent ways to self-validate. This can be CLI tools, MCP servers, unit test, linting, type checking, whatever, really. The sky's the limit here. You can create your own. kind of validation scripts and so on so that's really the key concept so until all of those validation that you create pass the loop will continue and once all of those checks pass then it will be considered done so yeah let's dig into it today we are continuing to build out shards of course is our application that we started building yesterday it's a cli tool that will help us startup coding agents inside of new work trees in isolation so we can run things in parallel. So we have already gotten somewhere on this. I'm going to open up our IDE. And yeah, we're using Kiro for this because we're building this for the Kiro hackathon. Where we left off basically yesterday is we created a POC. Basically, it is working. We haven't really tested it too much. I have gone through the testing guide here. So I know that all of the basic functionality does work. We don't have any obvious bugs there, like the happy path of the POC works. We can start new commands. We can list open the shards and we can get info about them and so on. And we can, of course, use the terminal that opens when we talk to it. So yeah, it's pretty simple right now. And what we're going to do right now is that we are going to open up agent in our terminal. So we're going to open up kero CLI with the trust all mode. And we're just going to say here, I think we have actually maybe a prime command here from col. Let's see, prompts, we have prime. So I think we should be able to just do that. Right. Yeah, great. So that will prime for us. Let's just take a look at that. It goes through this process, listing the files, reading core documentation, entry point files, and so on. Okay. Cool. Pretty standard stuff. And let's take a look at what it's doing. Okay. So right now there's a couple of things that I'm going to be doing. I am going to take the POC that we have. I'm going to move it over to my desired architecture. I'm a big fan of vertical slice architecture. So I'm basically going to feed it a blog post I wrote about that and have it create the plan for how to convert it over to vertical slice. Since we're so early in development, we might just do a complete rewrite. let's go through the works here so i'm just going to say please take this article as input and i want you to create an architecture.md of our desired architecture based on this article we want to use a vertical slice architecture we want to use the same loading structure that is mentioned in the article and we want to kind of optimize the project for developing with ai following all of the principles that are mentioned in these blog posts Okay, great. So now I'm just going to go to my blog where I have things. I use this blog mainly for clients too, but the blog is mainly for me to copy content contexts to my coding agents. I just take this, I give it here, and I take the other post, which is this, which is basically guides for how I start new projects. This is written for Python, but it can be easily converted into any language. So that's what I like to do. I'm just going to say here, the output should be a concise architecture.md that should live inside of .kero.steering. Think about it like this when you create it. You don't have to over-explain the concept because you are the one who's going to be reading this. So you can think if you understand the concept, you don't have to over-explain it to yourself. It needs a simple explanation, some example, and a concise natural language explanation of the concept. So that's just a key bit. short when i've done this in the past it basically it really likes to kind of over explain over do this and create several thousand lines not sure why this is not sending okay so i had to restart hero here because it crashed when i sent such a long message so what we're gonna do instead is just gonna do i'm gonna create a file i'm gonna say prompt md inside of here go to my whisper flow so these are that's the thing we had there now we're gonna take the other thing from whisper flow and we're gonna paste it in here so we're just gonna save that and we're gonna say copy this relative path and go back to the terminal please read this and follow the instructions in there Okay, so that works. Something happened with Kiro when the prompt was long, like many thousands and thousands of lines. So it just crashed out there. I'm going to let this generate our architecture at MD and I'll come back once that's done. Okay, so we have our architecture document here created. I'm going to trust that this is pretty good. It seems neat. It seems pretty short, which is good. And for now, I'm going to delete this file. we don't need that anymore and let's see i'm just going to tell it here the things that i want you to pay special attention to is the logging strategy and the vertical slice pattern writing out the desired architecture here okay perfect i'll leave it like that can you please commit and push the architecture identity okay great so now we want to see here what are the main things in our current poc that is not aligning with our desired architecture. We're going to send this off here. Okay. So now we have a pretty good and primed context window here to create this kind of like plan how to move to the new architectures. And we're going to create, actually what we're going to do, we're going to test the prompts that we have from cold here. So we're going to do plan feature. We're going to need to read a little bit in this plan feature since it can take an argument. This is probably just taken from plot code here. So it cannot take that argument as we have learned from before. And let's just see. Let's see what it does here. If we do this plan feature here. Okay, perfect. So it asks me. Yeah, the feature that we want to implement is not really a feature. I wanted to create a plan for the refactoring needed to go into this type of architecture. Like there's two options here. We could just delete source and recreate it. That's totally fine. If that would be easier. I think that's actually easier. Or we can create a refactoring plan. I'll leave it up to you what you think is the best path forward. But my strong recommendation is that we delete source and we recreate it from scratch. Yes, create the plan and delete source. i don't recommend you do this kind of like delete source thing here but so what we did yesterday as we created the poc just to test our concept to make sure that we can get it working that's what we did now today what we do is we start building it properly that's why i created architecture making sure that we're following the correct patterns from scratch since we have written so little code there's no harm in deleting what we had there because we know that you're in a very simple way going to be able to recreate exactly what we had yesterday but just following the desired architecture improving the logging system and so on so i'm going to recreate that from scratch and let's just have that run in the meanwhile something that i kind of want to talk about is the ralph loop i'm sure that a lot of you have heard about the ralph loop It's basically created by this guy, Ryan Carson. I first heard about it in probably April or something of this year. And if you go into, for those of you who know my PRP framework, if you go into like my old PRP commands here and you go into the experimental stuff here, basically, if you read some of these prompts and some of these workflows that are in here, they are basically based on the Ralph loop. There is no scripting, like there's no deterministic shell scripts in there, but it's basically prompted like a RALF script. Big inspiration actually for PRP when I started creating PRP in the first place. When I started creating this, of course, it was at a more infant state than what it is now. So what I've done, I've actually built the RALF loop into PRP. So if you go to my PRP repo now, you can see I made some updates here today, and I actually created a RALF loop. So there is a new command here. There is a lot of new commands actually in our commands. So I have stripped out all of the old commands that I no longer use. They are in old PRP commands, so you can still use them if you like. But here are the main commands that I use on a database basis. Of course, the Ralph command is new. I've only tested it a couple of times. It's pretty cool. So I highly recommend you try it out. What it does basically is it breaks the PRP down into a Ralph loop and it can like creates until everything is working and everything is green. So what I'm thinking that we will do once we have written this new architecture in our Kiro, we're going to test if Kiro can Ralph and we're going to test if we're going to create the Ralph loop in Kiro essentially. So if we don't have time to do that today, we'll do that on Monday. Let's see. Anyways, you can look into more. I'll leave some of these links in the description. You can look into this thread. This is basically a full guide how to use RALF. Here is a flow chart diagram of how RALF works. You write a PRD. You convert that into a JSON structure of tasks. Then you run the script. In this case, then Amps picks a story. We want to have Kiro here pick a story, implement, commit, and then it just runs until it's done. So yeah, we'll test that at some point here with Kiro. It is a little bit of a token eater, so we're going to have to look out for that. But yeah, go to the PRP agent engineering repo, grab the new plugin. You can just install it as a plugin directly from Cloud Code. Instructions are here. So you can just follow the quick start or the plugin quick start. And yeah, let's get started. I'll create a dedicated video to how to do that some other day. Okay, let's go back. Let's see. So the plan is created. if you want to open that their plans should be in the artifacts right where did and get created up agents okay should we go so what i'd like to do here i would just say yes please implement it make sure that you self-test everything and make sure that you validate everything and don't stop until you have validated that everything works so now we are creating a prompted ralph loop here essentially by just telling it to self-test but anyways we'll have that run let's take a look when it's done here okay so something that we will do here while it runs actually is since we it's going to take a while to run these things probably we're going to open another key here and we're actually going to think about these commands that cole has written for us in the prompts what we see here a lot on this like a lot of them have arguments so here we have arguments in the createprd In the execution report, here we have arguments in the implement plan. Prime doesn't have an argument. Quickstart doesn't have an argument. RootCostAnalysis has an argument. So what I really want to do here, I'm going to take this relative path. And a way that I thought we can try to make these commands more hero-friendly, since it doesn't support arguments, we're going to do this. Can you please read all of the files inside of... prompts and understand which ones have arguments and which ones does not we're wasting with the tokens here having it read all the files but i'm just gonna make sure we don't miss anything because i'm gonna recreate these for you guys so that you can then also use these in your projects instead of having to rewrite all of them yourselves i will rewrite them for you okay so here we go okay great so now all of the commands that uses arguments. Since arguments are not supported by the Kiro CLI, what we need to do instead is we need to figure out a way how we can feed this information that is intended to be in arguments to the agent. So I want to rewrite all of the prompts that have arguments, just the section where arguments is used. And instead of having the argument being injected as an argument, I want the agent that reads the prompt. to ask the user what should the input be. So for example, if you run at plan feature, then instead of having an argument as the input, the user should ask the question, what feature do you want to implement? Same for execute.md, where it asks for a file input. Then instead of giving the file input directly, the agent should ask the user, which file do you want to execute before it starts executing? So that should be like the first action. agent takes after the argument. So that's how we intend to fix this argument issue. So I think that's going to solve all of the commands actually. So instead of having this syntax here, we just write it in a way so that the agent will ask us what we want the input to be. So yeah, that should work. Let's see. I see that you said you're ready with all the steps. Have you tested it? I haven't seen any terminals opening up on my image. I wanted to actually test the CLI as well. And I think it should work with like shards. Shards should be the command, right? I don't know what command you created now. It's compiling. I don't really know how formatting is done in Rust either. Rust formatting. Okay, so now all of the commands should be updated. Wait, can you please commit and push all of the changes to the commands? Make sure that you only commit and push the commands, not the source folder. okay so now while we have that running we're gonna quit we're gonna open up here again so now we should basically test these right but we can do that later okay so what i want to start doing here really now is i want to create the ralph loop this is going to be fun i think so i have some things that i have already created because i did this for the prp before but i'm going to tell it here can you please research the ralph wiggum loop related to ai coding and tell me what you find so i'm basically just priming it having it go off do some research okay so it found some information okay great can you also now then research the kiro cli and the latest documentation from the kiro cli so i'm just going to prime it on kiro cli as well i'm going to use some of the things that i have created we're going to use some of the things that was created by this guy here ryan carson so i'm just gonna give it this guide here as well i think here is also a guide okay great so it has no it does not prime there this one is stuck i think yeah so the kirozilla is hung again that's unfortunate that i did not mean to do okay so we should be able to resume let's try it here can you do this yeah okay so stash quit i see okay they were in the wrong directory okay so you want this guy back so now we have that guy split it left and let's just see if we can restart this guy as well because this one i'm not going to do that i'm gonna quit let's just quit let's start a new session for this guy instead and we're gonna reprime it okay now we would like to create a ralph loop for the kerosene It should all start by creating a PRD. So it should start with this command or a version of this command. The only thing we kind of want to rewrite in this command is this where we store files. Instead of inside the PRP directory that is prompted here, I want to store files inside a .kero slash artifacts slash PRDs. Okay. and what i'm going to do here yes i'm going to take because i have a create prd command i'm going to use so instead of creating a new prd command or using whatever ryan had created i'm going to use my own prd generator which i know works and that is good so i'm going to tell this guy here okay we crashed out during testing as we were implementing the plan in dot agents slash plans can you please read the plan in dot agent slash plan and continue testing i want you to test all of the cli commands okay i think that you jumped ahead a little bit too quickly here i just wanted you to create that let's say the prd generator itself where did you create that yeah that's where the prompt should store the files so this should be a command it should be in the prompt instruction itself the thing that i pasted to you should be stored in dot kero slash prompts and the output of that file where that file should store the prd that it creates should be inside of the prds directory and it's important here that when the user runs we can call it prd dash ralph then the first action it should do is ask the user what it wants to build. Once it's established what's to build, then it should follow the rest of the instructions, like asking all of the questions and so on. So now we have that created. Now we have another file here that we want to use to kind of run the RALF. So when the PRD is created, the RALF PRD, then it should be the next step in the flow should be running something like this that should then run the script to generate the JSON. It's also important that this file reads PRD. So the start of the script instead of the arguments that is here, it should ask the user which PRD do you want to run on similar to the other prompt files. Okay, so it seems to hang here too. What's the command? Take it there. Okay, there we go. we seem to be hanging here so can you please look into why this is hanging don't run it again okay can you please explain me exactly how this ralph loop works right now okay we don't need this talk hook mechanism here so what we want to do instead is the ralph loop.md should initiate the script and the script should initiate the loop I think we tried like that. We'll refine this. I'll test it out and then let's check. So I'm going to read through the script file and the loop executor. Okay, so this should work now. I read through most of the instructions. It should work. I'll test it. And if it doesn't work, then I will make some refinements before I commit it. Okay. okay let's then implement persistence do you think we should implement persistence through files or database sql lite don't implement anything yet we're just discussing possible solutions here yes we're going to go to ralph prd creation for this feature and we're going to go with the file based version of persistence here so what i want to have is that saved the persistence saved in a dot shards directory in the root And yeah, I think that's it. Keep it simple. Core principles. Okay. Can you please commit and push everything we did in the source directory? Okay. I'm going to just take a look here and make sure that we, okay, we actually already did. Yeah, it doesn't matter. We're so early on. It doesn't matter that there are some mistakes, but there are some mistakes in what Kiro does. Like Cloud Code would not just push everything without asking me, or at least it will listen to my instruction when I tell it not to. So we need to look out for that here as we continue a little bit. Everything here at least is committed and pushed. So we can, okay, I'm just going to keep all of these open for now. Select file-based persistence and start the RALF loop to the default 20. Okay, we're starting the RALF loop. Let's take a quick look also at our credits. Sign in. Okay, so we have 109 used credits right now. And it's starting right now. So let's let it run. There we go. I don't know why it has some issues finding stuff here. Okay. Seems to be a bit confused here where it was. Okay. So what I'm going to do here, I'm going to iterate a little bit on the RALF prompts for the Kiro CLI here as well to make sure that they are solid. I haven't read through them that thoroughly yet. If you do want to test the RALF... properly you can do it in my PRP directory as I shared before it works really well with PRP it works really well with what Ryan Carson shared as well so you can try it directly from there and yeah if you want to test it with the Kiro CLI it will also be up inside of my charge directory so you can just take it from there and put it inside of your own directory to try it out also remember we changed all of the prompts to now ask you which file to use as input instead of using the cloud code argument syntax that doesn't work in Kiro So let's take a look at that. We'll dig into more about functionality and continue building our application tomorrow. What I will do here now before I end, I will just run a slash devlog to devlog so that we can add today's progress to devlog. We didn't do much progress on the actual application today. We basically explored a little bit around the route commands. I tested a few different things in Kiro. I don't think I got everything on camera, unfortunately, some things. a few of the ralph loops that i did are not caught on camera when i fix some issues but yeah the ralph loop works and you can see it's running right now it's going to take a while so i'm not going to film through the whole thing i'm going to push everything when it's done and yeah i think that's it for today i will see you guys back on monday

⚙️ Pipeline jobs

StageStatusAtt.UpdatedError
download done 1/3 2026-07-20 11:48:57
transcribe done 1/3 2026-07-20 11:49:12
summarize done 1/3 2026-07-20 11:49:43
embed done 1/3 2026-07-20 11:49:44

📄 Описание YouTube

Показать
Can Kiro Ralph?

Ralph Wiggum The First Agnetic Engineer - AGI?

If you've been anywhere near AI coding Twitter the past few weeks, you've seen the Ralph Loop. Named after everyone's favorite persistently optimistic Simpsons character, it's an autonomous loop that lets AI agents self-validate and ship features while you sleep.

But here's the thing - Ralph isn't magic. It's just prompts and a simple flow. Which means it works anywhere.

Today I made it run in Kiro CLI. I've also built it into my PRP framework for Claude Code. The pattern is portable.

What you'll learn:
- How the Ralph Loop actually works (flow diagram walkthrough)
- Why it runs reliably (self-validation is the secret)
- Making it work in Kiro CLI (no arguments? no problem)
- The "Ralph Anywhere" insight - it's just prompts

Also rebuilt our Shards project from scratch with proper vertical slice architecture. POC was fun, now we're building it right.

🔗 Links:
- Join the hackathon (free): https://dynamous.ai/#/kiro-hackathon
- AI Coding Course: https://community.dynamous.ai/checkout/dynamous-friend-discount?affiliate_code=d020a5
- Shards repo: https://github.com/Wirasm/shards
- PRP framework (with Ralph): https://github.com/Wirasm/PRPs-agentic-eng
- Day 1-4 playlist: [ADD PLAYLIST LINK]

📚 Ralph Resources:
- Ryan Carson's Ralph thread: https://x.com/ryancarson/status/2008548371712135632
- Ralph repo: https://github.com/snarktank/ralph
- Ralph guide: https://snarktank.github.io/ralph/
- Geoffrey Huntley on Ralph: https://ghuntley.com/ralph/

📚 Other:
- Kiro documentation: https://kiro.dev/docs

---

Timestamps below 👇

---

🔔 Subscribe - Monday we validate and keep building.

🎓 AI Coding Bootcamp: https://community.dynamous.ai/checkout/dynamous-friend-discount?affiliate_code=d020a5

📬 More from me:
- Blog: https://rasmuswiding.com
- LinkedIn: https://linkedin.com/in/rasmuswiding

#aicoding #ralphloop #kiro #claudecode
```

### Timestamps

```
0:00 - Can Kiro Ralph?
0:30 - What is the Ralph Loop (quick explainer)
1:00 - The flow diagram breakdown
2:00 - Why it runs reliably (self-validation)
3:00 - Opening Shards project in Kiro
4:00 - Priming the agent
5:00 - Creating architecture.md (vertical slice)
7:00 - Kiro crashes on long prompts (workaround)
8:00 - Analyzing current POC vs desired architecture
9:00 - Decision: delete and rebuild from scratch
10:00 - The Ralph Loop and PRP connection
11:00 - Ralph is already in my PRP framework
13:00 - Fixing Kiro prompts (no arguments supported)
15:00 - Rewriting prompts to ask for input instead
17:00 - Building the Ralph Loop for Kiro
19:00 - Creating PRD-Ralph command
20:00 - Loop executor and script setup
22:00 - Testing the Ralph Loop in Kiro
23:00 - File-based persistence discussion
24:00 - Wrap up and what's next
```


Today, we're building a "Ralph Wiggum loop" into the Kiro CLI for our "shards project," focusing on **ai automation**. This loop allows **artificial intelligence** agents to self-examine, a concept widely discussed in the AI community. The video demonstrates how this **automation** can enhance agent capabilities, making our **ai coding** more efficient. Learn how this approach integrates into real-world applications.