transcribe

Simple Pi Subagents

Eero Alvar · 13m · transcribed May 2026
More from Eero Alvar Business
𝕏 Share ▶ YouTube 📥 PDF 🤖 .md

Transcript

0:00 What is the obvious way to make your already overpowered pie agents even more overpowered? Well, you give it its own pie agents. All right, so two parts to the video. First, some theory or sub-agents philosophy motivating all the design choices, and then a practical demo. All right, so the problems we're trying to solve have to do with the task complexity. We want to be able to execute increasingly more complex, long-running tasks. And the underlying problem prohibiting us is context bloat.

0:32 Agent reads a million files during planning, and the context window goes into the dumb zone well before the agent can even begin execution. Most, or at least a very significant portion of file reading, is exploration, trying to find where things are, how pieces are connected, and so on. The full files that the agent reads during exploration, some with hundreds of lines of code, don't need to be there in the context window. The same applies to doing research on the web or any other task that requires ingesting a ton of tokens.

1:10 So, the idea, give your agent its own agent that it can prompt to outsource this kind of work. And bonus, this is mostly very mechanical work we're outsourcing. So, the agent we outsource it to doesn't need to be that smart. So, we can save money by using a cheaper model. That's That's good. And now, as a result, the master agent has only the relevant bits in its context window that it actually needs. Leaner context window, happier and smarter agent. Okay, here's another angle. Think about how useful of a tool coding agents are to humans. So, why wouldn't the same hold for coding agents themselves? It makes sense to give your coding agent its own coding agents. Now, onto the actual extension, sub-agents. The extension adds a new tool that allows Py to spawn sub-agents. This is a very minimal, bare-bones sub-agents implementation.

2:11 Nothing fancy here. I had three values in mind when building this. First, capability. You can make the sub-agents as capable as you need them to be. Observability. I wanted to have full knowledge of everything going on at all times because it can get kind of messy and confusing when your sub-agents are spawning their own sub-agents. I need to be able to observe their exact behavior, see what they're doing. This is important for two reasons. First, for improving the agents themselves. So, seeing where they go wrong so you can improve their prompts and functionality later on. And secondly, it gives a feeling of control.

2:56 Extensibility. Two layers to this. First, extensibility of the sub-agent loadout. It should be trivial to add and modify agents. So, each agent is entirely determined by a markdown file. Define name, description, tools, available sub-agents, model, and thinking level in the front matter, and then write the system prompt for the agent, and it gets automatically discovered by the extension. Secondly, extensibility of the extension itself. I went with a very minimal approach. Uh, no need to over-engineer this. Calling the sub-agents tool just creates an isolated Py process and then returns whatever the final text output is. And this allows you to very easily edit the extension. It's very simple. Makes it easy to try out different ideas and see what works. The extension ships with three agents. Scout, explore file system tools, read, grep, find, and ls. And since it physically cannot do anything, I feel safe using Haiku as the model researcher for doing research on the web. Tools, web search, and web fetch.

4:09 This one needs a bit more brain power, so it uses Sonnet. And then finally, worker. This one has basically the same capabilities as the master agent. It can do anything it wants. Though I have replaced the regular bash tool with a slightly safer version to block it from deleting my entire computer. But yeah, this means that the worker also has its own sub-agents tool, and it can spawn its own Pi agents. So theoretically, you could have an infinite chain of Pi agents. The extension allows you to do that. But in practice, that's not really ideal. So I've got an extra field for this. If an agent has the sub-agent tool, you also define which agents it can spawn. So for the worker, I've made it so that it can only spawn scouts and researchers. So this means that in practice, the effective maximum session depth is three for this setup. Three layers of Pi. Now let's see it in action.

5:12 Let's launch Pi. There we go. And we got the sub-agents extension on. And as you can see, the agents are just markdown files, like this. So here's the markdown for the scouts. Let's do demo. Try out the scout sub-agents. Okay. And it's going to show the live pros thinking in real time right here. Very useful and compact tool calls. One tool per line, unless you do control O, which expands the tool calls out. But yeah, as you can see, it's got the same footer as the main Pi window with all the token metrics, the cache read and the cache writes, the total cost of the session, and then the context window meter. So, 50k tokens used with Haiku, that's 15 cents. Very useful. Look at all the files it read.

6:10 And then control all to expand. So, we we can view the actual sub-agent output. Now, let's test out the researcher sub-agent. See what the latest AI news are and find something about Pi, something recent. I don't know. Let's see what it finds. So, this is for a web search, doing research on the web. Very useful. And it is also requires fetching a lot of pages, which eats a lot of context.

6:41 Okay, it's doing web search first, and this is actually the researcher sub-agent needs the custom web tools, these ones, which I have in my Pi config. But if you got your own tools, then it's very easy to just swap them in right here for the tools. Okay, it returned a lot of stuff. It used 70k tokens, and we kept our main agent very lean. So, yeah, that's that's the researcher. Now, let's try the worker.

7:13 This one's got a ton of tools, plus it can spawn its own sub-agents. Also, what what's this? Let's build a simple web UI for a Python app that takes in an audio file and cuts out the silences and returns a uh directly importable FCPXML file. Use FastAPI and Uvicorn and build a simple React uh UI. Copy the Python code directly into this directory. It can be found here.

7:48 And then we have the transcript. Very handy. I'll do a separate video on this. It'll need a bit more development. Just give it the path and let it go. Also, I forgot to mention, use Once you have a plan ready, use worker sub-agents. Cut the planning to phases and delegate each phase to a worker sub-agents to actually build it out. Don't write the code yourself. Delegate everything to workers.

8:19 They'll have their own scouts to scout out the uh code base. Yeah. Any questions? Usually ask user questions. So, uh go ahead. Okay. Almost forgot we're demoing the worker sub-agents. All right. It's got a plan ready. Now, it's going to delegate each phase to the worker sub-agents. Okay, it's dispatching another worker in parallel. Very efficient. Yeah, it ported everything over. All right, verified the build. Actually, now we're seeing a worker This worker spawned a scout agent. So, this is what it looks like.

8:56 Inside the worker, we're indenting all the sub-sub agents. Now, we have a scout working inside the worker tool call and it's got its own status bar with the exact same format. Now, the scout returns something to the worker. The worker reads it and starts the implementation. The agents can prompt agents very well. Opus gave it exact instructions on how to verify everything.

9:30 All right. The worker caught a bug and fixed it. Okay, let's see what they produced. We got the UI. Now, let's see if it works. Okay, I'm going to give it the audio from the beginning of this video. Yeah, let's go. And we got all the parameters as well. That's very good. All right, we got our output. Download it. Import the file. Yes, it works. And I've got a cut-up audio timeline here. Makes editing easy. Anyway, so that's so that's that.

10:01 It was supposed to be about the sub-agent, but either way, okay, this task could have been done with a single agent session. Not that complex, but just as a demo. Now, for the final test, I want to I want to see how far this can go. Uh spawning sub-agents inside of sub-agents. So, what we'll do is we'll give the worker sub-agent its own worker sub-agent. And this is done just by including it in the sub-agent agents front matter field.

10:37 And just in case, we'll also specify in the worker's system prompt that it can spawn workers as well. Workers, same agent as you. Same tools, same capabilities. Now, we'll reload the extensions and try it out. Let's see what happens. All right, let's stress test the sub-agents extension. So, what I want you to do is I want to I want you to spawn a worker sub-agent and task it to spawn its own worker sub-agent. And so on. Let's do this until we have, let's say, six worker sub-agents running inside of each other. Make sure nothing destructive happens. They should not really be doing all that much. Yeah, Uh that's it.

11:35 Send the prompt. Okay, I've actually not done this before, so I'm very very interested to see what happens. It spawned the first worker and the worker is spawning its own worker. Perfect. Level two reporting in. All right. And that worker spawns its own worker and they're going to get nicely nested like this and we're going to be able to see every sub sub sub agent layers tool calls exactly. Yes, we're at level four now.

12:07 Level five spawned. Level five reporting in. Yes. And we're at the final level. And now they're going to start resolving the tool calls. It worked. So there's theoretically no cap to the sub agents depth. I feel like this is the right level of observability. You don't need to see everything, just the tool calls and the pros thinking going on. But yeah, very easy to modify the behavior of agents.

12:39 Just a markdown file, define tools, sub agents, model and so on. Now, there are a few issues with this implementation. One of them being that the sub agents are not interactive. You can't interfere with the session because it would be very helpful for the sub agents to have their own ask user question tool. So interactivity would be a really good feature and that's what I'm going to be focusing on next. All right, finally, I want to show you a very cool implementation of sub agents. This guy's take on interactive sub agents which I found really cool.

13:21 So sub agents spawn as new panels in a terminal multiplexer. Uh yeah, entirely interactive, which is very cool. Though, I don't want to use Cmux, but this is a really cool implementation. Yeah. >> [sighs] >> Uh many ways to do things.

Summary

The video discusses enhancing the capabilities of pie agents by introducing sub-agents, which allow for more efficient handling of complex tasks by outsourcing mechanical work. This approach mitigates context bloat and improves the master agent's performance by keeping its context window lean.

- Sub-agents are designed to handle exploratory and mechanical tasks, reducing the load on the main agent.
- The implementation allows for a hierarchy of agents, where sub-agents can spawn their own sub-agents, theoretically creating infinite layers.
- Key values in the design include capability, observability, and extensibility, allowing users to easily modify agent behaviors through markdown files.
- The extension ships with three types of sub-agents: Scout (file exploration), Researcher (web research), and Worker (general tasks).
- The system maintains control and visibility over sub-agent actions, aiding in debugging and improvement.
- A practical demo showcases the efficiency of delegating tasks to sub-agents, including a stress test with multiple nested workers.
- Future improvements are planned to enhance interactivity within sub-agents, allowing for real-time user engagement during sessions.
© transcribe · For agents Built with care and craft by Gokul Rajaram