Refactor agent_utils.py by removing unused event imports and adding missing commas in function definitions. Update test_events.py to reflect changes in expected event counts and adjust assertions accordingly. Modify test_tools_emits_error_events.yaml to include new headers and update response content for consistency with recent API changes.

This commit is contained in:
Lorenze Jay
2025-03-31 15:21:44 -07:00
parent b8d871e795
commit 288afba5fa
3 changed files with 10850 additions and 5783 deletions

View File

@@ -16,11 +16,6 @@ from crewai.tools.base_tool import BaseTool
from crewai.tools.structured_tool import CrewStructuredTool
from crewai.tools.tool_types import ToolResult
from crewai.utilities import I18N, Printer
from crewai.utilities.events import (
ToolUsageErrorEvent,
ToolUsageStartedEvent,
crewai_event_bus,
)
from crewai.utilities.events.tool_usage_events import ToolUsageStartedEvent
from crewai.utilities.exceptions.context_window_exceeding_exception import (
LLMContextLengthExceededException,
@@ -46,7 +41,7 @@ def get_tool_names(tools: Sequence[Union[CrewStructuredTool, BaseTool]]) -> str:
def render_text_description_and_args(
tools: Sequence[Union[CrewStructuredTool, BaseTool]]
tools: Sequence[Union[CrewStructuredTool, BaseTool]],
) -> str:
"""Render the tool name, description, and args in plain text.
@@ -135,7 +130,7 @@ def format_answer(answer: str) -> Union[AgentAction, AgentFinish]:
def enforce_rpm_limit(
request_within_rpm_limit: Optional[Callable[[], bool]] = None
request_within_rpm_limit: Optional[Callable[[], bool]] = None,
) -> None:
"""Enforce the requests per minute (RPM) limit if applicable."""
if request_within_rpm_limit:
@@ -160,7 +155,6 @@ def get_llm_response(
color="red",
)
raise e
if not answer:
printer.print(
content="Received None or empty response from LLM call.",

File diff suppressed because it is too large Load Diff

View File

@@ -385,6 +385,7 @@ def test_tools_emits_error_events():
goal="Try to use the error tool",
backstory="You are an assistant that tests error handling",
tools=[ErrorTool()],
llm=LLM(model="gpt-4o-mini"),
)
task = Task(
@@ -396,7 +397,7 @@ def test_tools_emits_error_events():
crew = Crew(agents=[agent], tasks=[task], name="TestCrew")
crew.kickoff()
assert len(received_events) == 75
assert len(received_events) == 48
assert received_events[0].agent_key == agent.key
assert received_events[0].agent_role == agent.role
assert received_events[0].tool_name == "error_tool"