mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
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:
@@ -720,8 +720,13 @@ class Crew(BaseModel):
|
|||||||
def _handle_crew_planning(self):
|
def _handle_crew_planning(self):
|
||||||
"""Handles the Crew planning."""
|
"""Handles the Crew planning."""
|
||||||
self._logger.log("info", "Planning the crew execution")
|
self._logger.log("info", "Planning the crew execution")
|
||||||
|
|
||||||
|
agent_llm = self.agents[0].llm if self.agents and hasattr(self.agents[0], 'llm') else None
|
||||||
|
|
||||||
result = CrewPlanner(
|
result = CrewPlanner(
|
||||||
tasks=self.tasks, planning_agent_llm=self.planning_llm
|
tasks=self.tasks,
|
||||||
|
planning_agent_llm=self.planning_llm,
|
||||||
|
agent_llm=agent_llm
|
||||||
)._handle_crew_planning()
|
)._handle_crew_planning()
|
||||||
|
|
||||||
for task, step_plan in zip(self.tasks, result.list_of_plans_per_task):
|
for task, step_plan in zip(self.tasks, result.list_of_plans_per_task):
|
||||||
|
|||||||
@@ -28,10 +28,21 @@ class PlannerTaskPydanticOutput(BaseModel):
|
|||||||
|
|
||||||
class CrewPlanner:
|
class CrewPlanner:
|
||||||
"""Plans and coordinates the execution of crew tasks."""
|
"""Plans and coordinates the execution of crew tasks."""
|
||||||
def __init__(self, tasks: List[Task], planning_agent_llm: Optional[Any] = None):
|
def __init__(self, tasks: List[Task], planning_agent_llm: Optional[Any] = None, agent_llm: Optional[Any] = None):
|
||||||
self.tasks = tasks
|
self.tasks = tasks
|
||||||
|
|
||||||
if planning_agent_llm is None:
|
if planning_agent_llm is None:
|
||||||
|
if agent_llm is not None and hasattr(agent_llm, "base_url") and agent_llm.base_url is not None:
|
||||||
|
from crewai.llm import LLM
|
||||||
|
self.planning_agent_llm = LLM(
|
||||||
|
model="gpt-4o-mini",
|
||||||
|
base_url=agent_llm.base_url,
|
||||||
|
api_key=getattr(agent_llm, "api_key", None),
|
||||||
|
organization=getattr(agent_llm, "organization", None),
|
||||||
|
api_version=getattr(agent_llm, "api_version", None),
|
||||||
|
extra_headers=getattr(agent_llm, "extra_headers", None)
|
||||||
|
)
|
||||||
|
else:
|
||||||
self.planning_agent_llm = "gpt-4o-mini"
|
self.planning_agent_llm = "gpt-4o-mini"
|
||||||
else:
|
else:
|
||||||
self.planning_agent_llm = planning_agent_llm
|
self.planning_agent_llm = planning_agent_llm
|
||||||
|
|||||||
0
tests/utilities/test_planning_auth/__init__.py
Normal file
0
tests/utilities/test_planning_auth/__init__.py
Normal 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
|
||||||
Reference in New Issue
Block a user