Welcome to the cutting edge of crewAI!
In the previous Chapter 2: Hierarchical Process, we learned how to use a "Manager" to boss agents around and ensure quality. Before that, in Chapter 1: Sequential Process, we learned how to run tasks in a straight line.
But what if you don't want a boss? What if you want a Democracy?
In this chapter, we will explore the concept of the Consensual Process.
๐ง Note: The Consensual Process is currently a planned feature (experimental). It represents the future direction of crewAI. This chapter explores the concept and design behind it, so you are ready when it launches!
Imagine our Central Use Case: "The Product Launch".
You are launching a new software product. To approve the launch, you need agreement from three different departments:
If you use a Sequential process, Legal might say "Yes" to the law, but ignore that Engineering says the code is broken. If you use a Hierarchical process, a Manager decides, but the Manager might override the Engineer's safety concerns.
In a Consensual process, everyone must agree. If the Engineer says "No," the launch stops, and the team must fix the problem until everyone says "Yes."
Imagine you and two friends are choosing a pizza.
You cannot order until you find a topping that satisfies all three constraints. You discuss, propose options, and vote until you reach a Consensus.
In this workflow, agents act like a committee. They don't just do work; they evaluate the work of others and have veto power.
We need a team with different viewpoints.
from crewai import Agent, Task, Crew, Process
# 1. The Engineer (Focus: Stability)
engineer = Agent(
role='Lead Engineer',
goal='Ensure the system is stable',
backstory='You say NO if there are bugs.'
)
Explanation: The Engineer is programmed to care about stability.
# 2. The Lawyer (Focus: Compliance)
lawyer = Agent(
role='Legal Advisor',
goal='Ensure we do not get sued',
backstory='You say NO if there is risk.'
)
Explanation: The Lawyer doesn't care about bugs, only legal risk.
The task is shared. It requires approval.
# The Shared Task
launch_task = Task(
description='Review the product for launch.',
expected_output='A "GO" or "NO GO" decision based on agreement.',
agent=engineer # Assigned to lead, but needs consensus
)
Explanation: While one agent might lead the task, the output isn't valid until the others sign off.
Here is how you would theoretically set up the consensual process.
# Create the Democratic Crew
my_crew = Crew(
agents=[engineer, lawyer],
tasks=[launch_task],
process=Process.consensual # <--- The Future Feature
)
Explanation: By selecting Process.consensual, you are telling crewAI: "Do not finish this task until the agents agree on the output."
How does a computer program reach a "consensus"? It isn't magic; it is a loop of Proposal and Voting.
When you run a consensual process, the system enters a "Negotiation Phase."
Note: This is a conceptual implementation of how the logic would handle the loop.
The system needs a while loop that continues as long as there is a disagreement.
# Conceptual logic for Consensual Process
def kickoff(self):
proposal = self.generate_initial_proposal()
consensus = False
while not consensus:
# Ask all agents to vote on the proposal
votes = self.collect_votes(proposal, self.agents)
if all(vote == "YES" for vote in votes):
consensus = True
else:
# If someone says NO, ask agents to improve the proposal
proposal = self.refine_proposal(proposal, feedback=votes)
return proposal
Explanation:
all agents say YES, we are done.The Consensual process is the holy grail of autonomous AI collaboration. It moves beyond simple "do this, then that" (Sequential) or "do what I say" (Hierarchical) into true collaboration.
Key Takeaways:
Although this feature is currently in the experimental stage of crewAI's development, understanding it helps you see the future of AI Agents: teams that think, debate, and agree just like humans do.
You have now completed the core tutorial on crewAI Processes! You understand how to structure teams in lines, pyramids, and circles.
Happy coding with your new AI crews!
Generated by Code IQ