در حال بارگذاری ...

Introducing the Ralph Loop0:00

(upbeat music) In the beginning of 2026, an agentic looping technique called Ralph Wiggum went pretty viral. And it also had a big impact on how I developed today. The idea of this technique is super simple. You take your favorite coding agent like cloth, open code, or codecs, and run it in a loop. Let me show you. (upbeat music)

Walking Through the Script0:25

Let me show you. (upbeat music) Right here, we have a simple repository with a best script called Ralph.sh. And let's take a quick look inside before we run it. The script takes a single parameter, the iterations, and it will default to 10. And then we have our for loop, which will actually do the work. Let me quickly show you what it does.

which will actually do the work. Let me quickly show you what it does. In every iteration, we'll just output on which iteration we are. And in here, we'll actually do our work, we'll start Cloud, in print mode using -p, and we'll feed it the content of prompt.md. Let me quickly show you what print mode does. (upbeat music) If we say cloth, a hello world will start

Using Print Mode0:57

(upbeat music) If we say cloth, a hello world will start our interactive shell like we're used to, and we'll see the model working. If we instead say cloth -p, hello world, the model will interpret the prompt and simply output the string when it's done. I like using cloth, but this will work with any coding agent. If you take a look at the prompt,

with any coding agent. If you take a look at the prompt, we'll just instruct the agent to find the highest priority task in project.md and implement it. We'll ask it to append the progress to progress.md and check off the completed task in project.md, and then we'll ask it to commit and push the changes. We have two guidelines. The model is only allowed to work on a single task,

We have two guidelines. The model is only allowed to work on a single task, and if the project is complete, it has to output this exact string. The result of this command will be stored in our variable result, which we will echo, and I will check if the magic string is there. If this string occurs in the result, great, all tasks are complete. Otherwise, we'll just keep iterating until we hit

Defining Project Tasks1:52

great, all tasks are complete. Otherwise, we'll just keep iterating until we hit our maximum. If we take a look at the project file, I just have a small project asking it to set up a view three app in our app directory, and we have a few tasks. We ask it to bootstrap a view three app, then we'll ask it to add a route at hello agent and render a view saying hello world with our robot emoji.

then we'll ask it to add a route at hello agent and render a view saying hello world with our robot emoji. We'll ask it to add a link to our hello agent page on the index page, and then finally, we'll ask it to add confetti when I click a title. I also speak the settings a bit, so we set up the model for success. For example, we'll allow these commands, like npm install, npm create, et cetera, and we'll deny a few destructive actions for a good measure.

Running the Automation2:27

like npm install, npm create, et cetera, and we'll deny a few destructive actions for a good measure. We'll talk about permissions in depth in a future lesson. Now, let's create a new branch and run our script. (upbeat music) The model is currently working, and remember, because we're in print mode, we'll only see the output after it has completed. About 30 seconds or so later, we'll see the first task being crossed off in the list,

About 30 seconds or so later, we'll see the first task being crossed off in the list, and we'll see the output in our console, and finally, we'll see our app appear in our directory. If you let the model turn for a bit longer, we'll see it completed all tasks, and we see it echoed this exact string, so we should hit this if statement in our Ralph script, and we'll break out of the loop after echoing all tasks are completed after five iterations.

and we'll break out of the loop after echoing all tasks are completed after five iterations. Let's cd into the directory, and let's run the R and F, and let's take a look at what our model created. All right, let's first take a look if the confetti is there, so by clicking the link, all right, we have some confetti going on, great. We also see the hello agent route, which will echo hello world with our robot emoji, so that's pretty cool.

Why the Loop Helps3:32

which will echo hello world with our robot emoji, so that's pretty cool. As you can see, this technique is pretty simple, but there's a lot of power and simplicity, and we will discover that in this course. But for now, you may be wondering what the benefit is of interacting with models this way. Well, for starters, models are bound by a context window, which eventually fills up. When this happens, the model will have to do

which eventually fills up. When this happens, the model will have to do some cleaning up in order to continue working, meaning it will effectively lose some of its memory. At the time of this recording, we have context windows of up to one million tokens available in some of the higher plans, which is already very royal. But it's also a proven fact that the model performs worse, the more filled up the context window is.

But it's also a proven fact that the model performs worse, the more filled up the context window is. A model actually shines in the first half or so of its context window, and after that, it's gonna go downhill pretty fast. A Ralph Loop mitigates this by simply starting a new session on every iteration, meaning the context window starts fresh. To give the model some form of memory, we use the project and progress files,

To give the model some form of memory, we use the project and progress files, which give the model some context to what's happened before and what has to happen still. And another benefit of the Ralph technique is that you effectively take yourself, the human, out of the loop, freeing yourself up to focus on other tasks. I find myself using this technique all the time, not only to do small proof of concepts, but to actually ship features into production

not only to do small proof of concepts, but to actually ship features into production and into the hands of users. So join me in this deep dive into Ralph, and along the way, I'll also share some insights into my agentic development workflow. Let's get started.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟