Video: Agent Harnesses & Deep Agents 101 | Duration: 3219s | Summary: Agent Harnesses & Deep Agents 101 | Chapters: Agent Harness Fundamentals (0s), Harness Components (640.8s), Deep Agents (772.1449999999998s), DeepAgents Benefits (946.0990000000018s), Human in the Loop (1206.3290000000018s), Interactive Poll Session (1408.6790000000015s), Poll Results Review (1428.1940000000018s), Sub Agents (1493.3440000000019s), Production Ready Agents (1769.754s), Demo Setup (1963.6589999999978s), Configuring the Harness (2224.268999999998s), System Prompts (2479.158999999998s), Custom Tool Definition (2621.303999999998s), Agent Memory Management (2807.808999999998s), New Chapter (3212.754s)
Transcript for "Agent Harnesses & Deep Agents 101": Alright. Hello, everyone, and welcome to the DeepAgents workshop. We'll get started in just a moment. We have a icebreaker poll question for you guys to think about. Would you pay $60 for a loaf of rye bread? That's, like, 50 some euros. The votes are overwhelmingly in the no section, which is, kind of the opposite of what I voted. I said yes. Maybe I'm crazy. Okay. We'll give another couple of seconds, and we'll get started very momentarily. So thank you so much for joining for this agent harnesses and deep agents workshop. My name is Ishaan. I will be guiding you throughout the session, teaching you all you need to know about deep agents and agent harnesses by the end of the session. You should be a master in them and hopefully, get your hands on some of these deep agents and start playing around with that. So without further ado, we'll jump into it. So these sessions, for today is going to be pretty simple in terms of structure. I'll spend the first dozen or so minutes talking about what deep agents are, discussing harnesses, kind of going over all of the theory related to it. Then in the second part of the session, we will go through a deep agent. So I have some code written up. I'll walk you through it, explain to you how I go about going from an idea to an actual deep agent. You will also have the opportunity to take, work on a take home exercise on your own time where you will be able to build your own deep agent from scratch, so take your own idea and create your own deep agent. And then at the end, time permitting, we will do questions and answers. If you have questions throughout today's session, completely okay. I encourage you to ask questions, though it's probably best to use the Q and A tab. So you might see next to your chat tab a q and a tab. That's where you should ask the questions. We have two wonderful assistants backstage, Jezell and Marta, who will be answering your questions. So feel free to drop your questions there. They will hopefully get around to it. And, yeah, that's all you need to know. So let's start talking about deep agents. So before we even get to deep agents, we'll start with the primitives. So we'll first define an agent, explain what that is, and then a dive into what a deep agent is. So one definition of an agent is a model calling tools in a loop until it completes a task and returns a result. So you've probably used claud in the web or chat g p t, and sometimes when you ask it a question or some sort of prompt, you see a little ticker before it gives you an answer, and that ticker is explaining what it's doing. Maybe it's searching the web or writing a file or reading a file. That's kind of what we mean by tools, these extra operations that this that this agent is performing. But at the core of everything is your large language model. And so the model in tandem with the tools work together to accomplish a task. So what this looks like visually is you start with your input, which is the query or whatever question you're asking the, the agent, and the input gets passed into a model. So at the core of your agent is a model, large language model, something like Claude sonnet five or GPT six. So the query goes into the model. The model has a suite of tools, so the model may decide that, okay, in order to process this query, I need to call a tool, so it will call a tool. The tool executes and the result of the tool gets fed back into the model. The model can then process the result, determine if it needs to call more tools, and if so, it will call more tools, and back and forth this goes as a loop until eventually the model decides that it's done working and it has an output or it has an answer to your query. So once the model determines that, it provides the final output, the final answer, and all is good. So this is one picture, of what an agent is. It is a model calling tools in a loop until it completes a task. And so the tool is part of something called a harness, and we'll define what a harness is in just a moment, but tool is one aspect of something called a harness. And so to dive into what a harness is, we can revisit this question of, like, what is an agent? And another equivalent way of answering this question is to say that an agent is a model plus a harness. So kind of embellishing the definition from before where it was model calling tools in a loop, we're gonna say now an agent is a model plus a harness, and a harness is the scaffolding around the model. So part of this, part of the harness is the tool calling capabilities, but there's a little bit more to a harness, which we'll dive into. So to visualize what this looks like, in the center of your agent is the LLM, the model. That that stays the same as always. There's always gonna be a model at the center of your agent. But on its own, a model stand alone can't do too much. It is large language model. We've heard it be called, like, a word guessing machine. A model on its own can probably solve some basic tasks that are shorter, but the moment we start asking it some more complex tasks that are longer horizon, a model on its own starts to struggle, and it's less likely to complete the task how we want it to. And so that's where the harness comes into play. The harness is what surrounds the model. So these are these are aspects of the harness, some of which include tools and skills and system prompt and sub agents and so much more. All of these things are meant to enhance the capabilities of your agent existing. Because as we said, a model on its own can't do too much. But once you give the model access to tools and access to skills, and, hopefully, it interacts with these things appropriately, now we expand on the capabilities of this agentic system. Now we can start to solve some more complex problems, some long horizon tasks. So that's that's why the harness is so critical. And so all of this combined is what makes an agent. So with that in mind, we have a poll question for you, just testing whatever I just covered. So Jezell is going to launch a poll. You should see a poll tab up here to the side. So you can read through that question, give it your best shot of your answer, and we will debrief in just a moment. So I'll give you a second a couple of seconds to think about it. Cool. So the question, what is the definition of an agent? There's a few definitions that we went over. So, the answer we were looking for should be model plus harness and model running in a loop with tool access. Both of these are definitions of an agent. James Bond is also correct. So if you take that, that's completely fine. So those those are the three answers that we were looking for. Models like Claude sonnet five is an incorrect answer. That on its own is just a model, so it's missing the harness surrounding it. So Claude sonnet five would be something you would see at the center designated by, like, this pink robot. So that on its own, just a model, not an agent. Excellent. Let us move on. Great work with that poll. So we have our agent model plus harness. Likely, we want a good harness because a good harness would be a good indication that we have a good agent. And so you have probably seen the means about just asking Claude or chat gbt to just make no mistakes, but it's not enough to just tell the model this. A good harness is actually supposed to enforce the behavior we want so that it actually makes no mistakes. And so to crystallize what the job of a harness is, we want the harness to make sure the model makes the correct decisions, and it should do this by giving the model the right context at the right time for a given task. With just an LLM, as we said before, you're missing a lot of the support structures. So the moment you give your agent a much more complex task that has a bunch of subproblems, so to speak, we want our harness to provide the correct information, the correct context, so that way the model can focus on what it needs to and then progressively work through this complex task. So that's the job of the harness, give the model the right context at the right time. And so the harness provides many things that improve your agent over time. With all of those support structures, like tools and sub agents and memory, there's a lot of byproducts of it, and these all improve your agent. So agents need to work in an environment where they can take actions. They need to connect your data, need to manage growing context over long runs, parallelize task, connect with the human in the loop, and so much more, all of these to improve your agent over time. And these are all things that come with the harness. The harness should be able to provide all of these things, so that way your agent can accomplish this and complete some more complex tasks. So with that in mind, we will launch another poll question asking you about what a harness is. So that will be launched momentarily, and I'll give you a minute or so to think about it. Okay. We will bring up the results of the poll right now just to see how we answered. Excellent. Okay. So I'm seeing 27 votes for the first, 82, 85, and 64. So the correct answers, in particular, we were looking for the second and third option, though the first one is also correct. So let's just quickly go over this. Yeah, the last one is a little bit tricky to establish guardrails for your agent. What we mean by this is like specific rules that it should follow. There's an argument to be made that maybe this is part of the harness, that maybe you include this within your system prompt. But when we look at the actual job of the entirety of the harness, it would be to provide the model access to tools, memory, and system prompts. So, again, these are some of the components of what a harness is. Additionally, to give the model the right context at the right time for a task. So remember, we want we need the harness to solve these more complex tasks. The harness is there to provide that support, provide the context to the model so that, like, can accomplish these long horizon tasks. And, to safely connect a horse to a carriage, sure, maybe there's a little bit of humor involved there, which isn't the most funny thing, but, there there is an analogy to draw. There is a parallel to draw that a harness with a horse is to draw this connection, and the horse safely guides the carriage. And in a similar way, the harness in an agent is meant to safely guide the model to the correct, to the correct answer. So there's there's this connection involved between whatever is driving the agent and all of the support structures, so that way, them together reach the desired destination. Excellent. Good work with that poll. We will jump back into the presentation. Okay. We are back. So that brings us to what is deep agents. The past few minutes, I've been talking about what agents are. We've very well defined what an agent is, model plus harness, but the whole point of this session is deep agents. Now it's time to talk about deep agents. So what are deep agents and how do they fit into all of this? Deep agents are still agents. They are still a model plus a harness. But what makes them deep agents in particular is the fact that, for the harness, we are using something called the deep agents harness. So the deep agent's harness is Langchain's opinionated harness. What this means is that our engineers have built up features with the best practices, so that way you don't really have to focus on the durability and how good the harness is. That is already taken care of for you. You can focus more so on your business logic, like the queries you ask and the skills that you define and so on and so forth. All of the harness and all of the components of it are taken care of for you by the deep agent's harness, and so that's what deep agents are. When you define a deep agent, you get the deep agent harness with you. And so another way of defining this is to say that deep agents are a customizable agent harness purpose built for complex real world tasks. So to highlight the difference between what a deep agent is versus an ordinary agent, an agent on its own, you would be responsible for defining the harness and creating all of the infrastructure and components, that relate to that harness, and you would also have to determine how your model calls the harness and how it interacts with the harness. With the deep agents, the deep agents harness is already configured for you, so all of that design has been taken care of, and how it interacts with the model has also been taken care of for you. So with deep agents, you don't have to define the harness on your own. With that in mind, let's throw out poll question number three. So another one back to back to back. We'll give another minute to think about it. Excellent. 90% of the votes for, the first option and 10% for the other one. This is great. So, yes, the difference between an agent and a deep agent, as I mentioned before, with deep agents, that comes with the harness that we have built, the deep agents harness. You don't worry you don't need to worry about having to build that yourself. With regular agents, non deep agents, the harness may not be configured for you, and that might be something you would have to define and create yourself. Amazing. Excellent work. So let's dive back in. Alright. So why should you use deep agents? Beyond the fact that you get the harness with it, there's a lot of other byproducts that make deep agents an appealing choice. So first of all, deep agents are provider agnostic. So new models are coming out all of the time. It feels like every other day, there's a new model coming out that claims to be the best. I think what we just heard about, like, GPT 6.1 released yesterday, and a couple of days ago, it was SONNET 5.5. A few days before that, it was Ophis 5.5. It's hard to keep track. Each one claims to be the best, and who knows? Tomorrow, a new model is gonna come out, and it's gonna beat all of the other ones. Maybe maybe Gemini is gonna come out with something. We'll see. The point is, as these new models come out and each one claims to be the best, you likely want your agent to be able to swap in and out whatever model you wish, so that way your agent can be as good as possible. Moreover, it's helpful to be able to swap models, so that way you can determine what model is best for the agent you have at hand. So that ability is really important, and deep agents provide that. Since they are provider agnostic and model neutral, you're able to switch models and test them out on your own with just a few lines of code as change. Without DeepAgents, if you're using some other SDK, you would have to likely rebuild your entire stack and rebuild everything if you were to change model providers. So this is one of the many appeals of deep agents. Deep agents are also highly customizable. So we'll dive into the anatomy of a harness right now. So thus far, we've kind of highlighted some of the components of a harness, but there's so much more to it. So first part of the harness is the execution environment. So this includes things like the code interpreter, sandbox, and file system, which are there that allow the agent to take actions and connect to your data. In addition, there's this whole notion of context management, which includes skills and memory, summarization, context offloading, and prompt caching. When we think about what the job of the harness was to provide the model the correct context at the correct time, these are the scaffolding that are responsible for doing that. The skills are there, and that gets passed onto the model, and so on and so forth. So these are really crucial for long running agents. And there's also a notion of delegation capabilities. So as workloads increase, work needs to be distributed and planning and sub agents help with that. And so when you have a very complex task, maybe you don't want your agent to start executing, immediately. Maybe you wanted to devise a plan first and agree on the plan and then work from there. So that's what we mean by planning. And then sub agents, we'll talk about momentarily, but this idea of handing off smaller tasks to individual agents to kind of delegate the work off to them, and then they report back their findings. So that way context gets managed a little bit better. So these are also things that are part of the harness. And also middleware, this is a really big thing, and one aspect of it is human in the loop, which we'll talk about in just a moment, and the idea of human in the loop is to gate sensitive tasks by human approval and feedback before they execute. And so we'll touch on that momentarily, but there's a lot more to middleware. And the important thing I wanna highlight here is all of these things are part of the harness. As I said before, deep agents, the harness is created for you. So all these things have been taken care of for you. Without the deep agents harness, you'd be creating a harness on your own, so you would have to figure out how to configure all of these things like skills and memory and planning and sub agents, which is a lot of work. But since DeepAgents is open source, it is fully customizable. So if you use the DeepAgents harness, that's not quite where you need it to be for your particular use case. You have the ability to go in and make tweaks to the harness yourself and improve it for your agent. So it being open source is another great appeal of deep agents. So I'll dive into some of these aspects of the harness, in just a little bit more detail. So we'll talk about human in the loop first, and this is one way to customize your agent. So the idea of human in the loop, as I mentioned before, is sometimes your agent is going to complete some sensitive tasks or sometimes it's going to do some stuff that you really want to have your eye over, and you want to approve or reject the actions before the agent does that. That is what human loop is. So the picture is very similar to before of how an agent works. You start with your input. You start with your query. Just as before, that gets handed off to the model. And as before, the model is going to work with a set of tools working in a loop. So the model might decide, I need to call a particular tool, like delete file. This is likely a sensitive task that you want your eyes on before it executes it. You don't want your model or your agent to delete a file that is particularly important to you. So that's where human in the loop comes into play, that with human in the loop configured, you can add this little gate in between the model and the tool. And when the model decides to call this tool, it's going to ask you, like, hey. Do you reject or approve this action? So you can choose to reject it, or you can choose to approve it. And when you approve it, everything occurs as normal from before. The tool executes, so the file gets deleted. The result gets passed back into the model and so on and so forth. So the loop would continue until eventually the output is provided. We'll go back a second, but if you chose to delete or sorry, if you chose to reject the tool call, then that tool would not execute. So the delete file step would not occur. You might do this when it's deleting a particular least sensitive file. So it is giving you that option. It's giving you the oversight and the control before it completes a particular task. So that's what we mean by human in the loop. Okay. So that's the entire picture. Same as before, just now we have this human step in between. And so human in the loop is an example of middleware. Middleware is a broader category and human in the loop is just one example of which. So the more accurate definition of what we mean by middleware is hooks that allow you to customize behavior in the agent loop. So deterministic segments of code or deterministic commands that run at certain points that you specify within the agent loop. And so you could insert these hooks before an agent. It could be before a model occurs. It could wrap a model call. All of these are potential middleware options. This is the entire agent loop, and you can fire middleware anywhere in between. And so for human in loop specifically, that wraps a tool call. And, again, these are, like, deterministic things that fire at particular steps. So human in loop will always execute wrapping a tool call. And so as you can see here, human loop gates the tool call. We are dictating whether or not something should or shouldn't occur. And like I said before, this is one example of middleware. We can insert middleware at any point in the agent loop. So with that said, you know what time it is. Another poll question, hopefully, will be launched. I'll give you some time to think about this, and we will reconvene. We will kill the awkward silence because it's awkward, and let's take a look at the results. Wow. Okay. The overwhelming majority of people voted for option number two, saying that human in the loop is an example of middleware that pauses execution before a sensitive tool runs. Exactly. That's exactly how we just defined it. That is the correct answer. Yeah. The first option could be a little bit sneaky. A tool of the model decides when to call to ask for approval. Kind of, second option is better, and the other two are not the case. So, yeah, the human in the loop is not part of the system prompt. This is middleware. If you were to include this in the system prompt, there is not a guarantee that it would fire. We would like to hope so that the agent will always follow what the system prompt says. In practice, that's not always the case. So the nice thing about middleware, deterministic. So it'll always fire, wrapping the tool call in this case. And no one voted for option four. Excellent. Okay. We will dive back into things. Alright. So we just talked about human loop, so that's one aspect of the harness, plenty more to it. So the next one that I wanna talk about is sub agents and how sub agents work. So the idea of sub agents, as I hinted at before, is this ability to hand off particular smaller tasks to other agents, so that way they can handle the work for you and you don't really have to worry about them. So the analogy I like to draw here is I think about my mom, and my mom is a very busy person. She has a lot of stuff going on. Right? And at home, there's too much to worry about. And so sometimes, she just needs to hand off work to me and my brother. So maybe I have to, like, set the dinner table, and my brother has to wash the dishes. So she delegates that work to us. We work on it on our own. She doesn't need to worry about how I lay out the plates or what soap my brother is using for the dishes. The point is the work gets done, and we report back, and she can carry on worrying about everything else. And ideally, the work does get done. Knowing my brother, those dishes never get washed, and he makes me do it. But I think that's just how families work. So let's talk about sub agents pictorially. It's it's a very similar image to before. We take the input, pass it into the model just as before, and now the model might decide that, like, okay. I have this context window, which is some sort of capacity, and this contains a lot of information maybe that has occurred in the past, so past history, noise, or tool output from previous calls. And so this context window is finite, and that's kind of like its short term memory, so to speak. And as that context window fills, the model will gradually decline in accuracy and recall and reasoning quality. If my mom had to worry about doing the dishes and setting the table and a bunch of other stuff, her performance is going to degrade as well. So that's kind of the idea of the context window. That's something we wanna manage quite well. So this is why delegating the sub agents, these mini assistants, is super useful. You can take the work that needs to be done, hand it off to the sub agents, and they'll work on that, And that's because these sub agents have their own separate context window. They have their own area of things that they can be aware of. I only need to pay attention to, setting the table, and my brother only needs to pay attention to doing the dishes, which, again, he's not going to do because I know him well enough, but we have our separate context windows. We also have our separate tools. So, again, we can take these individualized tasks and do them ourselves. And so a better example, instead of doing the dishes, is maybe you have an actual agent that is a newsletter agent, and this newsletter agent is responsible for putting together an entire newsletter every single week. So you have your outer agent that is responsible for putting together the newsletter, but you might have these sub agents that focus on a specialized task. Maybe one of them scrapes the web for articles, another one scrapes video information. And so these work on their own. They have their own respective tools. And since they are agents, they work in the way an agent does. They have their own model, their own set of tools. They operate in a loop, they complete their respective tasks, and they pass their final results back to the model. The model doesn't need to know the outer model doesn't need to know the nitty gritty of which tools and sub agents that the sub agents called. That's not relevant to the bigger picture here. The only thing that the outer model agent cares about is the findings. What did the video scraper find and the web scraper find? So that information gets passed back to the outer agent and it works with that until it eventually produces an output. So the nice thing about these sub agents here is that since they're working on smaller and more specialized tasks, you can often give them a cheaper model to work with. You don't necessarily need to be using a flagship model for these sub agents because of the smaller scope of them. And so this is really good because it can save you a little bit of money if you configure your sub agents with a cheaper model. And so that's what we mean by sub agents. And the last thing I wanna highlight is how deep agents are production ready. So there are a lot of things that people want out of their agents, but there are these kind of come together in a few particular categories. So we want our agent to work with real data durably, and the deep agent harness supports this, by using virtual file systems. Additionally, agents should be able to write and execute code, and for that, we provide sandboxes to do that. Further than sandboxes, we provide, we provide file system permissions and middleware hooks so that there are multiple safeguards. Human in the loop is one of them, which we just looked at. And to ensure agents remember and access knowledge properly, we have memory, skills, and MCP. Again, all of these included in the deep agents harness. And to complete long horizon work, we have built in context management techniques. And finally, to optimize for provider and model choice, deep agents ships harness profiles. So all these things we want out of our, agents, they are all taken care of for you by the deep agent. But when we think about going to production with your agent, that is almost an entirely different beast. You can get an agent working really well locally, but taking it to production introduces a lot of new challenges, things like authentication or having a studio to work with or having a task queue and run cancellation, durable execution, so many things you need to think about. And so deep agents out of the box work well with these production concerns, but the way that they are resolved is through something called managed deep agents. So these are special type of deep agents. I'm not going to dive into it so much today, but I'll give you a brief teaser and a brief overview. So managed deep agents are these special type of deep agents that handle the production concerns for you. So the argument or the idea behind this is, as we said before, there's a lot of things we want out of our agent, like code execution and having appropriate models and tools and context, but each of these has its own related infrastructure or product, for example, sandboxes for code execution or an LLM gateway for models, so on and so forth. When you take an agent to production, you need all of this infrastructure. You need it hooked into your agent. Managed deep agents kind of bundles all of this together. So you can create a managed deep agent, and you can deploy a managed deep agent in just one command, and all of this is taken care of for you. So the entire harness is there for you, and all of the infrastructure related to it, sandboxes and gateway and so on and so forth, that is taken care of for you as well. It only takes, like, two or three lines of code to set up at the very basic sense, and that's the appeal of managed deep agents. So, again, special type of deep agents, but that's just a brief overview. I'll touch on it a little bit more at the very end of this session. Okay. I have been talking for quite a bit of time. That covers the theory part of things. We're now gonna jump into a demo where I'm going to walk you through a deep agent that has been built and show you how you would define things and how you would change things on your own. So there's a QR code here. You can scan it and get your own copy of the Colab notebook. I recommend that it's probably easier to just follow along with what I'm doing. You don't need to do code on your own time. You can just watch me as I walk through it. You will be able to access this after the session as well on your own time, so don't worry about that. And there will also be a separate take home assignment that you can play around with on your own, to practice your skills, and that'll, you know, that'll be provided to you as well. So for now, you can just watch, as I walk you through it. So let's do that. I think let me just unshare the screen, and then share again. I think we can go here. Brilliant. Okay. So this is this is the code notebook that I'm working with. We are going to be building a deep agent that is a journaling agent. Let me zoom in a tiny bit so you can see a bit better. Okay. So the idea of this journal agent is we want a way to communicate with our agent and, give it the ability to log and read journal entries and tag their mood, remember conversations, etcetera, etcetera. So ideally, just wanna talk to my agent, give it some notes about my day, so on and so forth, and it should maintain this journal for me. So the first bit of code here is just setup, so, you know, I'll just go over that. We're just installing dependencies here, so deep agent, slang graph, and some other stuff that we will use as part of constructing this deep agent. So these are all dependencies. If you run this on your own time and you do get this error, don't worry about it. Don't need to it's it's not gonna affect anything. So these are just the dependencies we need. And now we're going to set up our model. So as I've said, like, 300 times by now, at the center of your agent is a model. The model's at the core. We have our harness wrapped around it. So we'll start by defining the model part of things, and then we'll add the harness around it, and it's all going to be super easy. So these two cells are where I am defining the model. So the actual definition occurs down here where, we are doing init chat models, this function, and we specify the model we wanna use, in this case, anthropics claudsonnet5, and pass in an API key. To ensure that the API key is appropriately set up, how this is being obtained is up here. It is reading a secret called anthropic API key from user data. The way you get this configured when you do this on your own time, there's a little key off to the left hand side called secrets. If you click on that, you can specify a secret. So I've already done this. This is called anthropic API key. That's why it's reading the anthropic API key value here. And over here is the actual value, which I will not expose because I don't want anyone stealing it, and enable notebook access. So that's how you get your key set up there, and this is how it's being read in. So we define the variable, and this is just setting up the model. We don't expect any output because we're just setting up the model. Like I said before, deep agents are model agnostic. You don't have to use an anthropic model. You don't have to use anthropic as your model provider. You can use a different model provider and a different API key. And the change is very simple. So if you wanted to use OpenAI, you just need to change these values up here. Use OpenAI API key, change the API key down here, and change the model. So here, you might choose to use GPT six with an open AI API key. You also need to make sure you use the correct name here. Everything should match. But that's that's really the the great benefit of deep agents. You can swap out these model providers with just a few lines of code. Nothing else, none of the rest of the code needs to change. That all stays the same. These are the only lines you would change. Cool. Okay. That is setting up the model. We'll now talk about setting up the harness, which is equally simple. So here's the diagram we saw before. Pink circle is the model. That's what we've just defined. The harness is everything around it. And so okay. I'll just skip over that. The harness is configured just like this. We're going to say, okay. I want my agent to be a deep agent, and and we're gonna use the model that I specified before, which is the, you know, cloud side of five or whatnot. That's all. That is creating your deep agent. So with that line of code, this agent is now the entity that is model at the core plus harness around it. This create dev agent provides you the harness around it. So we can run that. And now let's interact with our agent. We have the agent defined. We can ask it a query. So this is going to be my first query for this journaling agent. So start a journal. Md file, log a new data entry with today's date, and here are my notes about the day, that what I learned today that a caching bug was hiding in the retry logic for whatever I was working on. I feel relieved to ship it, a little anxious about production traffic. And what's next? I need to write better tests before touching anything else. So we're gonna ask our agent to journal this and then read the journal file back to us. So that's our message. We will invoke the agent by this dot invoke, command and pass in the message, And I'll let that run and let it print out what happens, and I will stall because it takes a couple seconds and we're done. Excellent. So there's a lot of stuff here. It's a little intimidating, but this is this is very intentional, everything that's going on in here. This is showing exactly what went on within the agent, all of its inner workings. So we're going to see that that agentic loop that we showed in the slides before, we'll see that in action right here. So the first thing that happened was it has the human message. This is what I set in. This is the input. That gets given to the model. So the model receives that message, and it decides, do I need to call any tools? And in particular, it did call a tool. It called the write file tool with, the file path being journal. Md and the contents to write to the file. So this is the journal entry that it started to write, what I learned today, how I felt, etcetera, etcetera. So that's the tool call. The tool call completed, it said that it updated the file journal. Md. That gets passed back into the model, so we're going through one step of the loop. The model again decides, do I have to call any tools? And in this case, it decides it does. It wants to call the read file tool, reading the journal. Md file. And so it does that. It reads the file. This is the contents of the file that it just wrote. That goes back to the model. The model decides, do I have to call any more tools, or can I provide an output? In this case, it provided the output. It said it was done with the tools, and here is the final message. So this is what this is the message you would see if you were just talking to like a chatbot per se. So I've created the journal. Md with your data entry. Here's the content. This is the content that it journaled before, so on and so forth. So that is the thing I wanna highlight there. That that is the agent loop in action, and, yeah, just visualize out. One thing I wanna touch on. Maybe maybe the eagle eyed saw that, okay, the agent is calling write file and read file as tools, but we never specified these tools. We never defined these tools. How is it calling these tools? Excellent question. This comes with deep agent's harness. As part of the harness, some of these tools kind of come for free because these are actions that the agent takes quite often. So refile, write file comes for free. We don't have to specify that. For further, more complex commands, those are things that we would define, and we'll define tools very shortly. So that was that. We'll now set up a system prompt. So a system prompt is a string that controls how the agent behaves on top of whatever instructions or facts that you give it. So this is information that the agent will receive at every turn of the conversation. You should include in the system prompt the important information that you always want your agent to be aware of. This could be things like branding guidelines or branding voice or just generic facts and information that you want it to kind of always be aware of. So a nice example to demonstrate this is changing the voice of the agent. So in particular here, I'm going to tell the system prompt to act as a melodramatic Victorian child and narrate everything with excessive despair and flowery dramatic language. That's the system prompt. That's what I want it to always remember. We can define the agent in the same way, create deep agent, provide the model, and now we'll pass in the system prompt. So, again, just defining a deep agent. And now we'll provide another message. So it's kind of the same message of the journal entry. These are my notes, and then read the journal entry back to me, invoke the agent with the message. I will let that run. And ideally ideally, the agent should come back to me with this flowery Victorian era child voice. And so we will see how it responds in just a moment while it's done executing, which should be now. Excellent. So there is a lot of stuff here. Again, you can read through this. This is the same exact agent loop from before, pass the message in, give it to the model, model decides to call the right file tool, so on and so forth. And eventually, it, responds, clutches lock it, sniffling pitifully. There it is, dear diary, laid bare for all the world to pity. Let me read it to you now through my tears. Sounds like me every Friday night. But that is that is kind of what we're doing here. So the system prompt was read, and now it always responds like this, Victorian era tile. So there you go. You might use it for branding voice or just generic facts. That's the purpose. Okay. I'm going to reset the system prompt because I cannot I cannot be concerned about this drama all the time. I have enough drama to worry about. And we'll move on. So now we'll talk about custom tools. So we saw tool calls already. We saw read file. We saw write file as tools. Those aren't the only tools you want. Sometimes you want tools yourself, so you can define tools pretty simply. And they have a very particular anatomy, which is easy to work with, but it is quite important. So here I have this word count tool that I've already defined, and I wanna walk you through the anatomy here. First things to pay attention to, the name of the function is word count, and this docstring describes what it does, counts the words in a piece of text. These two things are quite important. Whereas programming before agents, you would just name your function whatever you wanted. This stuff actually matters because that's what the agent is going to look at to determine which tools it wants to call. And when it has multiple tools to call from, we want to make sure that this is specific and clear. So this clearly defines it. In addition, within our parameter, we have a type hint string. That way, the agent knows when it calls this tool, we need to provide a string as the parameter, and there's also an output type hint. So all of these things are quite important for defining a good tool, And to make it an actual tool that the agent can call, we provide this at tool decorator. So that indicates that, okay, this is something that the agent can call. But importantly, this is just a simple Python function. There's nothing special to it. It's just straight up Python code that the agent will be able to call. And here's another tool, it's called mood tag, and it gives the description there, tag a piece of text with mood using real sentiment analysis. So, again, name and doctrine very clear as to what they do, type in provided, and output type. The code is just straight up Python code. So that's how you define tools. To actually hook them into your agent, you just need to provide them as a list. So it's the same deep agent we created before. You can provide your model, your system prompt, and now you can also provide a list of tools, which in this case is just the mood tag tool. And so we'll test it out. Define the agent, give it the same journal entry. So this is the same notes, the caching issue, feels good to have it done, etcetera, etcetera. And we're telling the agent, okay, use your tool on it. So run the mood tag tool, and then clearly explain explain to me what you found. So, ideally, this will run the mood tag tool, and you might notice that I'm telling the agent to use your tool on it. You don't have to do this. Agents should be able to determine, looking at its set of tools, when and how to call it. So we could omit this sentence, and let the agent do its own thing. In this case, I just want it to run. So off it goes. We can see that it calls the mood tag tool. That's really great. And here's the output. The tool that I found, overall sentiment neutral with a compound score of point four nine, etcetera, etcetera. So the mixed emotional tone, it's a great band name, mixed emotional tone, accomplished tempered by fatigue, blah blah blah, is exactly why the score line didn't know. Excellent. So it called the tool this is a custom tool that we defined. Should you define more tools, it's done in the same way. Excellent. Okay. Few more things, and we'll wrap up. I know I'm inching a time here. Okay. Another thing is memory. You want your agent to be able to remember things across turns of the conversation, and that's managed using a check pointer. That's what allows the agent to remember earlier turns in the same conversation. And we manage these conversations through a thread ID. So I can define check pointer here. Just gotta import this in memory saver and instantiate the check pointer. And now I'm going to specify this configuration and provide this thread ID of one. So you can think of these threads as new sessions, like when you're in Cloud or ChatGPT and you click the new chat tab and it's like new session appears. That's kind of what we're getting at by threads, that conversations within the same thread should remember stuff from the past, but it doesn't necessarily remember things from other threads. So here, I'm just saying thread ID one. I'll create a deep agent using model and providing the check pointer from before so it remembers things across turns. I'll give it a message. So my name is Ishan. I feel elated because my project was launched. I'll invoke the agent with the message. I'm also providing the configuration. So I'm saying, okay, use thread number one for this conversation. So it'll run. We shouldn't expect anything too special out of this. It just says like, okay, hi, Ishaan. Congratulations. That's fantastic news, etcetera, etcetera. But this is where things get a little bit more fun. So I can now ask my agent, what's my name? How do I feel? And we're still gonna use thread ID one, so same configuration as before. Ideally, it'll remember my name is Ishaan, and I feel elated because I just hold it back in the same conversation thread. And you can see here that that message exists, and it says your name is Ishaan, and you feel elated. Brilliant. So that's all happening within the same thread. But if you have conversations across threads, so if I instead ask the same question now in a different thread, now we would think that the agent doesn't remember this information. And, indeed, I don't actually have any access to personal information about you. I don't have any memory of past conversations. I don't know how you're feeling. Nobody knows how I'm feeling. That's just the way life goes. But that's the point. Two different threads, they have different memory, so to speak, and they're they're not crossing in between. So you would manage your stuff in different threads. Okay. I will go over human in the loop, and then we'll and then we'll wrap up kinda quickly. So human in the loop, I talked about it before, this idea of we want to be able to pause and let an agent, ask us before executing a sensitive command. And so this is also configured pretty simply. We just need to use this interrupt parameter, interrupt on parameter. So the way that works, human loop is with tools, so we will still have a tool like before. Maybe we have this tool called share journal entry, which shares the journal entry to some sort of social media or external platform. This is just mocked for now, but you can imagine we can rewrite this as, like, posting my journal to x or something like that. I don't know why you would do that. But this is a pretty sensitive task, something that I would want to approve before my agent shares my journal entry. So the way we configure human in the loop, it's still a tool. We still add it to this tools list. When we create our deep agent, we pass the tool just like before, but now we'll specify this, interrupt on, that if you call this shared journal entry tool, if you do that, then I need you to interrupt. I need you to stop and I need you to ask me to approve or reject, whatever you're about to do. So that's the only thing you need to do to configure this human in the loop. So that's the definition of the agent with human in the loop included. I have my message here, which is start a journal. Md file, log in your data entry, setting up human in the loop approval today, blah, blah, blah. Read the file back and share the most recent entry to this team stand up platform. So I'm telling my agent, hey. Share this, share this entry ideally by using the tool we just defined. So I'll run it, again, invoking it with the message. And ideally, when it chooses to call this team stand up or sorry, the share journal entry tool, it's going to stop and ask me for approval. And here's here we go. Pause for approval. So it wants to call the share journal entry, and this is the entry that's including, but it is paused. It has not executed this command yet. Now we have the option to approve or reject it, and the way you do that is by passing in this little dictionary indicating your preference. So my decision has type approved, so I'm okay with it being shared. We will run that, and, ideally, it will go off into the sunset and completed the shared journal entry step. It returns back with the AI message, so on and so forth. Okay. There's a little bit more on sub agents. I don't have the time to do that, so I will let you play around with this on your own time. But, hopefully, you got a feel of what a deep agent is and how it works. So, I don't think we necessarily have time for a q and a, unfortunately. I did see that, some of your questions dropped in that tab did get answered. So if you haven't checked there yet, feel free to peruse there. Let me just do a little bit of wrap up really quickly, and then we will call it a day. Uh-huh. Here we go. Okay. So as I said before, this demo, you can access the Colab notebook. You can go through it on your own time. I'll give you a second to scan it. This the links are also shared in the chat, I believe. So if you go to the chat tab, Jezell has pinned some messages at the top, so you can access it there too. There's also this take home practice assignment. So here, this is a Colab notebook that you can play with on your own, define your own deep agent, get your hands dirty. Importantly, you'll have to make a copy of the notebook to actually make edits to it. But, again, this is for you to play around with. You know, feel free to work with it. If you have any questions, feel free to email me or whatnot, but that's for you to play around with. Again, link to that is in the chat as well. Some other small things, You can learn more at LangChain academy. So if you scan this QR code, it should take you to a course all about deep agents that is expertly created, that goes into a lot more details about a lot of the stuff that I touched on today. So highly recommend checking that out as well. Give it a second to scan it. There's more QR codes, tons of QR codes. So much fun. K. I hinted at managed deep agents. I took a couple moments at the, previously in the session to talk about managed deep agents, this idea of deep agents going into production really quickly. Next week, we are having another webinar about managed deep agents. You can register over the workshop there. You might see a familiar face. So if you like that familiar face, come say hi. If you don't, well, that's okay. But register for the workshop there. It's next week. And if you wanna learn more in the time between, if you're so eager to learn, we have a lot of YouTube videos about managed deep agents. Here's a teaser video that you can watch. Again, might feature a familiar face. So, again, if you like that face, great. If not, tough luck, I guess. So watch that. And if you have any questions about managed deep agents or anything leading up, feel free to email me. It's my email right there.