mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
fix: set result_as_answer=True in DelegateWorkTool to fix incomplete final answers in hierarchical process mode (#2768)
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -18,6 +18,7 @@ class DelegateWorkTool(BaseAgentTool):
|
||||
|
||||
name: str = "Delegate work to coworker"
|
||||
args_schema: type[BaseModel] = DelegateWorkToolSchema
|
||||
result_as_answer: bool = True
|
||||
|
||||
def _run(
|
||||
self,
|
||||
|
||||
46
tests/test_hierarchical_issue_fix.py
Normal file
46
tests/test_hierarchical_issue_fix.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""Test to ensure hierarchical process mode returns complete final answers."""
|
||||
|
||||
import pytest
|
||||
from crewai.agent import Agent
|
||||
from crewai.crew import Crew
|
||||
from crewai.process import Process
|
||||
from crewai.task import Task
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_hierarchical_process_delegation_result():
|
||||
"""Test that the hierarchical process returns the delegated agent's result, not just the manager's delegation thought."""
|
||||
researcher = Agent(
|
||||
role="Researcher",
|
||||
goal="Make the best research and analysis on content about AI and AI agents",
|
||||
backstory="You're an expert researcher, specialized in technology, software engineering, AI and startups. You work as a freelancer and is now working on doing research and analysis for a new customer.",
|
||||
allow_delegation=False,
|
||||
)
|
||||
|
||||
writer = Agent(
|
||||
role="Senior Writer",
|
||||
goal="Write the best content about AI and AI agents.",
|
||||
backstory="You're a senior writer, specialized in technology, software engineering, AI and startups. You work as a freelancer and are now working on writing content for a new customer.",
|
||||
allow_delegation=False,
|
||||
)
|
||||
|
||||
task = Task(
|
||||
description="Come up with a list of 3 interesting ideas to explore for an article, then write one amazing paragraph highlight for each idea that showcases how good an article about this topic could be. Return the list of ideas with their paragraph and your notes.",
|
||||
expected_output="3 bullet points with a paragraph for each idea.",
|
||||
)
|
||||
|
||||
crew = Crew(
|
||||
agents=[researcher, writer],
|
||||
process=Process.hierarchical,
|
||||
manager_llm="gpt-4o",
|
||||
tasks=[task],
|
||||
)
|
||||
|
||||
result = crew.kickoff()
|
||||
|
||||
assert "idea" in result.raw.lower() or "article" in result.raw.lower()
|
||||
assert len(result.raw) > 100 # Ensure we have substantial content
|
||||
|
||||
assert "delegate" not in result.raw.lower()
|
||||
assert "delegating" not in result.raw.lower()
|
||||
assert "assigned" not in result.raw.lower()
|
||||
Reference in New Issue
Block a user