AIAI EngineerMay 14, 2026· 1:04:27

Make your own event-sourced agent harness using stream processors — Jonas Templestein, Iterate

Jonas Templestein and Misha from Iterate introduce an event-sourced agent harness built on stream processors, arguing that agents should be modeled as an append-only event log with a synchronous reducer for state and an after-append hook for side effects. They demonstrate how every action—streaming chunks, tool calls, errors—becomes an event, enabling full debuggability and replay without re-running LLM calls. The key innovation is a "dynamic worker configured" event whose payload is a JavaScript processor; appending it to any stream instantly turns that stream into an AI agent with no server or dependencies. This allows processors from different authors and languages to compose on the same stream, and a safety checker can inject context within 200ms without blocking the agent. The hosts emphasize eventual consistency over before-hooks, and show deployment via Cloudflare Workers or by simply subscribing from any HTTP client.

  1. 0:00Intro
  2. 1:33Architecture Vision
  3. 5:40Stream Demo
  4. 11:57Stream Management
  5. 15:17Q&A
  6. 19:17TypeScript SDK
  7. 30:06Processor Design
  8. 47:34Dynamic Deployment
  9. 58:45Before Hooks
  10. 1:02:16Wrap Up

Powered by PodHood

Transcript

Intro0:00

Jonas Templestein0:15

Welcome to the workshop. I am Jonas, and this is Misha. We both work at Iterate.

Misha0:20

Hi.

Jonas Templestein0:21

And the, um, this is going to be chaos. I think pure chaos. First of all, because we only, we only decided last Monday to do this, and then there was, like, a bunch of personal stuff and half-term and the kids were sick.

And then this morning we came here, and I thought this was going to be like a, like an hour-and-20 hackathon or something like that. And then we came here and we're told, "You're going to do it without an audience," because of some fire thing.

And now there is an audience again, which is amazing. So we're going to do, uh, try and do this as like an improvised hackathon, but I've only just pushed the SDK literally one minute ago, and Misha is going to try and sort of like live-fix it.

But I hope it'll still be worth your time, because I think there's sort of some, hopefully at least some interesting ideas. Or maybe, like, one way to put it is, I would like to find out whether this is like dumb or cool.

And the, um, and you can help me with that. So please also just, like, ask clarifying questions, because part of this, the reason we said last week, "Okay, let's do this workshop," is because these have been ideas that have been kind of noodling around over the last year, but we haven't really actually done anything with.

It's not really like a commercial value to it necessarily, but I think, um, it's basically how I would like to build agent harnesses. So, you know, I've been noodling with this for a while now, and, you know, obviously you've got like Claude and you've got Pi now, but back in the day you didn't, and so you make your own coding harness.

Architecture Vision1:33

Jonas Templestein1:43

And there's all these different ways to do it. And I think, um, the way I would like to do it is I would like to do it purely event-sourced. And I say here, AKA debuggable, and that is because everything kind of skirts around of being event-sourced, like all these things, without quite being event-sourced.

There's always something that has a side effect that you later can't tell, and then you can only see it in the OTel traces or something, which doesn't really make sense to me, because normally these agents, the way they work, and we'll see that in a second, is they already have a log of events,right?

So if you just say, "Everything that could possibly happen is in there," it'll be really easy to debug. And as we'll see, hopefully, a little bit strange, but potentially in other ways also really easy to extend. And then the second thing is I want, I want this to be extensible.

And we've seen this, I think, with Pi, which is, which is incredible. How valuable it is to make an agent extensible, not just by humans, but also extensible by itself. And, um, one thing that I want in the extensibility is, is I want it to be composable.

Like, I don't think we'll get there within one hour with all of you, but maybe afterwards, if you say, "Oh, this is actually cool and not dumb," we'll keep working on this. And you can say, "Oh, I made this extension, you made that extension," and you can combine them.

And, um, because I think we don't really yet know what is the best recipe for, for agents, basically, for agent harnesses. And it's been too hard to experiment. Even in Pi, like, everything has to run in a single thread, in, in, in like one process over here on this particular computer, and so on and so forth.

So I think, I think we can maybe do a little bit better than that. Then I think it should be on the edge, publicly routable. Like, the way I think of it is basically an intelligent entity, like a digital one, that's not a robot in the future.

It's just internet-connected, basically server program,right? Like, it just speaks HTTP. So the slides, broadly speaking, that should be sufficient for almost anything. And then I would just put these agents on the edge, speaking to the internet straight away.

This is not very safe. None of what we're doing today is safe, by the way. There's no authentication you'll see. You'll all be able to see everybody else's event streams and agents and whatever else. You should not put any secrets in the actual payloads of the events or rotate them afterwards,right?

So we can, um, you know, those things can be solved. But broadly speaking, the moment an agent exists, it should have a URL. That's just like, that's just my opinion. Because otherwise, like, you end up making all these things and then you tie yourself backwards, inventing a connector concept just so you can get Slack messages in or God knows what.

And I think that should be really easy. Or like maybe, like, a human should fill in a web form and the result of the web form should be input for the agent again, or something like that. That's kind of like the same thing as a Slack web hook.

And then it should be distributed. And this is potentially like a very double-edged sword, as we'll see, like,right? But by distributed, I mean, you should be able to have an agent running sort of on one computer here on a server and my plugin running over here and your plugin running over there and yours is written in Rust and mine is written in TypeScript, and it all just doesn't really matter.

And the reason that is bad is because you will eventually get race conditions and loops,right? Like sort of like two plugins kind of sending messages back and forth, creating like an endless stream of events in your agent. But on the flip side, you have those issues normally anyway in most agent harnesses I've seen.

So it's quite good if you can kind of preempt that a little bit. Okay. So let's, um, let's talk about this thing that we have invented for, um, oh my gosh. Um, what is this? This isn't the same as in my file system, so I'll use the one in my file system.

Basically, we have created this service over last week called events.iterate.com. It has a web UI, and we can, um, you can use that. I think you'll certainly use it, but for now we'll just play with it with curl, because I think it makes it, in some sense, more tractable.

In the agents, in the events app, we have this concept of agent paths. So just like a file in a file system, every agent has a path. That's a hierarchy. And you just have, here, you can show this here.

Stream Demo5:40

Jonas Templestein5:52

You just have raw events. This is YAML-formatted raw events in each of these paths. And that is basically the entire, the entire primitive that we're going to be building our agent on. And so we can start by playing with this.

We can say, "Okay, we have a path prefix. If you copy this from the repo that Misha is going to put it in the README in a second."

Misha6:11

I'll add workshop.md as well.

Jonas Templestein6:13

Yeah. Yeah, okay. Oh yeah, maybe that's why.

Misha6:16

I added the README, but not the workshop.

Jonas Templestein6:18

Yeah. So basically, let's set ourselves a path prefix here. In my case, that is just going to be Jonas Templestein or something. They start with forward slash, by the way, which is a little bit awkward, potentially, but the service is very tolerant of URL encoding your slashes or doing whatever you want.

But I wanted good curl economics, but I also wanted them to start with a forward slash. So you have like a well-defined route. Then for the base here.

Misha6:45

It is now pushed to the repo, but have you shared the repo?

Jonas Templestein6:48

Oh yeah, because now you could actually do this on your computer. Let's do that, actually. If you go to github.com/iterate, there is an ai-engineer-workshop.

And in there, you should be able to, if you click on this workshop.md file, that's what we're now going through. So you should be able to copy and paste the curls from there. And again, there's no authentication, so you can just do this.

In fact, why don't a couple.

Misha7:17

This is hitting our live deploy.

Jonas Templestein7:18

Yeah, yeah, yeah.

Misha7:19

events.iterate.com, so.

Jonas Templestein7:22

Like, this is entirely just sort of like a proof of concept of how I think this should work. Basically, what we're going to do is we're going to turn this simple event stream into a fully-fledged agent without, like, really deploying any server software or anything like that.

Maybe. Yeah, I should be able to see if anybody, if anybody has managed to do it. I'll wait until two or three people have managed to successfully curl something, and then I'll carry on, because I think it'll be good if you curl it yourself.

So it's here in this ai-engineer-workshop, workshop.md.

Misha7:59

If two people have the same name, that's going to cause problems.

Jonas Templestein8:03

Same username. It doesn't matter.

That's fine.

Okay, there we go. Got a few people. Okay, so this is pretty good. By the way, you might see this here and there. There's also this thing down here called project slug. If you really start stepping on each other's toes, you can just type whatever, like, use a different project slug, and it's like a completely new database, a new namespace.

You can pass that in as an HTTP header. If anybody needs that later, you can ask me. Okay, so now we have a few people curling things. I will also start curling things. So now I'm just going to say, "Hello, world," here to my stream.

And it'll come back. And we straight away, we notice like a few things. There's a basic event envelope shape. We have a type that I've just invented here. Events don't need to have anything but a type, but most of them also have a payload.

Then there is the stream path, which came from the URL that we posted this to. And there's an offset. This is just an auto-incrementing integer that starts at one. And so there's basically like a point of serialization at the server that just increments them.

And you get a created at. And then here, what we can do with curl, which is quite nice, if you do -n, you can do streaming, streaming SSE. So this here is literally nothing magical. This is literally just, you know, slash Jonas Templestein, slash hello, world.

This is literally the curl that we're doingright here.

And, um, oop. There I can see the messages coming through. Very nice. And I can, I can add another message. And now, basically, all the messages will show up there. And there's also a, um, oh, if you do question mark live equals true, this is inspired by the durable stream standard, but like ever so slightly different.

But if you do live equals true, the connection will stay open, and it'll just keep sending you more events as you, as you put them through. So this is sort of already, you know, like, you could say this is an AI agent if Misha was simultaneously giving responses to my hello, world.

This would already be an agent. And then there is, my AI has told me you can, if you're going to be doing that a lot, you can pipe this through set, get just the data elements, and then pipe it through jq.dot, and then you get a little bit nicer formatting.

So this is sort of like, this is so trivial that I actually do spend a lot of time in curl, just curling it. Then what can you do? The thing is very tolerant, just in general, of stuff you post to it.

And this will become relevant if you wanted to, say, send webhooks from random third parties there. Like, my theory is always that, like, the LLMs are good enough. They can basically just consume raw webhooks from anywhere, and they'll roughly do theright thing.

So what specifically the server will do is, if you send it something that doesn't validate, like hogwash here, it says there's no type property, so there's not actually a valid event. Then you can see here what it has appended is basically an error.

But because we're event-sourcing, the error is also just an event. And it just says here, "Okay, you have an invalid event appended," event. Oh, another thing that we will notice is that the type here that our server has created, it starts with https://events.iterate.com.

You don't have to do that, but that is something that we like to do because that literally leads to the documentation for that event type. And if it's going to be an opaque string, like, why not make it something like that?

But obviously, you can just do, you know, single words or two words or whatever. But you will see these URLs, and they're just, they're just types. Then what else is interesting that we can do? I mean, this is kind of boring, but, you know, again, if you're going to do webhooks, you kind of put an idempotency key in, which just means if you have the same idempotency key twice, you don't get, you don't get the event appended twice.

You can pause a stream. I think in the interest of time, we can skip that. You can resume a stream. The reason the pausing is important, and we put this in, even though we literally just made this a couple days ago, is because of the infinite loops.

Stream Management11:57

Jonas Templestein12:07

Like, it's very, very easy to accidentally put, like, you know, thousands and thousands of events in an infinite loop in the thing. And so if you put more than 100 events in a second or something, it is just going to circuit break, and then the stream will be paused until somebody unpauses it.

So basically, if you try to, actually, let's do that. Because again, like, for those of you who haven't seen event-sourcing, this might be a bit weird. Like, how do you pause a stream? Well, you pause a stream by, oops, this is the wrong one.

You pause a stream by appending an event that says you're paused. The only external interface to the agent is, oh, um, now it's complaining. Why is it complaining? Ah, because I think there needs to be a reason or something, maybe.

Yeah.

Reason demo. Yeah, there you go. So now this thing is paused. So now if I, you know, try to send it the hello, world event from earlier, it's just going to barf and it's say, "No, no more events allowed."

And that is one, like, that is one thing that doesn't appear as an error in the stream, because otherwise you would still get infinite numbers of error events.

Then, I mean, there's other weird and wonderful things you can do. I don't even know if we really have to do this, but there's like, I have made a plugin for this already that makes it so that if I put this Jasonata transformer configured event in, what it'll do is it'll just observe certain events, rewrite them a little bit, and make a new event out of it.

But I think that's a bit advanced, so we'll do it later. It can also do weird things, like it can, you can schedule, you can schedule things. Like some agent SDKs, you'll know, can do this. But here, you know, if you want like a heartbeat event every five seconds.

Oh, oh God. Now I need to resume the stream because it's paused. Let's see. Stream resumed.

Okay. So now I am just creating this heartbeat event every five seconds, which can be quite handy. Or you can schedule something for 10 minutes in the future or at a certain time. And again, it's just an event that says, "Do this thing in the future."

I think I will skip over these, but you can cancel the schedule. You can tell the stream by appending an event to send your server or some third-party server or your, you know, your Slack API endpoint or whatever, an event every time an event gets added.

So you can basically subscribe to the stream. Here we're subscribing in our terminal. We're doing a pull subscription,right? We're doing, we're connecting to an HTTP server, and we're getting, we're pulling, pulling with the HTTP client, and they're the HTTP server, and we're getting an SSE response stream of streaming events.

But it can also do the other way around, where it will push you the stuff that gets appended or push you a filtered stream,

which can be quite handy. Okay. So let's maybe stop there, because I know also it wasn't really clear from the session description how deeply technical this was. And so let's take any questions on what is even this thing that we're going to be using for the next 45.

Q&A15:17

Misha15:31

But questions have to be submitted as an event to the question stream.

Jonas Templestein15:36

Yeah, exactly.

Misha15:37

You have any trouble using it?

Jonas Templestein15:38

Well, that can be the queue.

Does, I assume lots of things don't make sense, so please do ask them, because I think this will be extremely, like, random and strange so far.

Guest15:55

What does Iterate do for your company?

Jonas Templestein15:58

Oh, we're like, we're like a hacker hobby club at this point, to be quite honest. Like, we are, we have not got a launch product.

But if we did, it would be, I think, based on this architecture. It's like, anyway, I can talk about it afterwards.

Guest16:16

Okay, okay, okay.

Jonas Templestein16:17

But it's, yeah. It's more, it's more homebrew hacker club than, like, commercial enterprise at the minute. But it'll get there.

Yeah.

Guest16:28

I have a question. So I know that we'll be building event-based agents.

Jonas Templestein16:34

Yeah.

Guest16:35

Can you, like, maybe that's a basic question, but, like, agents that are on the marketright now, aren't they event-based? What's the, like, different architecture?

Jonas Templestein16:45

It's just, I think it's just the API. Like, if you, have you tried to make, you know, like an open code extension or plugin or a Py extension or a Claude extension? And they all have, like, an API surface that is a little bit bigger than what you would have or what we're going to have in a minute.

It's not like by much,right? But, like, okay, like, maybe the streaming chunks for partial completions are a different kind of thing for some reason, rather than just an event of type. I've received, you know, like five letters of a streaming response.

To me, that's a perfectly valid event. And the benefit then is that you can, that you, I'm kind of like a one abstraction kind of guy,right? Like, this should be like a, like web standards based. This should be, there should only be one thing, which is an event.

And then, as you'll see, like the thing that was at the top of this file, I think you can build a super expressive state-of-the-art coding agent by just implementing, like, a stream processor that reduces over the event stream and occasionally an X side effects.

That's all it does,right? Like, it just sort of sits there and says, "Okay." I'll show you that in a second. Like, it's a bit weird, I would say, a weird way of programming.

Guest17:57

So if I understand correctly, you're sort of saying you take events that you get generated from an AI model, and then you're basically going to pipe them through this stream processor. Is that the idea?

Jonas Templestein18:08

The stream processor is, or like the events that iterate to app is the storage. Like, you can almost think of it as a database. Like one, you know, do you know Convex is like a sort of, you know, they kind of give you the illusion that they're running TypeScript in the database?

You could almost think of this, this could be like a programmable stream or something,right? Because actually one thing that you can also do, we'll see later, once you hack on your stream processors, you can also make an event that contains the source code of your stream processor, and then it'll just run on every event.

And so, like, it's basically, it is like, it is like the, I think you can experiment with a huge array of different kinds of agent harness implementations that can respond to real events on the internet and make real API requests without deploying your service or something like that.

All you need is this sort of streaming, streaming service that has some of these things. Like, specifically, it needs to be able to wake up, you know, like other APIs and programs and so on. I don't know if that, yeah.

Does that answer your question at all, or?

Guest19:13

Yeah, I think so, yeah.

Jonas Templestein19:14

Okay. So we try and make now a, like, a slightly more serious version of these curls. So does anybody here not know TypeScript? I think, so I think the, like, one of the arguments in favor of this architecture that I also put in that, in that, in the blurb, I think, is this is in principle polyglot,right?

TypeScript SDK19:17

Jonas Templestein19:37

And there is a, like, in any language, there is actually at events.iterate.com/api/docs, you have just, I mean, this is an exceedingly simple API,right? You can make yourself, there's an open API spec, you can make yourself a client and so on.

But for the purpose of this, this workshop here, we'll just do a TypeScript version, and we've shipped a client in an NPM package already. But I just wanted to point out, like, even though we're doing everything in TypeScript, the whole point is that we wouldn't have to,right?

But we just have to do one thing for this workshop. Okay. So let's, let's do something pretty simple.

Is the AI engineer workshop package now up to date and working? I think it is,right?

Misha20:24

I think so, yeah. You might need to pull your repo because there was a client-side type error.

Jonas Templestein20:29

In the Iterate repo?

Misha20:31

No, in the AI engineer workshop.

Jonas Templestein20:33

Okay, that's fine.

Misha20:34

It's in example.ts.

Jonas Templestein20:36

Yeah, but I'm, oh, maybe I will actually use that. Then I'll be able to experience the same, the same bugs if there are any. Yeah, that's probably better. Okay. Okay. So I think if you wanted to just have a quick start, you can, you can just pull, clone the AI engineer workshop repo.

There is already a teeny tiny example file in there, and then we'll just add a couple more as we go along.

Misha21:02

And the workshop.md has runable curl as well.

Jonas Templestein21:05

Nice, yeah.

Misha21:07

That does work.

Jonas Templestein21:09

If you wanted, you could put a couple, like a couple of the follow-on examples that are in the Iterate repo that have actual processors.

Misha21:18

Yeah. I can take a look.

Jonas Templestein21:27

I don't know what's going on here.

Ah.

There we go.

Hmm. My computer seems to have slowed to a crawl trying to open a cursor window. This has been unfortunately, like, a somewhat regular occurrence recently.

Ah, okay.

Okay.

Or, oh no, I think this might be what you mentioned about the internet. I think it's just struggling because it can't open a terminal because

my terminal tries to connect with the internet.

Misha22:22

It does.

Jonas Templestein22:29

Oh well. Then let's do this.

That's not the internet. Where is it? There we go. Okay.

Okay. So we have here,

we have packaged up an SDK here to this AI engineer workshop package that you should be able to just PMPM install or you just use this example here. And then basically, what did we need in our curl,right? Like we needed a base URL, which is just events.iterate.com.

That's where our server is. We can use a path prefix. And then we can run this function here called create events client that is from our SDK. And then this is under the hood. This is, oh,

I really don't know what's going on with this terminal. It's very strange.

Hmm. Okay, maybe everything is just incredibly slow.

Misha23:54

Do you want to try mine?

Jonas Templestein23:56

Mine is, okay. Maybe, but there's nothing actually hogging the CPU. I do think it might be actually the network, but we'll see.

So here.

So here you have,

I don't think this has picked up the, anyway. Okay, so this is basically what we were doing just now,right? Like we say, okay, we're making ourself a client. And then here there is a function called stream. This is basically theright-hand side of the terminal that we had earlier.

And then you say live true and give them the stream path. And we can say, okay, if the event is not of type ping, we will do nothing. But if the event is of type ping, then we will, I mean, this is a completely unnecessary helper down there.

Then we can just do client.append. I don't understand why

the TypeScript language server isn't picking up any of the types for me, but I can't tell if that's just the cursor being weird again.

Misha24:57

Your own example, that means.

Jonas Templestein24:58

Yeah. Anyway.

Misha25:04

It quickly switched IDs.

Jonas Templestein25:06

No, it's fine.

Misha25:07

It is working for me.

Jonas Templestein25:08

Okay, yeah. I think this is unfortunately, like, a sort of cursor. Okay. And then you should be able to just, if you have a modern version of Node, you should be able to just run. Or maybe not. Did I make it?

It says invalid TypeScript syntax. You know what? I'm just going to, I'm just going to restart cursor. I think that is worth it.

Is anyone able to run this example.ts on their computer? There you go.

Misha25:44

I am.

Jonas Templestein25:45

Okay.

And are you able to send a ping to it and get a pong out of it? Okay, very cool.

Okay.

Yeah.

Yeah. I wonder if we use, I don't know if you can see this, but basically all my commands, they have like a several-second delay, which is.

Misha26:53

Yeah, it's looking okay to me. If you want to just swap laptops.

Jonas Templestein27:02

Hmm.

Maybe.

Guest27:13

I had to BMDM that package, the one that you imported.

Jonas Templestein27:17

Yeah, I know, I know, but it's just, yeah. It's just my editor doesn't work. And I also have several non-responsive cursors. So I feel like this is unfortunately a pattern with cursor recently.

Misha27:32

If you want to swap laptops, it does seem to be working okay on mine.

Jonas Templestein27:36

I would just give everybody 60 more seconds to just get the basic demo working and then.

Misha27:41

Just let me know.

Jonas Templestein27:42

Yeah, because I think using some, you know, this is still almost an hour to go. It's not good to use somebody else's computer.

Maybe I will continue on yours and I'll just restart my computer. I think that's a good idea because we can, yeah.

Misha28:30

I also have examples 0.1 and 0.2.

Jonas Templestein28:32

Oh, really? Oh, brilliant. I think working with some. What's your keyboard layout?

Misha28:37

Probably the same as yours.

Jonas Templestein28:40

One can hope. Okay. Entire screen.

Misha28:44

Looks there.

Jonas Templestein28:45

Looks pretty good so far.

What if you got a terminal? So

let's

see. Node examples 0.1, hello world.

Okay, perfect. Yeah. Well, this works flawlessly. So,

has everybody got that more or less working? Because then we can just make an OpenAI coding agent now. I think that's all we need.

Let's maybe, I'll ask, do you have a speech control in here?

Misha29:33

Yeah, it's control and option. It's kit's one.

Jonas Templestein29:37

Yeah. And then?

Misha29:39

That's it. It's recording.

Jonas Templestein29:41

Hello. Oh, cool.

Misha29:43

See that red bar?

Jonas Templestein29:46

Hey, I would like to make a third example called agent processor. And for that, we need to install just the normal OpenAI SDK. Please do that and just make me a new file that looks like the hello world processor.

Okay.

Okay, so

Processor Design30:06

Jonas Templestein30:11

I've just got to gather everybody again after I left you for about 10 minutes.

Here, this is a normal, pretty normal spaghetti code TypeScript program,right? Like basically what we've done here is we sort of like doing some boilerplate work. Here, if we want to subscribe, we have to make a subscription. Oh my gosh.

This example that you put in there has like a board signal and handles all kinds of things. And anyway, I think the way I think about what we're really doing is we're writing a stream processor. And if you've never done stream processing, this might be like a bit weird and people use slightly different names for these things.

But really, what we're saying is there exists some kind of world state that we're interested in that can be derived from the events. In this example here that Misha made, we are trying to count the number of times an hello world event has been encountered in the stream.

And then you can write the entire logic of your program as effectively a reduced function. This is synchronous and it just looks at all the new events as they come in and then it updates the state. That's all it does.

So it takes a state and event and it returns the new state. Or you can just also return nothing. It'll be fine. We'll just ignore it. And then you should not do side effects in this reduced function. And the reason I've split the reduced function from after append, where you should do your side effects, is because if you think about what happens if your program goes to sleep,right?

Like you're closing your laptop. At the moment, everything's running on our laptops. You know, 100 new events go into the stream. Some of these events might in the future need to trigger LLM requests or something like this. And then you open your computer again, you start your program again, and you don't want your program to go and make a ton of LLM requests for all of those 100 events in the past necessarily.

Instead, you want it to sort of like catch up all the way and then decide what to do with the state at the end. And so we've made this like super lightweight abstraction here of a processor that basically gets hooked up into a processor runtime.

And then what it does is it splits your work into reducing events into state. And then if you want to do some side effects, like for example, appending

to the same stream again, you can do this. By the way, I think you can also do this, which is like potentially, this is pretty interesting. Like, you know, you can literally just append to, you know, like a child path, or you can append to a parent path, or whatever else you want.

It's basically like meant to be like a file system. And so if you wanted to build sub-agents on this thing, all you would do is probably you would just append to ./boris and pretend to boris is a sub-agent.

And then you would just subscribe to some special events that boris might output, like I have the result. And then you would automatically be woken up again on the parent when boris has the result. Is this confirmed, Misha, that this runs?

Like, how do you run this? This just exports the, like, you need the runtime,right?

Misha33:23

Yes. There is a CLI command that I now can't remember because my agent has been running it, where you can, you should be able to do PMPMW and then pass the file, I think.

Jonas Templestein33:38

Did you do all that just now?

Misha33:39

I did that about a week ago, but you may have changed it.

Jonas Templestein33:41

No, no, no. Yeah, okay. So, okay. Okay.

Let's go to our repro. Like I promised, this is

a little bit, these are the, so you can actually also do this. If you go to iterate/iterate AI engineer workshop, here there are a bunch of examples of files that are.

Misha34:06

Oh, workshop two. I was going from workshop one.

Jonas Templestein34:08

Ah, yeah. I also.

Misha34:09

These are out of date ones.

Jonas Templestein34:10

That was meant to be renamed.

Ah, here. This is basically the snippet we want.

Misha34:20

Okay.

Jonas Templestein34:21

There is this thing that you can have. So here now we've just made a processor,right? Like this is just like a sort of inert thing. And then there's a thing called a pull subscriptions processor runtime. And all that does is it takes

your processor that you just made and it runs it.

Misha34:49

I think you probably need to assign it to a variable because you'll just export default above.

Jonas Templestein34:54

Yes.

Okay.

And here, let's just say,

just see if we can run this.

Guest35:28

Sorry, a question. Should we have access to these examples that you're showing?

Jonas Templestein35:33

Yes, but unfortunately they need to be modified in order to

do anything interesting.

Guest35:43

Because I don't see them on GitHub.

Misha35:45

Yes, those ones are

added in the last few minutes, but using.

Jonas Templestein35:52

Yeah, I give slightly bad copying instructions.

But I think.

Misha36:00

Those aren't committed yet.

Jonas Templestein36:01

Yeah.

I think that we're just going to have to sort of like slowly build it up in this repo and then push it once it works here, unfortunately. So here, basically what I've now done is I've taken this processor and I've hooked it up to this runtime.

And all the runtime does is it's just this like boilerplate for consuming the stream and running the reducer and running

the after append hook. And what we should see is once you submit hello world into this path here that is just jonas/example, you should get a response there. So if I go here in the UI and I go to jonas/example, and I think I said this should be event of type hello world.

Oh, no, this is up here.

If all works, this would be sort of like the proof point that lets us, it doesn't. Hello world scene.

Misha37:05

I don't remember if this example relies on the machine username, but if it does, then that would be mmcal, not jonas.

Jonas Templestein37:14

Maybe.

Let's just do this.

Ah, sorry. This is like the worst workshop example. Also on the wrong computer.

It does after append.

Hmm. Okay.

Is my computer back up?

Misha37:55

Yes, but I don't know your password.

Jonas Templestein37:57

Okay, yeah. I'll do that in a second. Okay.

This example here is not working. Okay, so I think we have to do plan B, but we might not actually be able to run this. Are you getting.

Misha38:11

Getting.

Jonas Templestein38:12

I'm just going to walk through the code as we would have written it from scratch. Sorry about that. Because I think it sort of like illustrates the progression of things. And maybe if you.

Misha38:23

It's installing dependencies, which is slow.

Jonas Templestein38:26

Yeah, but it's not exactly. Eventually this will.

Misha38:29

It will be runable by the walkthrough.

Jonas Templestein38:31

Exactly. So

in this paradigm, as we've been using it in our agent, when you want to implement some sort of feature, what you do is you say, okay, what is the state I actually need in order to do my thing?

In this case, we want to do an LLM request whenever somebody sends a message and says hi. So we have here in our user interface, and you can access this as well, there is basically like a cheat code that makes it a bit easier to create new events of a type called agent input added.

And this is like deliberately the simplest possible thing you can imagine. This is basically just a string. And so what we're trying to achieve is that whenever somebody puts an agent input added event into an event stream, we want to react to that by making an LLM request.

And for simplicity, we're just going to go in and do it using the OpenAI SDK. So the OpenAI SDK, the way it works is you have to, at some point before you want to use it, you have to make yourself

here a new OpenAI client. And then you can use their responses API. So you have OpenAI.responses, responses.create. And then in order to create it, you need some information. Specifically, you need a model string. And so immediately there I'd say, okay, so let's just say our state for our LLM agent, it has a model string.

Because that is one of the things that we will need when we come to actually make an LLM request and there is nothing but event sourcing. So let's just say, okay, we have a model string and that comes from our state.

And then, you know, you could easily imagine in the future this was one of the things that you could have done as an exercise in the hackathon is you could say, let's add an event that is like LLM changed, LLM model changed.

And then you have the teeny tiny one line reducer and it just sets the model to be a different model. And then off you go, you make the next LLM request with a different model. And the other thing we need is instructions.

This is, I think, a bit of a misnomer. So I would call it system prompt in our state. I would say, okay, like the system prompt for our LLM, what it's meant to be doing, we'll take that in our state.

And then you need a history, a state history.

And so we've defined this. And normally what you'll do is you'll just put this into like a little TypeScript type if you're using TypeScript. So here we're saying this is the state of our agent,right? And in the beginning, it's really simple, but in the future, you can very easily imagine how you quickly add things to it, like state, am I currently compacting, or is a tool call currently in progress, or whatever else you might have.

And the idea is to create a system in which it is trivially easy with three, four lines of code to add one of those capabilities to it. And then you say, okay, what's my initial state? Because we're processing the stream, initially there's no events, so we need to know what we're initially starting with.

And so we're just saying, this is, we're starting with an empty history and this system prompt and GPT 5.4.

And then the next thing you do once you've done that is you need to decide what events do I need to derive

this state? And in this case, we will just

create a new event here. We're using Zod here for schemas. We're saying it's an agent input added event and it just has a string.

And then whenever anything comes back from OpenAI, because that is like a fact that has occurred, even if it's just a teeny tiny fragment of a string or something else, we store that in an event. And that's it.

These are the two main event types. I don't think we need any of this stuff here, actually. Basically, what happened, as is often the case, I attempted to instruct an agent to rewrite all of these examples to be simpler to execute just before, and it just rewrote them quite significantly.

But this is really all you need. And then you have to write your reducer first. And the reducer is basically where you just say, okay, when an event is encountered, how do I update

my state? And you say, okay, when an agent input added event is encountered. This here is using a little like Zod helper library, actually one that Misha made called Schematch. It just gives you basically safety on this payload here.

When I have an agent input added event, then I want my state to be updated as the current state plus the history, except the history also gets this little thing here appended. And the reason we're doing that is because OpenAI's responses API, since we're making OpenAI processor, we're basically translating between our view of the world.

We just have this like agent input and it's just a string. But OpenAI wants you to put role user and then put the string in a content field. So we're putting that there.

And then the other thing we need to do, when you use the OpenAI streaming API, it'll basically chuck out tons and tons of these output response events. And one of them finally at the very end will be of type.

Guest44:04

Sure.

Jonas Templestein44:06

Yeah, I think this is a bit hogwash.

Guest44:08

It's like an end event at the end.

Jonas Templestein44:10

Huh?

Guest44:10

And it's done with.

Jonas Templestein44:11

Yeah, yeah, exactly. It basically, what we really want here is

yeah.

Misha44:28

We don't know about doing so.

Jonas Templestein44:29

Oh, thank you.

Misha44:33

Is that actuallyright?

Jonas Templestein44:38

No.

I don't suppose you have managed to get the.

Misha44:52

I have pushed workshop two to the demo repo, but it's more or less as is.

Guest44:58

I've got a question. Is it going to be streamed in?

Jonas Templestein45:01

Yes. Yeah. Okay, so let's just like sort of like admit defeat on the thing that I was going to do and just like try and show you how it would work. Because we can get something like very simple working,right?

Because we have the extremely simple ping pong processor that does work. And so here we can even just,

let's maybe actually start here.

Misha45:33

I might hit insufficient quote running my.

Jonas Templestein45:44

Hmm.

Misha45:48

Yeah, we do now have the same examples on the other repo, but it'll.

Jonas Templestein45:54

To be honest, I think we might have to just admit defeat and we can just talk about something else or give you the time back. Just because the problem is we can't actually run these things. And I think it will take me like probably like 10 minutes of actually concentrating to get them runable.

So maybe we should admit defeat on that. I do wonder if there's like,

yeah, does it sort of make sense what the idea is, especially with it being distributed? So the,right, that you can say, okay, like I have my processor over here and your agent can use it and it can be on a different server or it can actually be in a dynamic worker.

And

yeah,

I think without showing it, it doesn't really make sense.

Guest46:50

So is the idea you use, so with the stream processing, so you take this event stream from OpenAI and it contains events like output item added, or I know the Anthropic model better than anybody, but you've got.

Jonas Templestein47:03

It's very similar.

Guest47:04

And then you've got some series of like text deltas, say.

Jonas Templestein47:06

Yeah.

Guest47:07

And so the reducer here is kind of squashing all of those attendance and then materializing that sort of partial response into an event,right? So then the bit I was trying to understand was sort of with this stream processor sort of framework that you've built is like these materialized events, are those consistent as new messages on the stream?

Do clients consume the raw appends and sort of you're doing the materialization client side or is it sort of a part of something that's happening in the.

Dynamic Deployment47:34

Jonas Templestein47:35

So everything that happens in the system, every streaming chunk, everything becomes an event in the stream. And then you have reducers running in many different places. Like for instance, you know, even this thing with like is the stream paused or is the stream not paused, the actual implementation of that is maybe that's actually useful because this is running in production now.

Like there is a circuit breaker processor and this is like how the whole thing is built even inside the event service. And the circuit breaker processor has an initial state of paused, false, and it has pause reason null.

And basically then it has a really, really simple reducer that just checks what are the last 100 timestamps of events I've seen. If the last 100 timestamps I've seen don't go more than a second back, then I'm just going to append an event.

So the reducer basically just accumulates these timestamps and then the after append function here says, okay, if I have seen too many timestamps in the last second, I'm going to throw the circuit breaker. So this is like a real processor that runs inside my service.

But let me show you another one. This one here, this UI, this is also a stream processor. What does this UI do? The UI takes all of these events and for some of the events that it deems like interesting, it basically projects them onto what we call feed items.

So these things here that have like a slightly nicer rendering, they are feed items and they are not the same as events, but they're derived from events. So when you're making UI for this thing, you're also just reducing.

And because the reducer is just a synchronous function,right? If you knew, for example, I have this like a Pi agent harness processor and it comes with a whole bunch of event types and it has a reducer, you can just in your processor use their reducer.

It's practically free,right? Like you can just import it and run it. And then you can just sort of like start building abstractions that rely on their event types. And so I think what I will commit to doing, because this was such a shitty experience, is I will just do the whole rundown in video form on the internet.

And that was one of the things I was going to show. Like you can just hook up Pi or Claude or OpenCode as well and just say, okay, like they come with a bunch of events and you can store them in this event stream and you can react to them or build on them.

Does that answer the question like where the reducer runs? And then like one of the things you can do with this is you can also actually just append an event that has some source code in it and then it runs that particular processor literally automatically for you, horizontally scalable.

Misha50:18

It's just, yeah. Do you have the example of showing how you do that where you're appending like a function?

Jonas Templestein50:25

Yeah, I do have that.

Misha50:25

Even if it's not runable, I think the.

Jonas Templestein50:27

I do have that.

Misha50:28

Is somewhat.

Jonas Templestein50:28

Yeah, well, actually we can do it here. Yeah, I think maybe that is good. Just like focus, instead of trying to write code, we can focus on the things that might work. So we can create a new stream.

By the way, all streams are created, you know, completely implicitly. So you can just post to anything under the streams API and it'll make you a new stream. And then here there's in the UI, and you can also play with this if you want to just see, there's a bunch of sort of preset events.

And one of them is here. You can append an event of type dynamic worker configured to this thing. And what does it have? It just has a script in it. And the script is a string. And inside the string is a reducer and an after append hook.

And so this is literally like a stream processor. It would be funny if this is the thing that works because I was basically up most of the night working on this because this is the most exciting bit, but it wasn't really like workshop grade because it was, you know, you get like the first five concepts and then you're like, by the way, you can deploy this by just adding an event.

But if I just say ping here, it says pong,right? That's pretty crazy. Like I have here a stream that knows nothing about the world. And then I have appended this event here that just has a little bit of JavaScript in it.

And this little bit of JavaScript just makes it respond with pong whenever it encounters something with ping. And then there is actually a version of this. This is the thing that actually took the night away, so to speak, is if you have these processor files that export a processor that you define with define processor, you can bundle that into an event effectively.

And this AI agent, I also got running like that. But of course, you don't want to have your OpenAI API key in there. So that is why we have this like slightly awkward env vars here where you can put your OpenAI API key outside of the stream.

And then it will basically, when it makes a fetch request, it'll substitute the secret in the header. But

yeah, I'll definitely post a video of that because that's pretty wild. Like you can write like the 40 lines of code required for a basic AI agent and then you can append that to any stream and then that stream becomes an AI agent.

I don't know. I'm sort of looking at like two or three nods, but mostly blank stares. It is very strange. But does this make sense what happened here at least? Because this one you can just play with. Like you can just go in the UI.

And so to some extent, actually, you can make increasingly more complicated processors for your streams. You can just code them in this input field if you want. Or, you know, the only problem is it cannot have any dependencies.

Like if you want to NPM packages, you have to bundle it into this string, which gets a bit more complicated. But

yeah.

Guest53:25

Can you open ROC?

Jonas Templestein53:26

Yeah, so this is the other thing. Like everything you might have noticed is everything has a slug. It's just like a URL safe identifier. And so the event here is actually called dynamic worker configured because you can override it.

And what also already works with this event type is you can give instructions to an AI agent to make itself different functionality just by calling append with like a little bit of a different JavaScript. And, you know, you can quite easily imagine overcoming the bundling problem, for example, by just saying, oh, there's another event type, which is called like a sort of like unbundled dynamic worker, which just has a package.json file, a field, and a script field.

And then a different processor takes it, bundles it, makes the fat event that has all of the bundled source code, and suddenly it's basically like an IDE. And that's then where you can hack on the agent harness without having to really like install anything or like bring servers into the mix or whatever.

But sadly, I was not able to show it, so bummer.

Guest54:32

What if there is a header in the JavaScript code you push to the stream?

Jonas Templestein54:38

Hmm?

Guest54:39

So if you push the JavaScript code in a stream and if there is an error in that code or if you made a typing error, what happens then?

Jonas Templestein54:50

Well, this is JavaScript. There wouldn't be a typing error. But if there's any kind of error, the only thing that can possibly happen is that you get an event. So there would have to be an error event.

Misha55:03

And there are no typing errors as implementedright now, but that's because this is a JavaScript evaluator. But you could also find a way to run a TypeScript compilation step on it first and then you could emit error saying there was a TypeScript compiler error.

Then you could run it through an LLM to try and fix it and emit a new event with a fixed code or do something else with it.

Guest55:23

Yeah.

Misha55:24

The idea is that just everything that happens results in an event and then you can react to those events however you see fit.

Guest55:35

The events are then evaluated and run in your backend,right?

Jonas Templestein55:40

Yes. So in this particular case, it's dynamic workers in Cloudflare. So it just spins up a small dynamic worker. So basically, like the deployment story for a processor like this is, or like one way to think about it is when this was still working before I asked it to be refactored and broken, the way I would do it is I would locally on my computer, I would do the SSE subscription and run my processor that way.

And then once I thought it was cool, I could either deploy it just as a web service on Cloudflare workers or Vercel or wherever and just tell the

streams to notify me whenever a new event needs to be processed. Or alternatively, just use this dynamic worker thing. And like I don't know if this is going to work. This is why like at the moment it's looking more like it's a really dumb idea, I think, because it's really not coming across.

But for example, you could have a plugin for your agent that runs on another computer, especially if it was like something like really important, like a prompt injection protection or something like that. Like you could say, oh, okay, the way that my agent uses your prompt injection protection service, it can't really be through MCP because there is no way to kind of like proactively hook into the agent loop, or at least not at the minute.

But what it could be is it could say, okay, my agent loop actually waits for up to like 200 milliseconds before making any new LLM request for any safety checkers to say this. And then it can just literally ask your safety checker over there.

I don't care how you implement it. You could even charge me for it,right? And yeah, I just don't think that's currently possible in any other way. That's why I think it's quite important that the stream can reach out to the processors and say, you got to do something.

You know, you need to process some events now.

There's like a couple other potentially. I mean, this might.

Guest57:33

The idea, one of the ideas we shared is my agent might use just-in-time services that other agents are offering.

Jonas Templestein57:41

Yeah.

Guest57:41

Then he might be charged for it.

Jonas Templestein57:43

Yeah. Well, I mean, like probably initially the human would be charged of it. But this is just like there is no way. Like let's say, okay, so Claude code. If I want to make a Claude code plugin, if I wanted to make that into a business, think about how you would have to do that at the moment.

You need to give some sort of instructions or something to Claude code, either to proactively call your MCP tools or something of that nature, or call maybe some CLI tool that was previously authenticated where you did like CLI login to like prompt injection protector.com and then somehow it works.

Whereas

really, I think you can just plug into the agent stream, like into the event stream directly. Like the interface is just somebody notices that Claude is about to do something and chucks some more events in. And like they kind of all work that way, but not quite.

Like it's sort of like you have to squint a lot to see that that's what it all compiles down to.

Before Hooks58:45

Jonas Templestein58:45

Another thing maybe worth pointing out for some of you that have tried to make OpenCode or Pi plugins or whatever is there's no before hook. This is very important. There is actually in the backend, like our built-in processors, the only difference to our processors and your processors is that we can actually stop events from ever being appended.

That is why the pause feature could not be implemented by a third party. So there's sort of like certain things

that need to happen before an event goes in the stream. But broadly speaking, I'm very against before hooks. Like I think there were some instances in OpenClaw, for example, some massive performance regressions and cost increases where

you can break context caching quite easily with before hooks. You can massively destroy performance. Like it's just way better to think of the whole system as being eventually consistent. And, you know, doing all these distributed systems things, like saying, okay, we're going to wait for up to 200 milliseconds for somebody to say, I've got a little bit of information for you.

But then we're actually going to make the LLM request, whether you come in with information or not, because this needs to be a resilient system. So if you think, for example, about RAG pipelines and things like that, you can easily have a little processor that says, I have like an indexed version of the Notion knowledge base or something, and I'm just going to sit here and try to squeeze in a little bit of extra context if I think it's relevant.

But if I don't get there in time, it's like totally chill. The whole thing still works. It's not like I've kind of delayed the agent or something.

Yeah.

Guest1:00:17

What about, so you're hosting this instance of GitHub? Like how would you imagine in the future? Would everyone host their own one or.

Jonas Templestein1:00:25

You mean, I mean, the streaming database. Like, I don't know. I think this could work on almost anything that is like durable stream shape. So this was just for the purposes of this exercise. I do think like there is potentially an interesting scenario where

it's not even really like it's a combination of a queue and a pub subsystem and like a streaming database that can also run code for you. But that sort of thing is an interesting infrastructure primitive that maybe somebody could make.

I do think that, yeah. But in principle, like I don't know if you don't know about it yet, you can read up on this durable streams API specification that somebody came up with. We don't follow it exactly, but close enough.

And it's basically like a very common old idea. The thing that is more new is that it would be like you would also have push subscriptions out of it. But there are some things that do. There's a thing called like JetStream NAT or something that does it.

Yeah.

Guest1:01:33

Are you talking about like the electric SQL?

Jonas Templestein1:01:35

Yeah, exactly. They have durable streams, yeah. And like a durable stream is just like an append-only event log with offset tracking. And they want the client to track the last consumed offset. That's also how, say, Kafka works or something like that.

But you can also do it the other way around and have the server track the offsets. And those are more normally like there's Google Cloud and AWS, they have these pub subsystems where they say, oh, we'll just like give you the next event and we'll keep track of the offset for you.

Guest1:02:07

I've got another question.

Jonas Templestein1:02:08

Yeah.

Guest1:02:09

Say I've got Michael Bell here or Michael. And I have a subtask called images and I hook it up to like a local LLM, which is generating images. And then anyone could essentially pass a stream to that, which would then go to my LLM, generate an image and return it back.

Wrap Up1:02:16

Guest1:02:23

How would I prevent a certain amount of like basically flooding images?

Jonas Templestein1:02:28

Oh, I mean, you would need to have authentication on it. Right? Like this entire thing would never, like this I was thinking like it might be fun to just say there's.

Misha1:02:38

Don't do that yet.

Jonas Templestein1:02:39

Yeah, exactly. It might be fun to just say there's a public namespace and it just gets cleared every hour or something,right? Because it is kind of nice that anybody anywhere on the internet can just curl a thing or like copy and paste a curl from somewhere and suddenly have like a flavor of agent.

I do think that's quite interesting, but it just needs to be deleted quite aggressively. Yeah, but I think that's more or less a solved problem. It's like a bit gnarly, but basically the way I envision it, you would do it if you did this properly is on each event, you basically have like client provenance information.

We say like who was this? Like what were they able to do? Like how sure are we that these people, you know, the HTTP client or the stream client was actually entitled to do this operation? And again, you can model all of that as events,right?

Like you would just have an event that is like make this stream public. And until you make that event, it can only be written to by whoever created it or something.

Allright. I might ask Sean if we can, instead of this video, do a video we'll record a little bit later today that shows it more nicely, because I do think it's worth showing. Just a little bit too short notice.

Shall we just wrap it then? I don't mean to keep you all of you like a 10-minute longer break or if anybody wants to chat.

Guest1:04:08

Thank you.