Skip to main content

Reliable AI Agents in Production: CrewAI Flows, Guardrails and Observability

Summary

  • Deterministic flows: Scale multi-agent systems with strategic reasoning layers without drifting.
  • Guardrails and lifecycle hooks: Human-in-the-loop prevents agents from accessing unauthorized tools or data.
  • Terminal Bench results: Harness design improved accuracy from 20% to 65% without changing the model.

Reliable AI Agents in Production: CrewAI Flows, Guardrails and Observability

Watch: Reliable AI Agents in Production: CrewAI Flows, Guardrails and Observability
Talk by Lorenz, Open Source Team Lead, CrewAI
An agent harness is the scaffolding around a model — the control flow, guardrails, memory and observability that decide whether an AI agent survives production. Choosing the harness matters as much as choosing the model: on Terminal Bench, the same model went from 20% to 65% once the harness changed. CrewAI's open source team lead explains how to combine deterministic flow steps with agent reasoning only where reasoning adds value, so multi-agent systems scale to thousands of users without drifting.
This video uses a lead qualification flow to show where determinism belongs, with programmatic steps such as pulling data from Databricks or HubSpot, and where an LLM adds value. It covers guardrails that limit what tools can access, lifecycle hooks that sanitize inputs and outputs, human-in-the-loop as real intervention rather than an audit step, branching, and checkpoints. It explains why the harness around a model matters, citing a jump on Terminal Bench from 20% to over 65% without changing the model. You also learn why the ReAct loop falls short for long tasks, how plan-execute-observe-replan works with structured input and output, and how traces, metrics and feedback loops keep agents reliable.

Chapters

FAQs

What is an agent harness and why does it matter for production?

An agent harness is the scaffolding around a model that controls flow, guardrails, memory and observability. This video shows on Terminal Bench that changing the harness alone improved accuracy from 20% to 65% without modifying the model, proving that harness design matters as much as model choice.

How should I mix deterministic steps with AI reasoning in agents?

This video uses a lead qualification flow to show where determinism belongs: programmatic steps like pulling data from Databricks or HubSpot should be deterministic, while LLM reasoning adds value only where human judgment is needed. This approach lets agents scale to thousands of users without drifting.

What guardrails and lifecycle hooks do I need for agent safety?

Guardrails limit what tools and data agents can access, while lifecycle hooks sanitize inputs and outputs. This video covers how human-in-the-loop works as real intervention rather than just an audit step, with branching and checkpoints to keep agents reliable.

Why does the ReAct loop fall short for long-running agent tasks?

This video explains that ReAct alone doesn't work well for extended tasks and instead recommends plan-execute-observe-replan with structured input and output. Production agents need traces, metrics and feedback loops to maintain reliability over time.

Full transcript

00:00 Introduction

Thank you for coming. I know these past few days have been busy and interesting. But before we begin, let me introduce myself: my name is Lorenz. I lead the open source team at Crew AI. Before we begin, I want to ask you to raise your hands. How many people here actually created agents? Raise your hands. Okay , most of the people in the room. Keep your hands up if you have deployed them in grocery environments. Okay, half the room.
What about scaling? So that tens of thousands of people use these agents. Nobody raised their hand, really? OK. Hopefully, by the end of today, you will know how to do this reliably. So, my promise here is simple. I want you to be able to answer this question at the end of my speech. You will receive a framework that you can offer to your team or use yourself to answer: is our agent system ready for real use? Not just something that works in a demo or on my computer, but something that you can implement and scale to a large number of real users.

00:58 Is your agent system ready for production?

At Crew AI, we have worked with many organizations such as PWC, DocuSign, AB InBev, and others. These are different industries, different cases, and different models . But all our clients have one thing in common . They use what we call " flows". The main architecture they deploy is orchestration, a kind of event-driven orchestration layer. It is a deterministic system that has startup methods, listeners, and routers.

01:47 Flows: mixing deterministic steps with intelligent agents

Think of it as a traditional workflow automation tool. However, you can also add a little intelligence here. You can add it between nodes where intelligence or logical reasoning is important. So what do you get? Let me give you a quick example. Imagine the lead qualification process. First I need to get the data. This could be from HubSpot. This could be from DataBricks. This is a data sampling request. This is not something you should spend tokens on.
This is a programmatic action. Something in Python. This is what we have been doing for many decades. What is highlighted in green is completely software tasks. So, you get the data. I'm going to get data from HubSpot. Now I have this row of data. Now I can appreciate it. This is where the language model (LLM) comes into play. Based on my company's criteria for what constitutes quality lead, we can use a language model to evaluate this.
Next, we can add this router. This is a condition. So, if the lead score is greater than or less than seven, let's just give a general answer. This is a programmatic action. We can make a POST request and either do nothing, or go back to the database and mark it as "not ice". Or, if the score is higher than seven, let's explore them in more detail. Let's make more database queries . Let's analyze whether this profile is truly a lead, and then create a highly personalized campaign specifically for this potential lead.
Right? And the places highlighted in red are where you have levels of intelligence or agency. Right? Your first agent evaluates the language model, or your analysis is now performed by multiple agents. So you have three agents who are perhaps doing additional research on this user. But in general, we call this structure streams. So, what is the main conclusion? If there's one thing I want you to remember—it's the main takeaway.
Reliable agent systems balance between determinism and agency. Agency is intelligence, reasoning, etc. The goal here is not to eliminate agents. Agents are indeed powerful and useful, but the point is to be conscious about where we place them, right? At each node or each stage of the journey, where exactly do we want these intelligent models to operate? So how do we put all of this together? How do we design these reliable agent systems?
I believe there are three pillars here. The first is control flows. You have guardrails, hooks, a man in the loop, checkpoints. This is how you restrict and control your execution flow. Next comes the agent template, the design of how you actually create the agent. People perceive this as a cycle , but agents also need some structure. This can be done with planning, and we'll get to those details, but structure and structured inference are pretty much all you need to know for more robust agent patterns.
And I'll close with a review of observability. How do you find out what's happening with your agents? To avoid working in a " black box". So, if you know what is happening at the time of the event, you can act and control them. So let's start with control flows. The first is guardrails. This limits the scope of what your agents can interact with, right? Because without safeguards, your agents have access to anything you give them.

05:28 Guardrails: limiting what agents can access

A regular search tool turns into the entire internet. If you give it access to the database, it can read, write, update, and delete. This is how cases occur when entire working databases go down. You're just giving them too much access. The API becomes unlimited, right? And that's not exactly intelligence. This is vulnerability. So fuses allow you to limit this. At Crew, we have two ways to provide you with fuses. The first is software fuses.
This is actually code that you can use to configure and test whether your agents are behaving appropriately, or language model-based fuses where the model acts as the judge, assessing whether the end result follows your rules. Next we have lifecycle hooks. They control the input and output of everything that passes through the model all the way to the tools. So, think of "pre- hooks" as a way to control input. You can clear the messages coming to the LLM request.

06:21 Lifecycle hooks to sanitize inputs and outputs

You can block certain requests to LLM based on specified criteria. Oh, I don't want them to ask that type of question. So LLM's "pre-hooks" allow you to implement this. "Post- hooks" allow you to clean data, sanitize it, or delete personal information when it enters, for example, a database or during logging. They provide you with those software tools or levers with which you can control the operation of your LLMs and tools.
Man in a cycle. I think everyone has heard of the "human in the loop" since day one of agent systems, but I think there is some misunderstanding about the concept. Most people consider "man in the loop" to be a kind of audit level. My agents do all the work. They use a bunch of tools. They cycle through many model calls. But the role of man is reduced only to checking whether it is good or bad. Or let me influence the agent to give a different answer.

07:10 Human-in-the-loop as real intervention, not an audit

This is not really a control. Instead, "person in the loop" should mean how you can intervene as an individual. This effectively turns you into a fuse, does n't it? It's not just one check at the very end. This is control over every single step your agents take. So, if you look at it this way: the person in the cycle is no longer just an audit level. This is no longer the stage where "okay, my task is done." Good, bad.
Or maybe use bullet points instead of, you know, a numbered list. Instead, it's a way for you to check every step at the decision-making level. What is my action? What is the language model going to trigger? What tools will be used? How do I get to the final results? Now you can add these levels of human input or control at each specific node of this structured flow. Next are the checkpoints. They allow you to go back in time from a certain point.
Let's say your agents perform five steps. Your first two steps were very costly or took a long time. Instead, we can just continue with, you know, the third task and move on. A more interesting feature is called branching. Branching allows you to create a kind of experimental branch. It allows you to dynamically change input data. So let 's go back to the lead qualification example. Instead of the criterion being, you know, criterion A, now we can change that.
And maybe the ice will be affected differently. But you don't have to restart the entire workflow from step zero. So , this gives much more control when it comes to changing the results without the delays and expense of tokens that were already used in the initial call. So yes. We have considered the flow of control. Next, we'll move on to agent templates and how you can build reliable agents. So, to summarize: fuses set the rules for your agents.
Hooks are essentially a lifecycle of what comes in and goes out for each LLM and each tool call. The person in the loop is no longer just an audit level. Is this good? Is this bad? Instead, it's a way for you to actually intervene and establish these controls. Oh, before writing to the database, let's make sure the data is really good quality. Checkpoints allow you to go back in time, as well as experiment with different ways your agents behave.
Let me give you an example of how we improved our agents to be a little more reliable. Have you heard of Terminal Bench? Okay, no. Okay, one person. Terminal Bench is a series of long-term programming challenges. And we improved our fulfillment agent, raising the rate from 20% to over 65%. But we didn't change the model itself. We did not perform any model training. We simply changed what surrounds the model. And I'm sure everyone here has probably heard a word like "harness."

10:15 Why the agent harness matters: Terminal Bench 20% to 65%

I think this word is becoming more and more popular. So what is this "harness" you are building, huh? This is everything that surrounds the model. You can customize your harness for broader use, for a specific niche, or for programming. It's mostly a combination of hooks: your system prompt, fuses, subagents you deploy, memory, skills, sandboxes, context, and tools. All of this is brought together around the model. Why do you get different results when using Cloud Code or Cursor, despite using the same model, right?
This is a kind of their own harness that they have surrounded the models with. And there's one more thing you need to consider, namely the agent template. There is this ReAct template, which stands for " reasoning and action." This was popular in 2023, and it was a way for us to do tool challenges . So, the ReAct template works like this. Thought: What should I do given this task? My opinion: I should use this tool. Action: use this tool.

11:45 Limits of the ReAct loop for long-running tasks

Observation: Did I complete this task , or should I use the tool again? And we go through this cycle. And that's what most people call agents. Is the agent just an LLM in a while loop? Both yes and no, perhaps this is a moot point. But the limitation of ReAct is that there is no state, and it is very unclear how exactly it does the job. When you give him a task, for example: "Process these 100 lines in HubSpot." It will probably get the first 10 right, maybe the first 15 if you're using an advanced model.
On the 16th, it breaks. And he breaks down in a way that looks confident. " Oh, I completed my task." So, it doesn't work when you expect to perform long-running tasks or a deterministic number of steps. For example: "Work through 100 or 50 of these lines in turn." Yes. So instead, we created and implemented a new template called " planning and execution." And inside this loop, I'm showing quotes in the air, there's a little bit of that ReAct template.
So we haven't completely abandoned ReAct. We just wanted a way to have more control. So, React is a slightly more reactive thing. How do we actually implement this control? And it all starts with a plan. A plan is a structure. It gives you a definition of what needs to be done in the task sequence, right? So we go from React as something ambiguous to something with much more structure, and move on. You might think that “ planning and execution” is just another cycle.
We start with a plan, execute it, see if everything is completed, and then launch a replan. And this replanning is, " Oh, do I need another planning step?" » So you might think, “Okay, one more cycle. React is a loop. This is also a cycle now. What's the difference? Instead, it actually looks like this. Does anyone know what this diagram is? I may have mentioned this before. Does anyone know this structure? Let's be interactive.
No? This is flow. So, under the hood of this cycle, there is actually a flow. This is our planning agent. The principle of how a plan works is that we start a flow, and this flow has deterministic steps. The ones marked in black are deterministic, and each of them is itself a sequence of four things we need to do. The first is a plan. It has a language model ( LM), but we can guarantee that this plan will actually be created.

14:19 Plan, execute, observe and replan with structured outputs

This plan is broken down into a bunch of tasks, and from there we choose what is ready, what is done, or what is stuck. And then we take this step. Each execution works in isolation. So, we will have a subagent- executor who directly performs this task. There may be tasks that need to be performed in parallel, this is also provided for. And we also have a router. We check and decide: am I finished or do I need to correct the plan?
And I'll give you some practical examples of when this really works. But again, there's this balance when it comes to maintaining state: what are tasks, what's done, what's completed, and what threw an error. Should I check the plan or continue and give a final answer? And what planning really gives you is a structure based on that plan. That's a bunch of tasks, and each structure is essentially a Python class. You have a step number when it should be done.
It all depends on whether I need additional context from other tasks I've already completed . Which tool from the agent list should I use? Should I use a specific tool or not? Am I done yet? This is what the status and end result are. So, structured input, structured output. Think about it from that perspective. And that's all you need to know when planning. And the planning stages are almost entirely built on this. You have a task, and you define that task .
You give input to this agent. It usually has a description . You can provide the expected result . But our reasoning plan is a method that starts with the first part of the flow, where the instructions are quite clear. Each step should have criteria for what “done” means. We will not group unrelated actions. There are no separate stages of deliberation. And the last step should provide the necessary result so that we can say, "Hey, we really finished this task."
Even after it was broken down into separate points. And you get a very clear structure. Again , it is simple and clear for our agents. So, step one is action: finding frameworks. Step two—action: benchmark comparison. Step three—action: writing a report. Structured input, structured output . Again. Each item on the to- do list should be completed in isolation. Why? This means that we do not influence the state. These messages are not forwarded.
Each has its own controlled execution cycle. They can still run in parallel, but again, the concept is to isolate each individual task. We can provide additional context as to what "dependence on " means. So before you do task three, maybe it depends on completing tasks one and two, right? And each execution must be checked by the entity to understand whether it is complete. This entity is a sub- agent, which we call an " observer."

17:58 Observer agents and self-correcting plans

This observer evaluates the results. Was this step really successfully completed? Is the result valid? Did something unexpected happen? Were there any glitches in the process? This is why the scores in terminal benchmarks start at very low values. There are many dependencies when we run the sandbox. There is a base image that comes with the package, but it may be missing some dependencies. So what happens when there is a lack of dependency?
The context simply says, "Hey, we're broken because you didn't install this." And what now? Should we try again ? Should we introduce this as a new redevelopment plan? That's why we introduced " observation for replanning." So now that we get the answer, "Hey, this dependency is missing." Let's update our plan. I'm missing this dependency, so let's install it and continue with the original plan. True? This is where agents become self-renewable.
They can recover from mistakes. They can recover from failures. And I think that's what makes agents special. But you need this structure to fully implement it. You have several primitives to control. You don't want to plan and replan forever. You need to make sure your agents are behaving appropriately . So you have the leverage: "Hey, there needs to be a timeout." Treat these tools like regular software. If the process takes forever, it's not worth constantly spending tokens.
Set the maximum number of replans. Maybe after two tries, you should say, "Okay, I think this is broken and won't work ." So let's stop there. These are just some of the levers in Crew for controlling planning steps. I repeat: everything is built on a structure that gives you control. The internal template is built on a flow basis. So, flow is a balance between deterministic workflows and agency capabilities. We have analyzed the templates and design of agents.
Next we will move on to observability. You need to make sure your agents don't operate like a "black box." Observability helps to understand each step: agent paths, planning stages, LLM calls, tools failing, is this really taking long or am I just in an infinite loop? So being able to understand how to balance that or visualize it is where observation comes in handy. And you need to have this at all stages: when you build, when you iterate, and when you fully deploy .

20:32 Observability for agents: traces, failures and feedback loops

Just like in the planning phase, when you create a plan, do you have ways to see what I depend on? What tools was I going to use? What was that step and when did I perform that specific item or parallel process, right? How long did each step take? Is what I am doing actually happening, or are my expected results being achieved ? Another level of observability is to treat them like traditional software. So when LLMs fail, when tools don't work, when timeouts occur , something should notify you.
This is where notifications and webhooks come into play. They notify you when the system is down, for example. Then you can triage the problems. You can say: hey, when this error occurs, let's maybe create a bug ticket. Let's put this aside. We will notify the engineer. Maybe they are on duty. Let's fix this immediately. Again, this is part of reliability. When it comes to the ability to escalate and respond to these incidents.
So instead of wondering what went wrong, you get a signal instantly. And you can do it with the tools we have. We have, I mentioned, lifecycle hooks. These are the levers you can use to activate to get these signals as soon as they happen. Otherwise, these tools will simply silently fail . So, again , to summarize this slide: treat your agents the same way you would traditional software. When something happens, when something breaks, you get notified and have a way to respond to it .
Observability is not just during development, it's also during iterations and all the way to deployment. When you build a use case, you need to understand what your agents are calling . What are they doing? When you iterate, you want to understand if it's too expensive? How can I actually improve my plans? How can I actually improve agents if they keep failing? Is it a model issue or can I use a smaller model? If I use a smaller model, will the quality remain the same?
Here, observability gives you insight into how you can continually improve and iterate on these use cases. And finally, when you deploy, you get these notifications. So, when you deploy a system, you gain insight into what went wrong and what went right. But you need observability of all aspects of the agent lifecycle during development. So again , treat this like any other traditional software that we've been deploying for decades.
This is a bit more of an experimental thing . But over time, your agents will accumulate a bunch of traces. So how can we feed this data back to the agent so it can improve itself? Isn't that right ? So again, a similar concept to redevelopment. Did my replanning work correctly? Or every step I take, I'm constantly replanning from step number four. So this can be fed back into the agent's work. It can update its own system prompt, scheduling configuration, skills, and memory.
Over time, he gains this key knowledge. So he doesn't make the same mistakes again. And over time, this makes your agents much more reliable. That's all. We have looked at the three pillars of building reliable agent systems and what makes them work in practice. I'll do another quick review for you. So, control flows. We have fuses, interceptors, human participation, and the creation of checkpoints. Here's how we can limit and control our agents.
The template is simple. Structured input, structured output . It is built on a flow basis, which gives us leverage for control. Observability: You really need to know what’s happening “under the hood” in real time and be able to act when incidents occur. I'll just draw parallels with what we do at Crew. So, we have the platform for you. We have abstracted away all the complexities and knowledge we discussed today, and any agent can be easily created in our studio.
Just enter the use case you need . Again , all you need to worry about is your use case. "Hey, build me this lead qualification flow I need." Well, I'll give you connectors for tools like HubSpot, Databricks, etc. , and your only goal is to create. We will deliver and provide you with these reliable agents. This is one way to build. We also have a platform that allows you to deploy. So, even if you build code using our open framework, we provide a platform where you can deploy and scale it at scale.
Scaling means that when you have a lot of requests to fulfill, you can trust us to scale. There are controls, there are controls, there are ways to hide personal data in trace records. So, this is all covered by our platform. Well, actually, that's all. I believe there are three levers for reliably building agent systems. And I really hope that now you can answer this question. Isn't that right ? We started with this question at the very beginning of our conversation.

26:19 Production readiness checklist for agent systems

I hope you can now answer: are our agent systems ready for industrial operation? At the beginning, half the room raised their hands when we talked about creating agents. Only one or two people said they were actually able to scale it reliably. So, hopefully now, at the end, you can answer that. Oh, well, that's the main conclusion. Again, I mentioned this for threads: reliable agent systems combine determinism and autonomy.
You have this structured flow, but there is intelligence, reasoning, and planning steps woven into it. This is where agents really come in handy. Maybe this is the moment for a screenshot, or the moment to take out your phone and take a photo. Check with the team to see if you have these items. That's pretty much all we talked about. Do you have these fuses? Do you have these checkpoints set up ? Is my agent template structured?
Do I have monitoring? Do I have a notification? Do I have this feedback loop that I can provide to my team when it comes to building agents? Well , actually, that's all from me. Thank you for coming to the session. I know this was the last session on Databricks, so thanks for stopping by. If you want to continue the conversation, I think we still have time for questions and answers. And here is my LinkedIn. If you want to continue the conversation, if you have any questions.
Well, actually, that's all from me. Thank you .

Learn more about the Databricks Data and AI platform.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.