mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 15:52:34 +00:00
feat: implement hierarchical agent delegation with allowed_agents parameter
- Add allowed_agents parameter to BaseAgent - Add validation for allowed_agents list - Update delegation tools to respect restrictions - Add error messages for unauthorized delegation - Add tests for hierarchical delegation Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -107,6 +107,10 @@ class BaseAgent(ABC, BaseModel):
|
||||
default=False,
|
||||
description="Enable agent to delegate and ask questions among each other.",
|
||||
)
|
||||
allowed_agents: Optional[List[str]] = Field(
|
||||
default=None,
|
||||
description="List of agent roles that this agent is allowed to delegate tasks to.",
|
||||
)
|
||||
tools: Optional[List[Any]] = Field(
|
||||
default_factory=list, description="Tools at agents' disposal"
|
||||
)
|
||||
@@ -174,6 +178,13 @@ class BaseAgent(ABC, BaseModel):
|
||||
f"{field} must be provided either directly or through config"
|
||||
)
|
||||
|
||||
# Validate allowed_agents if delegation is enabled
|
||||
if self.allow_delegation and self.allowed_agents is not None:
|
||||
if not isinstance(self.allowed_agents, list):
|
||||
raise ValueError("allowed_agents must be a list of strings")
|
||||
if not all(isinstance(agent, str) for agent in self.allowed_agents):
|
||||
raise ValueError("all entries in allowed_agents must be strings")
|
||||
|
||||
# Set private attributes
|
||||
self._logger = Logger(verbose=self.verbose)
|
||||
if self.max_rpm and not self._rpm_controller:
|
||||
|
||||
Reference in New Issue
Block a user