Compare commits

...

8 Commits

5 changed files with 3904 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
import asyncio import asyncio
import json import json
import uuid import uuid
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union, Tuple
from langchain_core.callbacks import BaseCallbackHandler from langchain_core.callbacks import BaseCallbackHandler
from pydantic import ( from pydantic import (
@@ -224,6 +224,33 @@ class Crew(BaseModel):
agent.set_rpm_controller(self._rpm_controller) agent.set_rpm_controller(self._rpm_controller)
return self return self
@model_validator(mode="after")
def validate_tasks(self):
if self.process == Process.sequential:
for task in self.tasks:
if task.agent is None:
raise PydanticCustomError(
"missing_agent_in_task",
f"Sequential process error: Agent is missing in the task with the following description: {task.description}", # type: ignore Argument of type "str" cannot be assigned to parameter "message_template" of type "LiteralString"
{},
)
return self
@model_validator(mode="after")
def check_tasks_in_hierarchical_process_not_async(self):
"""Validates that the tasks in hierarchical process are not flagged with async_execution."""
if self.process == Process.hierarchical:
for task in self.tasks:
if task.async_execution:
raise PydanticCustomError(
"async_execution_in_hierarchical_process",
"Hierarchical process error: Tasks cannot be flagged with async_execution.",
{},
)
return self
def _setup_from_config(self): def _setup_from_config(self):
assert self.config is not None, "Config should not be None." assert self.config is not None, "Config should not be None."
@@ -315,9 +342,7 @@ class Crew(BaseModel):
if self.process == Process.sequential: if self.process == Process.sequential:
result = self._run_sequential_process() result = self._run_sequential_process()
elif self.process == Process.hierarchical: elif self.process == Process.hierarchical:
# type: ignore # Unpacking a string is disallowed
result, manager_metrics = self._run_hierarchical_process() result, manager_metrics = self._run_hierarchical_process()
# type: ignore # Cannot determine type of "manager_metrics"
metrics.append(manager_metrics) metrics.append(manager_metrics)
else: else:
raise NotImplementedError( raise NotImplementedError(
@@ -433,14 +458,16 @@ class Crew(BaseModel):
# type: ignore # Incompatible return value type (got "tuple[str, Any]", expected "str") # type: ignore # Incompatible return value type (got "tuple[str, Any]", expected "str")
return self._format_output(task_output, token_usage) return self._format_output(task_output, token_usage)
def _run_hierarchical_process(self) -> Union[str, Dict[str, Any]]: def _run_hierarchical_process(
self,
) -> Tuple[Union[str, Dict[str, Any]], Dict[str, Any]]:
"""Creates and assigns a manager agent to make sure the crew completes the tasks.""" """Creates and assigns a manager agent to make sure the crew completes the tasks."""
i18n = I18N(prompt_file=self.prompt_file) i18n = I18N(prompt_file=self.prompt_file)
if self.manager_agent is not None: if self.manager_agent is not None:
self.manager_agent.allow_delegation = True self.manager_agent.allow_delegation = True
manager = self.manager_agent manager = self.manager_agent
if len(manager.tools) > 0: if manager.tools is not None and len(manager.tools) > 0:
raise Exception("Manager agent should not have tools") raise Exception("Manager agent should not have tools")
manager.tools = self.manager_agent.get_delegation_tools(self.agents) manager.tools = self.manager_agent.get_delegation_tools(self.agents)
else: else:
@@ -465,6 +492,10 @@ class Crew(BaseModel):
agent=manager.role, task=task.description, status="started" agent=manager.role, task=task.description, status="started"
) )
if task.agent:
manager.tools = task.agent.get_delegation_tools([task.agent])
else:
manager.tools = manager.get_delegation_tools(self.agents)
task_output = task.execute( task_output = task.execute(
agent=manager, context=task_output, tools=manager.tools agent=manager, context=task_output, tools=manager.tools
) )
@@ -554,7 +585,9 @@ class Crew(BaseModel):
self._rpm_controller.stop_rpm_counter() self._rpm_controller.stop_rpm_counter()
if agentops: if agentops:
agentops.end_session( agentops.end_session(
end_state="Success", end_state_reason="Finished Execution", is_auto_end=True end_state="Success",
end_state_reason="Finished Execution",
is_auto_end=True,
) )
self._telemetry.end_crew(self, output) self._telemetry.end_crew(self, output)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,146 @@
interactions:
- request:
body: !!binary |
CtoyCiQKIgoMc2VydmljZS5uYW1lEhIKEGNyZXdBSS10ZWxlbWV0cnkSsTIKEgoQY3Jld2FpLnRl
bGVtZXRyeRJpChCqSW3lVdefwRBLNXi6Xhm8EgijxkgGOCJOMSoQVG9vbCBVc2FnZSBFcnJvcjAB
OQh+giEMv94XQYgthSEMv94XShsKDmNy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DAyLjQxLjl+Ni9SRUxFQVNFX0FSTTY0X1Q2MDAwSgoKBGNwdXMSAhgKegIYAYUBAAEAAA==
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Connection:
- keep-alive
Content-Length:
- '6493'
Content-Type:
- application/x-protobuf
User-Agent:
- OTel-OTLP-Exporter-Python/1.25.0
method: POST
uri: https://telemetry.crewai.com:4319/v1/traces
response:
body:
string: "\n\0"
headers:
Content-Length:
- '2'
Content-Type:
- application/x-protobuf
Date:
- Wed, 03 Jul 2024 15:56:09 GMT
status:
code: 200
message: OK
version: 1

View File

@@ -1027,6 +1027,29 @@ def test_agent_usage_metrics_are_captured_for_sequential_process():
} }
@pytest.mark.vcr(filter_headers=["authorization"])
def test_sequential_crew_creation_tasks_without_agents():
task = Task(
description="Come up with a list of 5 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="5 bullet points with a paragraph for each idea.",
# agent=researcher, # not having an agent on the task should throw an error
)
# Expected Output: The sequential crew should fail to create because the task is missing an agent
with pytest.raises(pydantic_core._pydantic_core.ValidationError) as exec_info:
Crew(
tasks=[task],
agents=[researcher],
process=Process.sequential,
)
assert exec_info.value.errors()[0]["type"] == "missing_agent_in_task"
assert (
"Agent is missing in the task with the following description"
in exec_info.value.errors()[0]["msg"]
)
@pytest.mark.vcr(filter_headers=["authorization"]) @pytest.mark.vcr(filter_headers=["authorization"])
def test_agent_usage_metrics_are_captured_for_hierarchical_process(): def test_agent_usage_metrics_are_captured_for_hierarchical_process():
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI
@@ -1058,6 +1081,61 @@ def test_agent_usage_metrics_are_captured_for_hierarchical_process():
} }
@pytest.mark.vcr(filter_headers=["authorization"])
def test_hierarchical_crew_creation_tasks_with_agents():
"""
Agents are not required for tasks in a hierarchical process but sometimes they are still added
This test makes sure that the manager still delegates the task to the agent even if the agent is passed in the task
"""
from langchain_openai import ChatOpenAI
task = Task(
description="Write one amazing paragraph about AI.",
expected_output="A single paragraph with 4 sentences.",
agent=writer,
)
crew = Crew(
tasks=[task],
agents=[writer, researcher],
process=Process.hierarchical,
manager_llm=ChatOpenAI(model="gpt-4o"),
)
crew.kickoff()
assert crew.manager_agent is not None
assert crew.manager_agent.tools is not None
assert crew.manager_agent.tools[0].description.startswith(
"Delegate a specific task to one of the following coworkers: [Senior Writer]"
)
@pytest.mark.vcr(filter_headers=["authorization"])
def test_hierarchical_crew_creation_tasks_without_async_execution():
from langchain_openai import ChatOpenAI
task = Task(
description="Come up with a list of 5 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="5 bullet points with a paragraph for each idea.",
async_execution=True, # should throw an error
)
with pytest.raises(pydantic_core._pydantic_core.ValidationError) as exec_info:
Crew(
tasks=[task],
agents=[researcher],
process=Process.hierarchical,
manager_llm=ChatOpenAI(model="gpt-4o"),
)
assert (
exec_info.value.errors()[0]["type"] == "async_execution_in_hierarchical_process"
)
assert (
"Hierarchical process error: Tasks cannot be flagged with async_execution."
in exec_info.value.errors()[0]["msg"]
)
def test_crew_inputs_interpolate_both_agents_and_tasks(): def test_crew_inputs_interpolate_both_agents_and_tasks():
agent = Agent( agent = Agent(
role="{topic} Researcher", role="{topic} Researcher",
@@ -1068,9 +1146,10 @@ def test_crew_inputs_interpolate_both_agents_and_tasks():
task = Task( task = Task(
description="Give me an analysis around {topic}.", description="Give me an analysis around {topic}.",
expected_output="{points} bullet points about {topic}.", expected_output="{points} bullet points about {topic}.",
agent=agent,
) )
crew = Crew(agents=[agent], tasks=[task], inputs={"topic": "AI", "points": 5}) crew = Crew(agents=[agent], tasks=[task])
inputs = {"topic": "AI", "points": 5} inputs = {"topic": "AI", "points": 5}
crew._interpolate_inputs(inputs=inputs) # Manual call for now crew._interpolate_inputs(inputs=inputs) # Manual call for now
@@ -1375,6 +1454,7 @@ def test_crew_train_success(task_evaluator, crew_training_handler, kickoff):
task = Task( task = Task(
description="Come up with a list of 5 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.", description="Come up with a list of 5 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="5 bullet points with a paragraph for each idea.", expected_output="5 bullet points with a paragraph for each idea.",
agent=researcher,
) )
crew = Crew( crew = Crew(
@@ -1429,6 +1509,7 @@ def test_crew_train_error():
task = Task( task = Task(
description="Come up with a list of 5 interesting ideas to explore for an article", description="Come up with a list of 5 interesting ideas to explore for an article",
expected_output="5 bullet points with a paragraph for each idea.", expected_output="5 bullet points with a paragraph for each idea.",
agent=researcher,
) )
crew = Crew( crew = Crew(
@@ -1450,6 +1531,7 @@ def test__setup_for_training():
task = Task( task = Task(
description="Come up with a list of 5 interesting ideas to explore for an article", description="Come up with a list of 5 interesting ideas to explore for an article",
expected_output="5 bullet points with a paragraph for each idea.", expected_output="5 bullet points with a paragraph for each idea.",
agent=researcher,
) )
crew = Crew( crew = Crew(