Conditional Tasks in Multi-Agent Systems

Learn about conditional tasks in multi-agent systems and how to implement them in CrewAI.

We'll cover the following

These "agents" are supposed to be intelligent, right? They can fetch data, analyze it, even somehow manipulate it—they can do all sorts of useful things. But here’s the part we need to be aware of: they’re not always as reliable as we’d like them to be. We might tell an agent to fetch some data, and it might come back with everything we asked for. But sometimes, it doesn’t. It misses a piece here and forgets a detail there. Why? Because, like all systems, agents are only as good as the instructions we give them and the data they have to work with.

In the real world, when you ask someone to do something, they might ask, “Did I do enough?” or “Is this what you wanted?” This is where we can make our agents smarter, not by making them perfect, but by giving them a fallback plan—something to check their work and see if it’s good enough. This is where conditional tasks come in. Think of a conditional task as a safety net. It’s like saying, “Hey, if you didn’t gather enough data, go back and fetch some more.” Or, “If the numbers don’t add up, do more digging.” It’s a simple idea, but it’s powerful, especially when dealing with numbers, quantities, or any kind of data where “just enough” might not cut it.

Let's get into how we can use these conditional tasks in a multi-agent system. We’ll look at a practical example where agents work together to fetch, process, and summarize data. But what happens if one of them doesn’t do its job right? That’s where our conditional task steps in – to make sure we get the results we need, even if the agent isn’t perfect.

Agents

Now, like always, let’s get our hands dirty and build a multi-agent system with a conditional task. First things first, we need to set up our agents. We’ve got three: a data collector, a data analyzer, and a summary writer.

Get hands-on with 1400+ tech skills courses.