mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 23:32:39 +00:00
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:
@@ -16,11 +16,6 @@ from crewai.tools.base_tool import BaseTool
|
|||||||
from crewai.tools.structured_tool import CrewStructuredTool
|
from crewai.tools.structured_tool import CrewStructuredTool
|
||||||
from crewai.tools.tool_types import ToolResult
|
from crewai.tools.tool_types import ToolResult
|
||||||
from crewai.utilities import I18N, Printer
|
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.events.tool_usage_events import ToolUsageStartedEvent
|
||||||
from crewai.utilities.exceptions.context_window_exceeding_exception import (
|
from crewai.utilities.exceptions.context_window_exceeding_exception import (
|
||||||
LLMContextLengthExceededException,
|
LLMContextLengthExceededException,
|
||||||
@@ -46,7 +41,7 @@ def get_tool_names(tools: Sequence[Union[CrewStructuredTool, BaseTool]]) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def render_text_description_and_args(
|
def render_text_description_and_args(
|
||||||
tools: Sequence[Union[CrewStructuredTool, BaseTool]]
|
tools: Sequence[Union[CrewStructuredTool, BaseTool]],
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Render the tool name, description, and args in plain text.
|
"""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(
|
def enforce_rpm_limit(
|
||||||
request_within_rpm_limit: Optional[Callable[[], bool]] = None
|
request_within_rpm_limit: Optional[Callable[[], bool]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Enforce the requests per minute (RPM) limit if applicable."""
|
"""Enforce the requests per minute (RPM) limit if applicable."""
|
||||||
if request_within_rpm_limit:
|
if request_within_rpm_limit:
|
||||||
@@ -160,7 +155,6 @@ def get_llm_response(
|
|||||||
color="red",
|
color="red",
|
||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if not answer:
|
if not answer:
|
||||||
printer.print(
|
printer.print(
|
||||||
content="Received None or empty response from LLM call.",
|
content="Received None or empty response from LLM call.",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -385,6 +385,7 @@ def test_tools_emits_error_events():
|
|||||||
goal="Try to use the error tool",
|
goal="Try to use the error tool",
|
||||||
backstory="You are an assistant that tests error handling",
|
backstory="You are an assistant that tests error handling",
|
||||||
tools=[ErrorTool()],
|
tools=[ErrorTool()],
|
||||||
|
llm=LLM(model="gpt-4o-mini"),
|
||||||
)
|
)
|
||||||
|
|
||||||
task = Task(
|
task = Task(
|
||||||
@@ -396,7 +397,7 @@ def test_tools_emits_error_events():
|
|||||||
crew = Crew(agents=[agent], tasks=[task], name="TestCrew")
|
crew = Crew(agents=[agent], tasks=[task], name="TestCrew")
|
||||||
crew.kickoff()
|
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_key == agent.key
|
||||||
assert received_events[0].agent_role == agent.role
|
assert received_events[0].agent_role == agent.role
|
||||||
assert received_events[0].tool_name == "error_tool"
|
assert received_events[0].tool_name == "error_tool"
|
||||||
|
|||||||
Reference in New Issue
Block a user