Improve docstrings and test clarity as requested in PR review

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-03 11:50:57 +00:00
parent d1ffef6f3c
commit 52a81d15b5
3 changed files with 28 additions and 4 deletions

View File

@@ -1827,6 +1827,9 @@ def test_agent_uses_own_llm_for_function_calling_when_not_specified():
Test that an agent uses its own LLM for function calling when no function_calling_llm
is specified, ensuring that non-OpenAI models like Gemini can be used without
requiring OpenAI API keys.
This test verifies the fix for issue #2517, where users would get OpenAI authentication
errors even when using non-OpenAI models like Gemini.
"""
@tool
def simple_tool(input_text: str) -> str:
@@ -1853,8 +1856,8 @@ def test_agent_uses_own_llm_for_function_calling_when_not_specified():
agent.execute_task(task, tools=[simple_tool])
args, kwargs = mock_tool_usage.call_args
assert kwargs['function_calling_llm'] == agent.llm
assert kwargs['function_calling_llm'].model.startswith("gemini")
assert kwargs['function_calling_llm'] == agent.llm, "Agent should use its own LLM for function calling"
assert kwargs['function_calling_llm'].model.startswith("gemini"), "Function calling LLM should be Gemini"
except Exception as e:
if "OPENAI_API_KEY" in str(e):
pytest.fail("Test failed with OpenAI API key error despite using Gemini model")

View File

@@ -4127,6 +4127,10 @@ def test_crew_agents_use_own_llm_for_function_calling():
"""
Test that agents in a crew use their own LLM for function calling when no
function_calling_llm is specified for either the agent or the crew.
This test verifies the fix for issue #2517, where users would get OpenAI authentication
errors even when using non-OpenAI models like Gemini. The fix ensures that when no
function_calling_llm is specified, the agent uses its own LLM for function calling.
"""
@tool
def simple_tool(input_text: str) -> str:
@@ -4160,8 +4164,8 @@ def test_crew_agents_use_own_llm_for_function_calling():
crew.kickoff()
args, kwargs = mock_tool_usage.call_args
assert kwargs['function_calling_llm'] == gemini_agent.llm
assert kwargs['function_calling_llm'].model.startswith("gemini")
assert kwargs['function_calling_llm'] == gemini_agent.llm, "Agent should use its own LLM for function calling"
assert kwargs['function_calling_llm'].model.startswith("gemini"), "Function calling LLM should be Gemini"
except Exception as e:
if "OPENAI_API_KEY" in str(e):
pytest.fail("Test failed with OpenAI API key error despite using Gemini model")