Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

test(agents): cover native result as answer (#7334) (#7336)

Liangshanbobo929a17357568
diff --git a/lib/crewai/tests/agents/test_agent.py b/lib/crewai/tests/agents/test_agent.py
index 98d220bd1..74403ccd8 100644
--- a/lib/crewai/tests/agents/test_agent.py
+++ b/lib/crewai/tests/agents/test_agent.py
@@ -700,9 +700,8 @@ def test_agent_step_callback():
callback.assert_called()
[email protected](reason="result_as_answer feature not yet implemented in native tool calling path")
-def test_tool_result_as_answer_is_the_final_answer_for_the_agent():
+def test_tool_result_as_answer_is_the_final_answer_for_the_agent() -> None:
+ """Use a native tool result as the Crew's final answer without another LLM call."""
from crewai.tools import BaseTool
class MyCustomTool(BaseTool):
@@ -710,13 +709,16 @@ def test_tool_result_as_answer_is_the_final_answer_for_the_agent():
description: str = "Get a random greeting back"
def _run(self) -> str:
+ """Return a deterministic greeting for the integration test."""
return "Howdy!"
+ llm = LLM(model="gpt-4o-mini")
agent1 = Agent(
role="Data Scientist",
goal="Product amazing resports on AI",
backstory="You work with data and AI",
tools=[MyCustomTool(result_as_answer=True)],
+ llm=llm,
)
essay = Task(
@@ -727,8 +729,18 @@ def test_tool_result_as_answer_is_the_final_answer_for_the_agent():
tasks = [essay]
crew = Crew(agents=[agent1], tasks=tasks)
- result = crew.kickoff()
+ tool_call = {
+ "id": "call_greeting",
+ "function": {"name": "get_greetings", "arguments": "{}"},
+ }
+ with patch(
+ "crewai.experimental.agent_executor.get_llm_response",
+ return_value=[tool_call],
+ ) as mock_llm_response:
+ result = crew.kickoff()
+
assert result.raw == "Howdy!"
+ mock_llm_response.assert_called_once()
def test_agent_definition_based_on_dict():