Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/crewai/src/crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,7 @@ def _run_hierarchical_process(self) -> CrewOutput:
return self._execute_tasks(self.tasks)

def _create_manager_agent(self) -> None:
"""Create or configure the manager agent for hierarchical execution."""
if self.manager_agent is not None:
self.manager_agent.allow_delegation = True
manager = self.manager_agent
Expand All @@ -1502,7 +1503,7 @@ def _create_manager_agent(self) -> None:
color="bold_yellow",
)
manager.tools = []
raise Exception("Manager agent should not have tools")
# tools are stripped after warning — see set_manager_agent()
else:
self.manager_llm = create_llm(self.manager_llm)
i18n = get_i18n(prompt_file=self.prompt_file)
Expand Down
4 changes: 3 additions & 1 deletion lib/crewai/src/crewai/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,9 @@ async def _ahandle_streaming_response(
)

except (AttributeError, KeyError, IndexError, TypeError):
pass
logging.getLogger(__name__).debug(
"Failed to parse streaming chunk", exc_info=True
)

if chunk_content:
full_response += chunk_content
Expand Down
16 changes: 13 additions & 3 deletions lib/crewai/tests/test_crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -2878,7 +2878,9 @@ def test_manager_agent_in_agents_raises_exception(researcher, writer):


@pytest.mark.vcr()
def test_manager_agent_with_tools_raises_exception(researcher, writer):
def test_manager_agent_with_tools_logs_warning_and_strips_tools(researcher, writer):
"""Test that manager agent tools are stripped after a warning."""

@tool
def testing_tool(first_number: int, second_number: int) -> int:
"""Useful for when you need to multiply two numbers together."""
Expand All @@ -2904,8 +2906,16 @@ def testing_tool(first_number: int, second_number: int) -> int:
tasks=[task],
)

with pytest.raises(Exception, match="Manager agent should not have tools"):
crew.kickoff()
with patch("crewai.crew.Logger.log", autospec=True) as log:
crew._create_manager_agent()

log.assert_called_once_with(
crew._logger,
"warning",
"Manager agent should not have tools",
color="bold_yellow",
)
assert manager.tools == []


@pytest.mark.xfail(
Expand Down