Our thesis is that AI is still just engineering… those people who tell us for fun and profit, that somehow AI is so, so profound, so new, so different from anything that’s gone before that it somehow eclipses the need for good engineering practice are wrong. We need that good engineering practice still, and for the most part, most things are not new. But there are some things that have become more important with AI. One of those is durability.
Samuel Colvin, Creator of Pydantic AI, joins Hugo to talk about applying battle-tested software engineering principles to build durable and reliable AI agents.
They Discuss:
* Production agents require engineering-grade reliability: Unlike messy coding agents, production agents need high constraint, reliability, and the ability to perform hundreds of tasks without drifting into unusual behavior;
* Agents are the new “quantum” of AI software: Modern architecture uses discrete “agentlets”: small, specialized building blocks stitched together for sub-tasks within larger, durable systems;
* Stop building “chocolate teapot” execution frameworks: Ditch rudimentary snapshotting; use battle-tested durable execution engines like Temporal for robust retry logic and state management;
* AI observability will be a native feature: In five years, AI observability will be integrated, with token counts and prompt traces becoming standard features of all observability platforms;
* Split agents into deterministic workflows and stochastic activities: Ensure true durability by isolating deterministic workflow logic from stochastic activities (IO, LLM calls) to cache results and prevent redundant model calls;
* Type safety is essential for enterprise agents: Sacrificing type safety for flexible graphs leads to unmaintainable software; professional AI engineering demands strict type definitions for parallel node execution and state recovery;
* Standardize on OpenTelemetry for portability: Use OpenTelemetry (OTel) to ensure agent traces and logs are portable, preventing vendor lock-in and integrating seamlessly into existing enterprise monitoring.
You can also find the full episode on Spotify, Apple Podcasts, and YouTube.
You can also interact directly with the transcript here in NotebookLM: If you do so, let us know anything you find in the comments!
👉 Want to learn more about Building AI-Powered Software? Check out our Building AI Applications course. It’s a live cohort with hands on exercises and office hours. Here is a 25% discount code for listeners. 👈
LINKS
* Samuel Colvin on LinkedIn
* Pydantic
* Pydantic Stack Demo repo
* Deep research example code
* Temporal
* DBOS (Postgres alternative to Temporal)
* Upcoming Events on Luma
* Vanishing Gradients on YouTube
* Watch the podcast video on YouTube
👉Want to learn more about Building AI-Powered Software? Check out our Building AI Applications course. It’s a live cohort with hands on exercises and office hours. Our final cohort starts March 10, 2026. Here is a 25% discount code for listeners.👈
Get full access to Vanishing Gradients at hugobowne.substack.com/subscribe
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Transcript
From the show. Tap a time to play from there.
Our thesis as a company more and more is that AI is still just engineering. Those people who tell us for fun and profit that somehow AI is so profound,
SPEAKER_01so new, so different from anything that's gone before that it somehow eclipses the need for good engineering practice are wrong and that we We need that good engineering practice still. For the most part, most things are not new. Most things we have to go and do are not wholly new. But there are some things that have become slightly more important with AI. One of those is durability.
SPEAKER_00That was Samuel Colburn, creator of Pydantic and leading the team that's building the Pydantic stack. Validation, AI and Logfire for observability on why building with generative AI remains fundamentally a software engineering challenge. Samuel's a dead set legend, and I was so glad that he joined me to discuss the transition from experimental prototypes to durable agents, robust systems built to survive network failures, and the inherent stochasticity of LLMs and generative AI.
If you're calling an LLM and that's taking somewhere between three and 300 seconds,
SPEAKER_01and then you're going to go and call 10 of them in a row, you really don't want to have to start again. And you really don't want to have that to die every time your Kubernetes node gets killed. And so durability is about effectively, there's lots of ways to talk about it. Fundamentally, it's about recovering from failure and resuming from where you left off.
SPEAKER_00With respect to agents, Samuel describes a bathtub curve of constraints. Coding agents can be messy because a human is watching, but production agents need engineering-grade reliability. He makes the case for splitting agents into deterministic workflows and stochastic activities So you can cache results and skip redundant LLM calls during retries. We also get into context engineering, why agentlets are replacing the mega agent paradigm and a prediction that AI observability won't exist as a category in five years.
SPEAKER_00It'll just all be observability. Samuel also walks through live demos of durable agents and deep research. He talks us through the code as he goes, so you can follow along even if you're just listening. If you want, though, you can also check out the video on YouTube. This conversation was a Q&A from a recent cohort of our course, Building AI-Powered Applications, which I have the great pleasure to co-teach several times a year with my friend, Stefan Krauchik, who works on AI agent infrastructure at Salesforce. Links in the show notes if you're interested.
We also live stream many of our podcasts and free workshops and would love you to join. Check out the Vanishing Gradients Luma calendar and subscribe to our subset
SPEAKER_00newsletter and YouTube channel. All links are in the show notes. If you enjoy the show, the best way to support it is to share this episode with a friend or colleague who you think would get something out of it also. I'm Hugo Bowne-Anderson and welcome to Vanishing Gradients. And we are live. What's up, Samuel Colvin? Nice to see you, Hugo. Yeah, all good, all good. Yeah, very happy to be here. Always a pleasure. I also enjoy our chats and I learn so much from you. We've been doing so much in this course. There's a lot of new stuff we've been covering in the course.
SPEAKER_00The last time we taught it was July, of course, when you came and talked about and showed us all about self-healing agents. But there's so much more now in the space around multi-agent systems, how to handle context and this new idea of context engineering, which seems like a good term for a lot of what we're all doing here. And I do, I'm really excited to talk about durable agents and how they relate to all of these different things. But I thought people, of course, everyone knows who you are because of Pydantic.
One thing I'm interested in, could you just give us a bit of your background?
SPEAKER_00Because you didn't build Pydantic for AI reasons at all, right? Yeah, absolutely.
SPEAKER_01Yes. Pydantic predates Gen AI by a few years. So it started in 2017. I was running a software company back then. In fact, I was trying to build something to parse HTTP headers, and I found myself duplicating the type annotations of whatever it was I was trying to extract and the validation. I forget what I was using at the time, probably doing it manually, and it just seemed mad. And so, yeah, Pydantic started off as this project, like side quests in a directory in an existing project to see if I could use type
SPEAKER_01adaptations to validate data. And it turned out it took over my life. And here I am eight years later doing nothing but Pydantic, although Pydantic is now some more things.
SPEAKER_00Well, also, as it turned out, Pydantic is all you need, as we know. I also am interested in... So firstly, thank you so much once again for sponsoring the course and all the credits you've given everyone to experiment with Logfire. No problem at all. And I am interested in what you're working on and what you've built and why you're doing this now.
SPEAKER_01Yeah, I think obviously Pedantic became a company. I think, I mean, you can talk about why we do it commercially, but I think why we do it from the passion of why it's interesting. I think, of course, there's the building of LLMs, which is a fascinating subject in itself. But what I have always been good at and what I've always been interested in is taking the low level of the science and turning it into engineering. Taking the very complex, theoretically, what's possible and making it easy to do from an actual engineering point of view. And so,
SPEAKER_01yeah, I mean, I think that right now, the like most, the apex of what's interesting in terms of software design is how you do that with LLMs, whether that is building software with LLMs or building software that uses LLMs, observability and how that relates to AI. I think that's a really fascinating space. That's why I enjoy what I do. We get to go and like invent ways of doing things.
SPEAKER_00Cool. And so I suppose I'd love to know what you've built, Pydantic, no log file. What else is in the mix? And why did you prioritize these things? Yeah, so we do four things today.
SPEAKER_01So we do Pydantic Validation, the OG library. It's relatively stable for the most part, although actually we have some really exciting improvements coming up over the next few months. We have what we call struct, which is this idea that we can later materialize the data and therefore we can... improve performance of validation by up to kind of three, four X, but also make it more, more flexible. Also reduce memory, but like we should, we should support validating of like arrow data directly. And it's like materialization stuff that improves performance. So, but yeah, first thing is Pydantic validation.
Second thing is Pydantic AI, the agent framework, but also we have Pydantic evals in there.
SPEAKER_01There's Pydantic graph. There's the durable execution stuff that I'll talk about today, where instead of reinventing the wheel and trying to invent our own thing, which others in our space have tried to do and I think fails. Instead, we're integrating with the people who are best at doing dual execution to give you battle-tested ways of supporting that. Then we have Atlantic Logfire. I still believe that AI observability will not be a term in five years' time. I think AI will be a required feature of observability, just as there's no such thing as web observability or cloud observability.
SPEAKER_01But today, Working out what it is to build, to observe AI applications and the AI observability, both on the eval side and on the prompt management and all the other stuff is like more and more of our focus within Logfire. And of course, the problem with a growing company is you are always at the limit of the performance of your database. And so we always are grinding to try and make the database cheaper, faster, better at ingest, all that stuff. And then the other, the last bit is Pyantic AI Gateway, which we announced.
I think now two weeks ago or a week and a half ago, that's the latest bit on the stack. Well, many congrats on everything, in particular, the recent announcement of Gateway.
SPEAKER_00I do want to jump in to talk about durable agents. I can say durable here. It's a safe space for such intonations. You and I have had a bunch of conversations around, for lack of a term, kind of being a bit fed up with the lack of robust software engineering principles in a lot of the space. And when I played devil's advocate with myself, I asked myself the service area of what's possible with software and what software means, I think has expanded so much.
SPEAKER_00I suppose I do ask myself, do we still want software to be reliable and consistent in all the ways we expected, or is there room for other types of things? So I think that there is a continuum of how constrained the problem is and how
SPEAKER_01willing you are to accept unusual behavior, including outright failure, as in like network failure, the thing crashed. And that is basically a bust up curve today. We have the two extremes of the most continuum. You have a bump in the middle, which is where everyone sits. And there are like widows at both ends of the spectrum. This particular continuum is the opposite. We have the two extremes, populated and very little in the middle. So we have the one and the least constrained, most willing to accept odd behavior or failure are the coding agents.
SPEAKER_01They're running locally on our machine. They have hopefully an adult, sober adult, not always entirely sober, not always entirely acting like an adult, but there's a human watching what they're doing for the most part and you don't really mind how wrong they go. For the most part, we use don't do stuff outside the current directory as our level of Sandboxing, we may do some better sandboxing than that, but they're pretty unconstrained, and that's kind of the idea. They can go and use all of the tools in the toolbox to try and solve problems. At the other end of the spectrum, we have agents that we go and put into production,
where we generally have a much more constrained space for what we allow them to do.
SPEAKER_01We're much more concerned about security. We care a lot more that they are reliable and repeatable and that they will do the same sort of task 300 times in a row without going wrong. We care much more about latency and cost and all that stuff. So I think in the first category, where basically LLMs are replacing our fingers, we're prepared to accept them going wrong quite often. And actually, codecs and code code don't do a half bad job of actually tolerating using them on a plane. I was in New York last week,
and I was coding with both of them on the flight both ways. And sometimes they would grind to a halt, but for the most part, they would work.
SPEAKER_01But in the other case, I think we're not happy with the idea that one network failure will cause our agentic flow that was going to take half an hour to go wrong and have to be restarted.
SPEAKER_00Does that answer your question a bit? It really does. And it speaks to, I think, how much risk one wants to take on with what the software one's working with and also building from our side. I think related is just timescale of feedback loops as well, right? Because cursor's pretty quick. most of the time and so i get and it does wrong stuff all the time but the time scale of my ability to have a feedback loop with it is pretty good similarly i've been using manus a bunch recently to help with research and it
will go and compile a bunch of research on a podcast or something i want to do in 10 minutes that's pretty good but i need to iterate with it a few times if it took 10 hours that wouldn't work for me right but the fact that it takes 10 minutes and then i can
SPEAKER_00iterate is pretty powerful
SPEAKER_01Yeah, but also I think you know that you're using an LLM. Ignoring your ability level, you are comfortable with the fact that you are doing something that's fundamentally stochastic. If you are looking for a recommendation on a shopping site, you probably are not comfortable with it to randomly recommend it completely the wrong thing. You don't find it funny if it recommended something obscene to you when you're looking for children's toy. If it recommends a sex toy, you are not happy with that hilarious mistake. Whereas you might be amused by the like... Adam from Prefect was giving a great talk the other day where
he had asked a deep
SPEAKER_01research agent to go and research set, now this is going to challenge me, 1686, which is the set for long-running tasks at MCP, and it had come back with the Battle of September 1686, which was where the Ottomans defeated someone or other, I forget who. It was hilarious that set 1686 was the wrong thing, but because he was using an AI, we can all sort of guffaw at the fact that the LNN got it wrong, but there were situations where that's really not okay. The shopping example I give, but you can think about lots of other ones in medical,
even if it's more mundane and it's like processing the values in an invoice, if no human's ever going to go and look at that and turns out 10% of the time we
SPEAKER_01are allocating things wrongly, that's not good enough. I might be able to show an example of a fairly subtle failure in a minute. I can't pretend I came up with it on purpose. It came to me, but anyway.
SPEAKER_00Awesome. Let's jump in. We're here to talk about durable agents. I do want to know what durable means in a second. I'm wondering if you can just tell me what agent means first. So there are three definitions of agent.
SPEAKER_01This is one of my go-to jokes at the moment. There are three definitions of agent. There's the LLM or AI people's definition of agent, which is an LLM calling tools in a loop. There is the infra person's definition of agent, which is a microservice. And then there is the business person's definition of agent, which is something that can replace a human and take their salary away. At the beginning of, the big thing that's changed this year is at the beginning of this year, we thought that the, ignore the business person, they're wrong completely. But like, we thought that one infra agent, one microservice would contain one AI agent,
SPEAKER_01one calling tools in the loop. More and more, I think this is still the year of the agent, but those agents have stopped being like one agent that does our entire service, microservice thing. That like agent is now made up of many agentlets inside it that will go and do subtasks. An agent has sort of become, at the risk of sounding really pretentious and VC-ish, agent has become the kind of quantum of AI, the single building blocks where we stitch together, plug together multiple different agents to do tasks rather than having one agent that has all of the tools and all of the control and all of the
time and will
SPEAKER_01always get it right, which we've sort of learned isn't generally the case.
SPEAKER_00I love it. So what does durability mean then? And when is it important as well? I think that our thesis as a company more and more is that AI is still just engineering. Those people who thought tell us for fun and profit that somehow AI is so profound,
SPEAKER_01so new, so different from anything that's gone before, that it somehow eclipses the need for good engineering practice. are wrong and that we need that good engineering practice still. And for the most part, most things are not new. Most things we have to go and do are not wholly new, but there are some things that have become slightly more important with AI. One of those is durability because If you're making, let's say you have six database requests to make to do some transaction for a user, like update their balance or whatever it might be. You could do that in,
let's say that fundamentally we're looking at sub 100 milliseconds for each of
SPEAKER_01those queries. You can do them in 600 milliseconds and you can return to the user. And as long as they are all atomic, you don't really mind trying them again a few minutes later if they went wrong. If you're calling an NLM and that's taking somewhere between three and 300 seconds, and then you're going to go and call 10 of them in a row, you really don't want to have to start again. And you really don't want to have that to die every time your Kubernetes node gets killed. And so durability is about effectively, there's lots of ways to talk about it.
Fundamentally, it's about recovering from failure and resuming from where you left off.
SPEAKER_01It's about recovering. And that failure can either be a node shutting down or a network request going wrong. And then some of the durable execution frameworks like temporal also allow us to write some code, which you write a sort of normal deterministic code or not deterministic, but like procedural code. Let's say I want to send an email 24 hours after someone has signed up. I don't need to go and set up tasks for that. I can just sleep for 24 hours and then send an email and the temper will take care of basically turning off that process and resuming it when it
needs to run.
SPEAKER_01That's not really, I don't know whether they would call that a core component of durable execution. I think it's a very nice cherry on top, not the core nature of it.
SPEAKER_00Great. And I didn't actually plan this, but this chat couldn't have come at a better time because the workshop we just did, we covered a lot on agent reasoning loops and then agentic research as well. Yeah. Which I know is something that interests you and motivated this for you quite a bit. Yeah.
SPEAKER_01Yes. So I have what I call the like treasure hunt. I think of the like treasure hunt case of agents. So where basically you can't get to the answer immediately. You need to go out and find some intermediate step along the way. And then with that, you can go and find the next step and the next step. You know, you think about those old school computer games where you have to go off and like, ask the woman at the end of the lane where the secret potion was, and then he went and asked someone, you found the secret potion, you drank it, whatever it is, right? There are lots of cases in real world that feel somewhat like that.
SPEAKER_01And deep research is kind of the quintessential example. You can't start reasoning about your response until you've gone off and done your research, but you probably need a few steps of research until you found all of the information because you don't know what you're looking for until the end of the first one, et cetera. And so the example I'll show you now, I'll share my screen if that's all right.
SPEAKER_00Great. Absolutely.
SPEAKER_01I'll do some aggressive zooming in so people can see it. Love it. I'll share my entire screen and then do some aggressive zooming in so you can see this example. Hopefully people can see that. Let me know via Hugo if anything that I'm showing is not clear.
SPEAKER_00So we can see all your code, but yeah, zooming in would be amazing. I think I've zoomed in quite a lot there.
SPEAKER_01Hopefully that's big enough that it should appear on screen. yeah looks good to me but you could actually fill your whole screen with it potentially as well yeah i mean it won't be wide enough i could yeah i mean i think we're getting towards yeah that's the limit that should be pretty big so here we're playing as the as the file name suggests 20 questions so we have uh you know the game where you basically normally you would answer yes or no to something and someone would try to guess what what you're thinking of in this case It turns out LLMs are quite bad at playing 20 questions. And so to give them a better chance of answering, we actually have a set of five different categorical answers.
SPEAKER_01Yes, kind of, not really, no, and completely wrong. And then we have our answerer agent, which has got a very simple task. It's just going to take in... The secret object that it's thinking of, it's got one prompt, which is you're playing question and answer game. Your job is to answer questions about a secret object only you know truthfully. And you see, because this is a relatively simple task, I'm using, in this case, Haiku 3.7, 3.5, sorry. So this is our answer agent, not in some sense the core bit of what we're doing here. And then we have our game state and our questioner agent,
SPEAKER_01which has a bit more of a prompt, which is going to go and ask those questions and try and find the answer. And ultimately, what it's doing is it has one tool registered, which is ask question. And inside that tool, we're going to use the answerer agent to answer the question that we've been given and return that output. And so it's going to run in a loop. The questioner agent is going to call this tool to ask the answer agent, and it's going to try and work out when it's got to the right answer. And once it gets to the right answer, it will then exit.
And can I just ask, do we need agents for these, or would an LLM with just basic memory...
SPEAKER_00Be fine there or for these sub-agents, I suppose.
SPEAKER_01So the questioner agent is going to run an agentic loop. It's kind of the definition of an agent, right? It's going to call a tool in a loop until it arrives an answer. So if that's not an agent, then what is? Okay, great. The answerer agent, so this doesn't have a tool registered. We use this add answer context manager to insert the answer from depths so that we don't have to encode the actual answer within our definition of the agent. This, in theory, doesn't need to be an agent. Now, it turns out even here we get an agentic loop because it's going to have to return some structured data,
SPEAKER_01in this case, an instance of answer. And so if we were using a dumb enough model that it sometimes got this wrong, we want that agentic loop to basically reply to it and say, you got that wrong, please try again. But yeah, you could argue that that one doesn't need it. But I'm going to come over here and run it and I'm going to make my window much bigger so you can see it. I'm afraid I'm just not cool enough to use the terminal within the IDE so you get a separate terminal, but you should be able to see that. To be clear,
SPEAKER_01this has no durable execution within it, but I need to show you the simple case to show you what's going to go wrong. I'm going to go and run that. And the other thing to see here is I've instrumented it with Logfire. So we'll be able to see the agents running. I'll show you that in a moment as well. But if I go and run this, what have I done wrong? UV run. You should see it thinking about the question. And then you'll see it asking questions. I'm just printing out the answer here, not using Logfire's terminal output. So you can say it's saying, is it a living thing? Kind of.
SPEAKER_01Oh, so the answer is potato in this case. And it's trying to work towards the answer. And you can come over here to Logfire. And you could see our 20 questions being played back and forth. And we can see the individual spans as they're going on. Can you zoom in there a bit as well? I can try. I mean, it's not that easy to zoom in that much. But you get the idea. We get the token counts. We get what we spent so far. Just gone over one cent. And we can go and look into an individual exchange with the answer agent here and
SPEAKER_01what the exchange was. You can see it's using a tool call to do the structured categorical response. and in this case success it got to the answer potato in 14 steps but if we ran this again and we let it get some way in and now either we get a networking error that would cause it to raise an exception and crash or the node that's running running this agent had to shut down And it gets killed. Now, of course, we've lost our lost our progress, we're going to have to start again. And if we start again, we start from start from one.
And so this is an obvious candidate for something where we would love to be able to
SPEAKER_01retreat, resume from where we were at without having to build our resume stuff into our agent, like agent graph, which would be, you know, unless you thought very hard about building that it would end up not being type safe, and it would not be resilient to all the different kinds of failure, and it wouldn't be able to resume for the most recent spots. So that's where durable execution comes in. So I'm going to look at another example of this 20 questions game, but here we're going to use temporal as our durable execution framework to run it.
SPEAKER_01It's worth saying there's another example in this repo, which is a resource that uses DBOS, which is another durable execution framework. I think today I'm just going to talk through temporal because they're kind of the big 300-pound gorilla in the durable execution space. And OpenAI even uses Temporal, right? Yes, that's right. So if this is obviously very similar to a deep research case, I've got a deep research version of this code here as well.
SPEAKER_00Cool. Yeah,
SPEAKER_01they use them, and I think Anthropic, I'm not sure, but I think Anthropic as well also use Temporal. also use this so would it be possible to pivot to the deep research case just because we've been covering deep research today or will the setup be to I can try I'm going to whiz through this one really quickly how long as long as you want okay I'll go through this one quickly and then hopefully we can get to it yeah So you'll see here that we have our answer agent. I've actually simplified it here. So it's just returning a bull true or false. And then we have the, the difference here is we take our temporal agent type from
Pydantic AI and we wrap
SPEAKER_01our agent in temporal agent. This gives us back something, which is an abstract agent. It will behave exactly like an agent, but we have done the hard work of inserting temporal into it. So temporal works by. by splitting up code execution into workflows and activities. And the workflow is the main programmatic deterministic execution of your task. So it has to, it cannot do file system access. It can't do IO. It can't do anything which might be random. It has to, given the same inputs, has to behave the same way each time.
And then all of the stuff that will do IO or access the file system or anything
SPEAKER_01like that is an activity. And effectively what Temporal is doing behind the scenes, I have somewhere a graphic which makes this even more complicated to understand, but fundamentally what Temporal is doing is it's recording, it's caching the answer to each activity as it runs. And so if you want to retry this particular workflow, Temporal can basically plug in the numbered responses to each of the activities. So that's why it needs to be completely deterministic, the workflow, so it can always know for certain which answer to which activity it needs to plug in. And if you were writing normal code,
you would need to go and annotate things with workflows and activities all over the
SPEAKER_01place The nice thing about using Pydantic AI is we have gone and done all the hard work to wrap stuff in temporal. So you will write almost exactly the same code. You will have a bit of ceremony, as I'll show you at the end of this repo, end of this file to run it as a workflow. And hey, presto, we get the durable execution. So for the most part, that involves wrapping our agent in this temporal agent. So we have the same question agent here. Again, it has capacity to ask a question. Again, it's wrapped in durable in temporal agent.
You will see here inside this tool call, basically 10% of the time, it will raise an exception. And I've added that to demonstrate what it would be like if we had some networking
SPEAKER_01issue where unreliability of our upstream model, so we were getting periodic failures. It's worth saying that both LLM calls and tool calls with Pydantic AI are wrapped in activities with only agent framework that does that properly. So in my opinion, the rest of the agent frameworks, which claim to have some degree of durable execution of kind of chocolate teapots, because all of your tools, again, end up needing to be activities. And if you don't automatically make them activities, they're kind of unusable. But anyway. So we have relatively similar agent. We just wrapped it in our temporal agent.
SPEAKER_01Then this is where we get to the kind of temporal code. So we define our workflow like this. So we have a class that is decorated with workflow definition. Then we have a workflow run here. This is all kind of temporals ceremony. I don't think it's particularly pretty, but it does what it needs to do. But in here, ultimately, all we're doing is calling our temporal question agent, which is how we kick off our game of 20 questions. We just give it the input start as we did before. And now we've defined our workflow. We can then go and play the game. And here we're going to do a bit more setup so we will
create a temporal connection that's going to connect to the temporal server,
SPEAKER_01which is taking care of this. We register some plugins for log fire and pydantic AI, which do some work behind the scenes. And then we define our worker, which again, we define, we have a name, we have the workflow. And again, we define some plugins that are necessary to basically do all over the plumbing. And then we get to where we basically kick everything off. And ignoring this case for a minute, here we're just going to call execute workflow to start running our workflow. And we give it an ID that we can get back.
SPEAKER_01And that's all we really need to do to kick off our workflow. I'll get to what's going on here.
SPEAKER_00Now for a word from our sponsor, which is, well, me. I teach a course called Building AI-Powered Software for data scientists and software engineers with my friend and colleague, Stefan Krauchik, who works on agent force and AI agent infrastructure at Salesforce. It's designed for people who want to go beyond prototypes and actually ship AI-powered systems. The link's in the show notes. super cool and we have we have a question or a set of questions from brad and he thinks it's been answered he's still trying to wrap his head around a few things so
brad has asked is temporal basically the framework behind mal managing failures and so on and then he says he hasn't quite connected the dots what would be the difference between using pydantic and temporal versus a lang chain flow and he thinks he's still trying to wrap his head around so i'm wondering if you could just
SPEAKER_00help Yeah,
SPEAKER_01so I think LandGraph has, their graph structure has support for snapshotting, which is their, like, in my opinion, somewhat rudimentary attempt to do the same kind of thing. The point there is that you don't get, you only get the snapshotting at the end of each node. And to have snapshotting and parallel node execution, you basically have to give up on all type safety. Whereas here we'd have any, you'll see here that there are no squiggly lines anywhere in this file. This is completely type safe. We take types of safety very, very seriously inside,
SPEAKER_01inside Pydantic AI, because I think it's absolutely key to, to building modern software. You literally cannot implement. graphs with parallel node execution and snapshotting and keep it type safe. It is like, I can explain why in detail, but fundamentally it's impossible. So their equivalent would be land graph. I think that like no one's credibly arguing, but that's a serious option. I would, my parallel, my apologies for being rude, but like, I think Langchain, you know, when you go to the beach and you can pick up that bat and ball and like hit the bat
SPEAKER_01and ball back and forth. Langchain and Langrath are the plastic bats to Temporal or Piedansky AI, which is the tennis racket you might go to Wimbledon with. They're not for professionals, they're for amateurs as they get started. And anything else is basically, to argue anything else is dishonest, I would argue,
SPEAKER_00although I'm obviously opinionated in that take. And how are people doing this? more generally? Or are people hand rolling like with retries and catches? I mean, I think serious people are using Temporal and DBOS and other durable execution
SPEAKER_01frameworks. I know that we have a lot of people who've picked this up and used it within PyDantic AI. I know there's a bunch of people who will use the underlying SDKs directly, not use PyDantic AI, but use Temporal Like, look, some of the people who are managing other routes, I doubt very many serious applications are using LangGraph or LangChain. I suspect that there are, I think the two credible ways of doing it are using the SDKs directly or using PyDantic AI. And the hybrid one is OpenAI agents, they're SDK.
SPEAKER_01which is also a quite serious answer. And that's no coincidence because they basically copy-pasted Pylandic AI. And so it has many of the advantages and they've introduced some disadvantages along the way, but it's useful. Anyway, I'll stop trash talking all of the competitors and run this example quickly. And then I'm happy to come back. So in this window here, I'm going to run the Temporal server. So I'll make that a bit bigger so you can see it. Awesome. And I'm just going to run the local Temporal server. So Temporal are a company. They have a commercial offering. That's how, if you were running this in prod, you would probably use Temporal's Durable Execution Orchestrator.
But there's an open source version for running it locally, which I'm going to use today.
SPEAKER_01Sorry, Hugo, did you have a question?
SPEAKER_00No, no, no, I'm good.
SPEAKER_01So I'll just run that and it'll just say it's running on this port, which you see that we've connected to here. And with that running, I can now come over and I can run my durable execution example. And so I'm going to run the temporal example here. And you'll see it prints out a bit of stuff. In particular, it prints out the workflow ID. And it should now start chunking away, asking those questions, as we would have seen before. What's powerful, though, is, oh, you saw we got a broken error just on cue. This exception just recovered from that. Basically, any error within an activity, Temporal is able to retry.
SPEAKER_01You'll see it carries on working. And if I now go and kill it, at question five, you will see. I can now effectively run the server again. In this case, all I'm going to do is, this is where I said, I'm going to run the worker again, and I'm just going to wait on the answer to a particular job ID. You wouldn't normally need to do this, but if I just ran it normally, I would start running two different workflows at the same time, because each time I run the worker, it starts a new workflow. That will be confusing. So here, just to make things more easier to understand, I'm going to
SPEAKER_01run it again and specifically wait on this job ID. And so what you will see is once we get going, you'll see we go straight to question six in terms of what's printed out and it continues. And if you want to understand how that works, you can come back over and see it in Logfire. So you'll see here within our trace, when we ran it for the second time, this trace here, you will see that the responses to the first five tool calls happened in a matter of a couple of milliseconds. And that is where temporal is basically taking the cached answer and injecting it
into the workflow from the activity so that you don't rerun those first steps. And then when we start running the following steps that need to still be run,
SPEAKER_01it will go back to running the activity. So running the LLM within each tool call. And it should at some point. See, we're getting a few broken errors, but it is interesting how sometimes the NLM goes off on this particular challenge and will get itself confused and won't get to the answer, but you get the idea.
SPEAKER_00Fantastic. It's great to see Logfire integrated so easily as well. It's one of the really nice things about Logfire ultimately being an open telemetry system. uh just receiving open telemetry data that we have done we've done a bit of work to make this all add up but fundamentally it's all it's all connecting together because of open telemetry it's the great thing about following open standards
SPEAKER_01And you can still see, we can see all of the details on token counts, on the tools registered with each individual agent,
SPEAKER_00et cetera, et cetera. Super cool. And I know we've chatted about evals a bunch in the past, and I know you've got your eval stuff happening there. I'm wondering whether you've found this type of... Evals can take a while and they can stuff up. How do you think about using durable execution for evals? Is that something you've worked on?
SPEAKER_01I think it's exactly the kind of case where you want it, because the last thing you want to have to do is to go and... rerun the whole thing from scratch I actually have some evals on this particular case I'm going to see if it's I think it's gone off it's got confused it happens to the best of us it's got itself really confused is it flexible or rigid okay I'm gonna I'm gonna kill that I can actually I mean one thing I wanted to show I don't know if there's any in this project here but yeah this is some tech this is some evals I ran the other day on this exact case oh could you zoom in just a tad
yeah i mean it's it's gonna be hard to read is the truth because it is it's a pretty complex screen so you will have to tolerate it being ugly yeah this is our view of the list of experiments and then if i go and open a particular pair of experiments we get a view of the relative performance so here we're comparing gpt
SPEAKER_014.1 to gemini 2.5 flash For the Q&A case, and you can see in terms of the assertions that, so this is interesting. You see it's saying that Gemini Flash did better than GPT 4.1. I think actually here, that's a slightly incorrect result. There's a problem with the evals, input tokens and stuff like that, but more interesting. And I say we are a bit too zoomed in here for me to really, this really to be... particularly viewable but what you will see is we can go
through basically the the here we have the case names and the inputs in this case are the same so this is effectively the object that we're looking for and then we have the one assertion on each side which is whether or not it succeeded uh and you will see that it yeah you'll see it succeeded 100 of the time with google vertex and some minority of the
SPEAKER_01time with gpd 4.1 now As I said, in this particular occasion, this is incorrect because what happened was that Google Vertex basically got bored and eventually replied and said, I can't find the answer. And when I wrote these evals, I haven't actually confirmed that it had found the right answer. So this is not a particularly accurate eval. But if you remove Gemini 2.5, which has this particular bug, and you look at two other models, 4.1 and Mini, you'll see in this particular case, they did exactly the same at exactly the same number of failures.
SPEAKER_01And then you can, what's nice is that you can dig into the exact inputs and outputs that happened in each individual case. We don't have any custom metrics here apart from duration, but if we have them, you can see them. And because all of this is OTEL data, if you want to go in and look at exactly what happened in the case of Gemini 4.1 mini, in the case of house, you can go and look at the actual trace that generated it and go and dig in and see exactly what happened i've kind of whizzed through the evals there without explaining
everything but hopefully that gives you some idea yeah super cool and everyone go and use your very generous credits to to instrument with logfire and check out the evals as well we've got a question is if if there's a repo for everything you've just been showing and i think i've just linked to pydantic stack demo is it in that part of the repository yes i think it is there's a folder directory called durable exec so yeah so it's here and i can do that thing that some of you may or may not be able to see and
take a picture of which is the remember but basically which is the link but basically go to github.com and then look for stack demo and you'll find it and
SPEAKER_01you'll see all of the durable examples in this durable x directory
SPEAKER_00Awesome. So I'd love to just chat a bit. I don't think because the deep research demo is there as well. People can go to that themselves. I wonder if just chatting through it would be useful. Yeah, absolutely.
SPEAKER_01So this is an example of, in fact, of what I was saying earlier that like often the best examples we The best agents are made up of multiple sub agents. So in this case, we have we define this deep research plan as a pydantic model. This is a relatively unsophisticated example. I think if you were building a deep research agent, you would want something slightly more sophisticated in this case. But we have. the plan comes with a kind of executive summary what you might show to a user this is what we're about to run some the web search steps so up to five web search steps
which on this occasion just contain a search term you'll see we're using attribute
SPEAKER_01doc strings so these descriptions here will become the descriptions for the parameters of a tool that is ultimately registered with the LM. And then we have analysis instructions, which is kind of the rubric that the AI will ultimately use to evaluate the deep research. So then this is where we have multiple different agents. So we have the plan agent and what it will turn structured output which is of type deep research plan. So this is how we effectively build our plan based on the term. Then we have the search agent, which uses relatively light agent,
SPEAKER_01Gemini 2.5 flash, with a built-in search registered here. So we'll use the search that comes from Google rather than registering a separate tool. And then lastly, we have an analysis agent where we're using a different model called Sonic 4.5. And that will be fed the answer. And that last analysis agent has access to search again, if it really wants to, to call the search agent. If there's something else, it needs to go and look up. And I'm looking at the DBOS example, and I actually think I want the temporal example.
There's quite a lot going on here, but ultimately what we're doing here is we are...
SPEAKER_01running the plan agent, getting back our plan. Then we are running in parallel all of our web searches using the LLM. We'll collect those results and we will use format as XML, which is our tool for basically smashing any old Python object into a kind of XML-ish format, which LLMs can understand. We'll pass that to our analysis agent and it can then go and run. Do you want me to try and run it? Yeah, let's do it. We've gone this far. So the question I've asked is, what's the best Python agent framework to use if you can care
about durable
SPEAKER_01execution and type safety? This was reliably returning Pylandic AI. The other day, it committed, sort of insulted me deeply and suggested LandGraph, which I'm deeply offended by. But we'll run it and we'll keep our fingers crossed.
SPEAKER_00Maybe LandChain's working on their agent. GEO rather better than I am. Yeah, exactly.
SPEAKER_01Yeah, you're probably right. deep research temporal and i think the server is running over here yep server's running there and if i run this and i have not got uh excuse me it's a valley key there that i will put in um I better go and reset that after this. And that will then go and run. Just one thing while we were, oh, yeah, that's the traces from Logfire as that's running. I come over to live here.
SPEAKER_01You should be able to see the deep research agent running. What exactly is going on? I just mentioned when we're talking about keys, you'll see that the previous examples I ran Here, the model we were using always was prefixed with gateway. This is how we use Pyland's AI gateway, very simply. So we just have to set one gateway key where we can control limits, and then we can use any model with the one budget. So I would encourage you to go and sign up for Pyland's AI gateway, and that will have to put a card in if you want to use our inference, or if you don't want to, you can put your own keys in and,
SPEAKER_01again, use one key to access all of the major models. But while that is running, I will cross my toes that it's going to give the right answer,
SPEAKER_00but we will see what it says. Yeah. And while that's running, I'm wondering if you could just to speak to, and we've spoken about this implicitly throughout, but how this type of durable execution just relates to, you know, builders concerns such as memory and context engineering and all these things that we're trying to figure out at the moment.
SPEAKER_01I think that it's relatively orthogonal. I think that one of the problems you run into, oh, we've got the answer. Oh, and for once it gave the right answer. Fantastic. So that's good to know that it's right. Amazing. If you went through, yeah, so it recommended Landgraf second and Temporal on its own third. I have no idea whether Microsoft Agent Framework does a good job.
SPEAKER_00I would guess not. so i've just discovered these new sounds we can have here i feel like 70s dj thank you very much indeed uh yeah and you can see the full plan that it obviously gave a long report here where it's gone through the different options yep maybe our work
SPEAKER_01on geo is beginning to work again because this is this last week but um Yeah, you'll see it's done a pretty good job here of summarizing. Memory and context. I don't think that it's, I think it is a kind of orthogonal concern. I think the power is that you get to worry about building your agent and the like durability is for the most part, you write this kind of bunch of ceremony to set up. your agent, your durable execution framework of choice, and then you can get on with building your agent and not have
to worry about that
SPEAKER_01kind of like infra side of things. Yeah, that's a really good. If you're using memory, sorry to interrupt, if you're using memory via tools, you will want to have your tools set up as, I think they're sharing my screen quickly. I'll just show you the full run here. Where did we get to? We had the last agent was the... no here we are analysis agent and yeah you can see here in logfire the full report that we got out as well as a summary of it here i'll stop sharing my screen so i
think there are things like you know if you're implementing memory via tools and you're going to go and store your memories in a database you're going to need things like tools to be activities not doing so would mean that approach would not work any other regards you go was there anything particularly you were thinking of
SPEAKER_00that i've missed where they overlap well yeah i was just thinking if one of the concerns is we lose all state and essentially when we think about memory or context engineering we're offloading and isolating and like writing stuff to different places for context so of course temporal solves all of this but we may be able to recreate current state if we're using these kind of more advanced ways of thinking about context
SPEAKER_01Yeah, it definitely makes it a heck of a lot easier to go and have multiple different agents that have their own individual tasks where you can choose what model they want to use, where you can control what they have in context much more easily than if your durable execution concerns require you to have a single agentic loop or a single graph in the sense of if you're still thinking that the right way to build agents is with graphs like that kind of thing makes sense i am wondering do you have a few more minutes i know we're going to stop at around quarter two yeah i can do i can
definitely do another five minutes sounds great i'm wondering could you just speak a bit more to how it
SPEAKER_00helps developers think less about infrastructure Yeah, I mean, I think if you were to go and set this up,
SPEAKER_01let's ignore the alternatives out there. And we're going to go and set each of these things up as an individual task. Now I'm going to need to, you know, you take the 20 questions example, which is very simple. We just call this tool in a loop. We can no longer do that if we want to do snapshotting at each one. We need to have implement our agentic loop directly. And we need to basically have Basically, you would run each individual tool call as a single task, which would then put a new job into the task queue, which would then be taken out of the task queue and run. And that would then mean that we would basically be able to
store our state. A bit like the kind of climber climbing up the hill and inserting the thing into
SPEAKER_01the rock at each step, so if they fall off, they don't fall too far. You would need to do the same thing, basically... stop yourself from going back to the beginning by storing the intermediate results so that we can resume. With durable execution, that is effectively taken care of with this very elegant activities versus workflow distinction.
SPEAKER_00Awesome. I'm also interested, does it, the developer experience you showed seems really seamless. I'm just wondering if there are any costs? We need to think about... I haven't... I don't know the exact cost of Temporal.
SPEAKER_01I feel more and more like I'm a sales guy for Temporal. I haven't looked at them. I didn't show you DBOS today just because I didn't want to go into it, but DBOS is another option, and that is backed by Postgres, so you would just be using Postgres as your store of state. I suspect that any of them, if you set them up right, the tokens you can save by setting up your context and your agent... ontology correctly will save you many times what the durable execution stuff costs super cool maybe to wrap up i'd love to know i mean you've been building so much
exciting stuff for builders and developers i'm wondering what's exciting for you
SPEAKER_00and what what are you thinking about next So we are working on managed variables, which is our take on prompt management. But the point is that actually to control an agent, you want more than just that one string.
SPEAKER_01So managed variables are basically a way of, it's a bit like context files, but you can be managed externally in log files. So you can have your system problems, but you can also have temperature and which tools are registered all set up as part of your managed variables that you can then go and think of ways change in development, run your evals against them and see how that changes performance. I think this prompt playground way of doing evals doesn't work that well because ultimately if your agent's complex enough that it needs tools and it needs specific
SPEAKER_01responses from those tools, the only way to set up a really like version of your agent is in your own environment, staging, production, whatever. And so I think managed variables are going to be a really important step of that. And then twinned with them, we have prompt optimization or agent optimization coming. We'll be using the JEPA library. It's the kind of new exciting stuff doing the DSPY kind of thing, but doing it in a hopefully type safe and more engineering rigorous ways than DSPY. Those are the things coming in in Logfire and Pydantic AI.
SPEAKER_00Super cool. And to your point, I mean, prompt playgrounds can be super fun, but I mean, I don't know anyone who uses them seriously because they are so decoupled from what builders build. I agree with you. I think there are those who have,
SPEAKER_01look, I've heard from some customers that they're useful in some places. Maybe I think it wouldn't be too hard for us to add a very simple like prompt space in to plan to get our gateway. How useful that really is? Good question. We may have to build it, but it's not that much work to do now that we have the gateway. So now that we can basically use whatever model you like.
SPEAKER_00Yeah. So a bunch of people in the chat are super impressed and particularly the restarting from where it stopped and crashed. We can punt this question as well, but Wilma has said she's been a big fan of Langraff, may not be anymore after today with a laughter emoji. I think you've spoken to this with respect to durable execution, but Wilma has asked, are there any other obvious advantages of using Pydantic and Temporal and Logfire over Langchain, Langraff, Langsmith ecosystem when deploying agentic systems to production?
SPEAKER_01One thing I think it's worth just mentioning, I'll share here quickly. We do in fact have, although I don't always think graphs are the right answer to all questions, we in fact have, we've had Pydantic Graph for some time and we have a new, what we call beta API, which is much more like functional API for graphs. where you get something much more similar to a land graph, but compatible with temporal. So you can basically run your graph as a workflow and it can call agents within
SPEAKER_01nodes, which will then automatically become activities. The main difference is that this is all type safe. David and Dauer who've worked on this have worked incredibly hard to build a system where basically if you see like we'll have the input type for this graph, where's a good example. Basically the inputs and outputs of connecting nodes have to be type safe. And so you get much of the land graph stuff, but it's type safe and that we get, we can get parallel node execution, but those graphs, those nodes are run by temporal or something.
SPEAKER_01And so you're, you're not having to, we can't maintain type safety whilst having parallel node execution. That was a slightly different question, but I thought relevant, a relevant point.
SPEAKER_00Yeah.
SPEAKER_01What was the, what was the other thing you were asking? Any other advantages of using the Pydantic stack over Langchain and the Langstar ecosystem? I think the number one thing is type safety that I've mentioned a number of times and will continue to bang on about. Secondly, I think the durable execution stuff that we've talked about. I think there were lots of other nice-to-have things that individually don't make much difference, but sum up to be pretty valuable. We have 100% code coverage. All of the examples in our documentation are run as part of CI, as part of unit tests.
SPEAKER_01So you won't have examples that are out of date. I think that we're moving pretty quickly, adding some really exciting stuff. I think we come from an open source background. We maintain infrastructural bits of the Python ecosystem, both within the company and as a team. And I think, bluntly, the caliber of open source that we're doing is better than other people. That's obviously more subjective. I think the first two points are a way you can be objective. I think we come from structured outputs are obviously our bread and butter with Pydantic. We have support for multiple different ways of doing structured
outputs in Pydantic
SPEAKER_01AI, which I think sets us apart from some of the others.
SPEAKER_00Great. And the other answer is, of course, go and experiment with yourself and see how you can instrument everything with Logfire and all your evals.
SPEAKER_01Yeah. What we find is once people find financing AI and get using it, they don't go back. But of course, there'll be some people who find other things useful, and that's fine. That's why, luckily, there's lots of choice.
SPEAKER_00Yeah, exactly. Well, as always, Samuel, I appreciate you coming in and speaking to the course. And I appreciate, once again, all the credits. You've been so generous, you and the team, in provisioning for all the students. So thanks. No problem. Thank you so much. It's a pleasure. Nice to see you. Thanks for tuning in, everybody. And thanks for sticking around until the end of the episode. I would honestly love to hear from you about what resonates with you in the show, what doesn't, and anybody you'd like to hear me speak with, along with topics you'd like to hear more about. The best way to let me know is currently on LinkedIn and I'll
put my profile in the show notes.
SPEAKER_00Thanks once again and see you in the next episode.
Hilary Mason, CEO of Hidden Door, works with agents across software development and creative projects. Drawing on Richard Hamming’s distinction between science and engineering, she describes agents as “bringing the...
Agents can write the code, run the analysis, and produce a convincing explanation. How do you check that they’ve answered the right question, used the data appropriately, and reached a conclusion you can act on? I...
“It’s an LLM, a loop, and enough tokens.” - Nicolay Gerold, Amp Code So why does a coding agent forget your instructions, keep reading tiny pieces of a file, or struggle with an edit another model handles easily?...
“If you feel that a product is hard to eval, or you feel like, ‘I don’t even know how to eval this,’ it’s a strong smell that your product isn’t good.” - Hamel Husain, on AI product design An AI data agent tells you...
“It would be sad if local models were not an option and there were only proprietary models. It’s good to have alternatives. Competition is good for business.” - Sebastian Raschka, on open-weight AI Kimi K3’s weights...