Fix issue #2647: Make planning LLM inherit authentication parameters from agent's LLM

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-19 23:06:52 +00:00
parent 311a078ca6
commit f7ecc0bc47
4 changed files with 58 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
from crewai import Agent, Task
from crewai.llm import LLM
from crewai.utilities.planning_handler import CrewPlanner
def test_planning_llm_inherits_auth_params():
"""Test that planning LLM inherits authentication parameters from agent LLM."""
custom_llm = LLM(
model="custom-model",
base_url="https://api.custom-provider.com/v1",
api_key="fake-api-key",
api_version="2023-05-15",
organization="custom-org"
)
agent = Agent(
role="Test Agent",
goal="Test Goal",
backstory="Test Backstory",
llm=custom_llm
)
task = Task(
description="Test Task",
expected_output="Test Output",
agent=agent
)
planner = CrewPlanner(
tasks=[task],
planning_agent_llm=None, # This should trigger the inheritance logic
agent_llm=custom_llm
)
assert hasattr(planner, 'planning_agent_llm')
assert hasattr(planner.planning_agent_llm, 'base_url')
assert planner.planning_agent_llm.base_url == "https://api.custom-provider.com/v1"
assert planner.planning_agent_llm.api_key == "fake-api-key"
assert planner.planning_agent_llm.api_version == "2023-05-15"
# organization is not directly accessible as an attribute