Compare commits

...

6 Commits

Author SHA1 Message Date
Devin AI
74c1f7492a Fix lint: Apply automatic fixes from ruff linter
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-19 23:16:22 +00:00
Devin AI
559442853e Fix lint: Add unittest import to match project conventions
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-19 23:14:44 +00:00
Devin AI
65dd3c1bdc Fix lint: Correct import order in test file
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-19 23:12:48 +00:00
Devin AI
5ebd3ce269 Fix CI issues: Fix import sorting and type error
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-19 23:10:40 +00:00
Devin AI
7ff66aaf71 Fix security: Use mock approach in tests instead of hardcoded API keys
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-19 23:08:16 +00:00
Devin AI
f7ecc0bc47 Fix issue #2647: Make planning LLM inherit authentication parameters from agent's LLM
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-19 23:06:52 +00:00
4 changed files with 48 additions and 3 deletions

View File

@@ -720,8 +720,13 @@ class Crew(BaseModel):
def _handle_crew_planning(self):
"""Handles the Crew planning."""
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(
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()
for task, step_plan in zip(self.tasks, result.list_of_plans_per_task):

View File

@@ -28,11 +28,23 @@ class PlannerTaskPydanticOutput(BaseModel):
class CrewPlanner:
"""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
if planning_agent_llm is None:
self.planning_agent_llm = "gpt-4o-mini"
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:
from crewai.llm import LLM
self.planning_agent_llm = LLM(model="gpt-4o-mini")
else:
self.planning_agent_llm = planning_agent_llm

View File

@@ -0,0 +1,28 @@
import unittest
from unittest.mock import MagicMock
from crewai import Task
from crewai.utilities.planning_handler import CrewPlanner
def test_planning_llm_inherits_auth_params():
"""Test that planning LLM inherits authentication parameters from agent LLM."""
mock_llm = MagicMock()
mock_llm.base_url = "https://api.custom-provider.com/v1"
mock_llm.api_version = "2023-05-15"
task = Task(
description="Test Task",
expected_output="Test Output"
)
planner = CrewPlanner(
tasks=[task],
planning_agent_llm=None, # This should trigger the inheritance logic
agent_llm=mock_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_version == "2023-05-15"