fix: add ConfigDict for Pydantic model_config and ClassVar annotations

This commit is contained in:
Greyson LaLonde
2025-09-19 00:44:33 -04:00
parent eca9077590
commit 82cb72ea41
221 changed files with 2365 additions and 2202 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any
import pytest
from pydantic import BaseModel
@@ -12,7 +12,7 @@ from crewai.utilities.token_counter_callback import TokenProcess
# Concrete implementation for testing
class ConcreteAgentAdapter(BaseAgentAdapter):
def configure_tools(
self, tools: Optional[List[BaseTool]] = None, **kwargs: Any
self, tools: list[BaseTool] | None = None, **kwargs: Any
) -> None:
# Simple implementation for testing
self.tools = tools or []
@@ -20,19 +20,19 @@ class ConcreteAgentAdapter(BaseAgentAdapter):
def execute_task(
self,
task: Any,
context: Optional[str] = None,
tools: Optional[List[Any]] = None,
context: str | None = None,
tools: list[Any] | None = None,
) -> str:
# Dummy implementation needed due to BaseAgent inheritance
return "Task executed"
def create_agent_executor(self, tools: Optional[List[BaseTool]] = None) -> Any:
def create_agent_executor(self, tools: list[BaseTool] | None = None) -> Any:
# Dummy implementation
return None
def get_delegation_tools(
self, tools: List[BaseTool], tool_map: Optional[Dict[str, BaseTool]]
) -> List[BaseTool]:
self, tools: list[BaseTool], tool_map: dict[str, BaseTool] | None
) -> list[BaseTool]:
# Dummy implementation
return []
@@ -40,7 +40,7 @@ class ConcreteAgentAdapter(BaseAgentAdapter):
# Dummy implementation
pass
def get_output_converter(self, tools: Optional[List[BaseTool]] = None) -> Any:
def get_output_converter(self, tools: list[BaseTool] | None = None) -> Any:
# Dummy implementation
return None
@@ -95,7 +95,6 @@ def test_configure_structured_output_method_exists():
adapter.configure_structured_output(structured_output)
# Add assertions here if configure_structured_output modifies state
# For now, just ensuring it runs without error is sufficient
pass
def test_base_agent_adapter_inherits_base_agent():

View File

@@ -1,4 +1,3 @@
from typing import Any, List
from unittest.mock import Mock
import pytest
@@ -8,7 +7,7 @@ from crewai.tools.base_tool import BaseTool
class ConcreteToolAdapter(BaseToolAdapter):
def configure_tools(self, tools: List[BaseTool]) -> None:
def configure_tools(self, tools: list[BaseTool]) -> None:
self.converted_tools = [f"converted_{tool.name}" for tool in tools]

View File

@@ -1,5 +1,5 @@
import hashlib
from typing import Any, List, Optional
from typing import Any
from pydantic import BaseModel
@@ -11,14 +11,14 @@ class MockAgent(BaseAgent):
def execute_task(
self,
task: Any,
context: Optional[str] = None,
tools: Optional[List[BaseTool]] = None,
context: str | None = None,
tools: list[BaseTool] | None = None,
) -> str:
return ""
def create_agent_executor(self, tools=None) -> None: ...
def get_delegation_tools(self, agents: List["BaseAgent"]): ...
def get_delegation_tools(self, agents: list["BaseAgent"]): ...
def get_output_converter(
self, llm: Any, text: str, model: type[BaseModel] | None, instructions: str

View File

@@ -1,6 +1,7 @@
"""Tests for reasoning in agents."""
import json
import pytest
from crewai import Agent, Task
@@ -79,10 +80,8 @@ def test_agent_with_reasoning_not_ready_initially(mock_llm_responses):
call_count[0] += 1
if call_count[0] == 1:
return mock_llm_responses["not_ready"]
else:
return mock_llm_responses["ready_after_refine"]
else:
return "2x"
return mock_llm_responses["ready_after_refine"]
return "2x"
agent.llm.call = mock_llm_call
@@ -121,8 +120,7 @@ def test_agent_with_reasoning_max_attempts_reached():
) or any("refine your plan" in msg.get("content", "") for msg in messages):
call_count[0] += 1
return f"Attempt {call_count[0]}: I need more time to think.\n\nNOT READY: I need to refine my plan further."
else:
return "This is an unsolved problem in mathematics."
return "This is an unsolved problem in mathematics."
agent.llm.call = mock_llm_call
@@ -215,8 +213,7 @@ def test_agent_with_function_calling():
return json.dumps(
{"plan": "I'll solve this simple math problem: 2+2=4.", "ready": True}
)
else:
return "4"
return "4"
agent.llm.call = mock_function_call
@@ -251,8 +248,7 @@ def test_agent_with_function_calling_fallback():
def mock_function_call(messages, *args, **kwargs):
if "tools" in kwargs:
return "Invalid JSON that will trigger fallback. READY: I am ready to execute the task."
else:
return "4"
return "4"
agent.llm.call = mock_function_call

View File

@@ -1,11 +1,11 @@
import pytest
from crewai.agents import parser
from crewai.agents.crew_agent_executor import (
AgentAction,
AgentFinish,
OutputParserException,
)
from crewai.agents import parser
def test_valid_action_parsing_special_characters():

View File

@@ -1,4 +1,3 @@
# ruff: noqa: S101
# mypy: ignore-errors
from collections import defaultdict
from typing import cast