Loading video player...
Hey friends, this is Viv from Langchain.
So if you've been keeping up to date
with the latest and the greatest in
agentic coding, then you might have
heard of this guy. This is Ralph Wigum,
famous from the Simpsons, but given a
sort of new lease on life in our agentic
world by our good friend Jeff Huntley.
Now, what does Ralph actually have to do
with agent encoding? Well, we can thank
the Ralph loop for that. Let's dive in.
It's a story of perseverance, but it's
also a story of what your agent can
really do with a simple while loop and a
file system.
Great. So, we talked about the Ralph
loop, but what's actually in there? To
show you, we built Ralph mode for deep
agents. It's a pretty simple flow. So,
basically, here's how it goes. you have
some sort of task or task specification
here. We'll keep it pretty simple. I'm
just asking my agent to build a Python
course. That same prompt and that same
task gets passed to the deep agent on
every iteration. So my deep agent gets
this task the associated prompt and then
what it also gets is access to the file
system. So the file system sort of acts
as a work log and a memory store for the
agents work over these iterations. So
you can have iteration one, two, three,
you can set max iterations or you can
just let Ralph run and then check on it
later and stop it if you want. So this
is the loop to keep it running.
Why is this important and what why does
this matter? Well, few reasons. First of
all, one of the easiest ways today to
get agents to do longrunning work is
just by forcing them to continue this
loop over and over again.
The other important thing is that agents
are really, really good at using file
systems. And file systems are great
because if they're coupled with
something like Git for history, they can
keep track of the other work that
they've been doing. So, it's pretty
simple. I just give my deep agent a
task. It continues to do work on it.
It'll probably save some files to the
file system for this task, which is
build a Python course. It'll make some
demo files, some some writeups, some
course content, and then when it thinks
it's done, it will just loop back and
it'll see its previous history, and then
we'll just get the same thing, which is
continue building the Python course.
Cool. Let's actually dig into what a log
looks like when we run Ralph.
Great. So let's take a look at what
happens when we just let Ralph cook for
a little bit. What we have here is the
Ralph mode of our deep agent CLI. So a
few things to sort of point out here.
First is we have this flag the Ralph
flag and second is what's the actual
instruction specification that I'm
giving Ralph. So it's build a Python
programming course for beginners use
git. You can also set the number of max
iterations. So these are the Ralph
iterations here. There's a few different
ways of designing the Ralph loop. For
example, you can just sort of let it run
forever and then you go and you manually
exit it. Um you can also let Ralph break
out of the loop by saying that he's
done. Just different design decisions.
At the end of the day, you're basically
looping Ralph over and over again over
the same prompt and an updating file
system. So let's sort of take a look at
what Ralph goes and does when we let him
be. So iteration one takes a look at
what exists and sees if there's anything
there. Then the main thing here is
usually Ralph starts with creating some
sort of to-do list. This is because
we're built on deep agents and deep
agents has this sort of primitive built
in which is our to-do list tool. It goes
and it does that and then what it does
is it starts executing stuff. So it goes
it makes a readme. it it says okay these
are the modules that I have to build and
then eventually I need to initialize the
git repo so it's going it's doing some
of this stuff it's using the right tool
to write these Python files and it's
doing work so let me show you what
happens
as Ralph continues to work and gets to
the second iteration
so again iteration two happens so we did
one cycle of the loop Ralph tried to
exit but we go and put him back at the
start. So, updated file system, updated
git, but same prompt, continue to build
out the Python course. Great. So, Ralph
says, "Okay, let me check what exists
and I'll continue building out the
course." Takes a look at what exists and
then starts updating the task list that
he needs to do. So, this sort of loop
just keeps happening over and over
again. And if I didn't set a max
iterations, then eventually I would need
to come back to this, see the progress,
and stop Ralph manually. At the end,
I'll scroll all the way here and sort of
see what Ralph completed. So nice of
Ralph to give us a final summary. So
completed six modules, 74 exercises
through world projects. You get the
idea. When you let agents act in this
loop over and over again, then they can
just sort of make progress and track
their changes over time using the file
system. Another thing I'll mention
that's pretty interesting, context
management is still pretty difficult to
do across these longunning agent tasks.
Things like compaction, summarization,
offloading are ways to mitigate this
idea of context rot where you if you
have a ton of context, then your agent
performant degrades. But what we can do
is if we just restart the loop and we
let Ralph see, hey, these were the
changes that were roughly made. This is
where I'm starting from now. then we
have a cleanish context window and it
can just continue working in some sort
of loop. So just another thing to to
note that Ralph is actually really good
for context management if you want to
work in these like long running tasks.
Hope this was fun. Hope you have fun
playing with Ralph and really excited to
see uh what you make Ralph do. Thank
you.
š«” Ralph Mode for Deep Agents š«” What if you could give an AI agent a task and just let it run forever? We built Ralph Mode to test this, built on Deep Agents. Ralph Mode loops an agent with fresh context each iteration, using the filesystem as memory. Just start it, walk away, and Ctrl+C when you're satisfied (or set some limits beforehand). In this video, we go over how to run Ralph Mode with Deep Agents to build an entire Python course autonomously. --- š Repo: https://github.com/langchain-ai/deepagents/tree/master/examples/ralph_mode