mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
fix: Replace remaining deprecated typing imports with built-in types
- Replace List[...] with list[...] in crew.py method signatures - Replace Dict[str, Any] with dict[str, Any] in crew.py and task.py - Fix all undefined name errors from deprecated typing imports - Maintain backward compatibility while modernizing type hints Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import uuid
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from copy import copy as shallow_copy
|
from copy import copy as shallow_copy
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from typing import Any, Callable, Dict, List, Optional, TypeVar
|
from typing import Any, Callable, Optional, TypeVar
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
UUID4,
|
UUID4,
|
||||||
|
|||||||
2
src/crewai/agents/cache/cache_handler.py
vendored
2
src/crewai/agents/cache/cache_handler.py
vendored
@@ -1,4 +1,4 @@
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, PrivateAttr
|
from pydantic import BaseModel, PrivateAttr
|
||||||
|
|
||||||
|
|||||||
@@ -860,7 +860,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
tools_for_task = self._prepare_tools(
|
tools_for_task = self._prepare_tools(
|
||||||
agent_to_use,
|
agent_to_use,
|
||||||
task,
|
task,
|
||||||
cast(Union[List[Tool], List[BaseTool]], tools_for_task),
|
cast(Union[list[Tool], list[BaseTool]], tools_for_task),
|
||||||
)
|
)
|
||||||
|
|
||||||
self._log_task_start(task, agent_to_use.role)
|
self._log_task_start(task, agent_to_use.role)
|
||||||
@@ -986,7 +986,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
# Add all new tools
|
# Add all new tools
|
||||||
tools.extend(new_tools)
|
tools.extend(new_tools)
|
||||||
|
|
||||||
return cast(List[BaseTool], tools)
|
return cast(list[BaseTool], tools)
|
||||||
|
|
||||||
def _inject_delegation_tools(
|
def _inject_delegation_tools(
|
||||||
self,
|
self,
|
||||||
@@ -1001,8 +1001,8 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
return cast(list[BaseTool], tools)
|
return cast(list[BaseTool], tools)
|
||||||
|
|
||||||
def _add_multimodal_tools(
|
def _add_multimodal_tools(
|
||||||
self, agent: BaseAgent, tools: Union[List[Tool], List[BaseTool]]
|
self, agent: BaseAgent, tools: Union[list[Tool], list[BaseTool]]
|
||||||
) -> List[BaseTool]:
|
) -> list[BaseTool]:
|
||||||
if hasattr(agent, "get_multimodal_tools"):
|
if hasattr(agent, "get_multimodal_tools"):
|
||||||
multimodal_tools = agent.get_multimodal_tools()
|
multimodal_tools = agent.get_multimodal_tools()
|
||||||
# Cast multimodal_tools to the expected type for _merge_tools
|
# Cast multimodal_tools to the expected type for _merge_tools
|
||||||
@@ -1010,17 +1010,17 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
return cast(list[BaseTool], tools)
|
return cast(list[BaseTool], tools)
|
||||||
|
|
||||||
def _add_code_execution_tools(
|
def _add_code_execution_tools(
|
||||||
self, agent: BaseAgent, tools: Union[List[Tool], List[BaseTool]]
|
self, agent: BaseAgent, tools: Union[list[Tool], list[BaseTool]]
|
||||||
) -> List[BaseTool]:
|
) -> list[BaseTool]:
|
||||||
if hasattr(agent, "get_code_execution_tools"):
|
if hasattr(agent, "get_code_execution_tools"):
|
||||||
code_tools = agent.get_code_execution_tools()
|
code_tools = agent.get_code_execution_tools()
|
||||||
# Cast code_tools to the expected type for _merge_tools
|
# Cast code_tools to the expected type for _merge_tools
|
||||||
return self._merge_tools(tools, cast(List[BaseTool], code_tools))
|
return self._merge_tools(tools, cast(list[BaseTool], code_tools))
|
||||||
return cast(List[BaseTool], tools)
|
return cast(list[BaseTool], tools)
|
||||||
|
|
||||||
def _add_delegation_tools(
|
def _add_delegation_tools(
|
||||||
self, task: Task, tools: Union[List[Tool], List[BaseTool]]
|
self, task: Task, tools: Union[list[Tool], list[BaseTool]]
|
||||||
) -> List[BaseTool]:
|
) -> list[BaseTool]:
|
||||||
agents_for_delegation = [agent for agent in self.agents if agent != task.agent]
|
agents_for_delegation = [agent for agent in self.agents if agent != task.agent]
|
||||||
if len(self.agents) > 1 and len(agents_for_delegation) > 0 and task.agent:
|
if len(self.agents) > 1 and len(agents_for_delegation) > 0 and task.agent:
|
||||||
if not tools:
|
if not tools:
|
||||||
@@ -1028,7 +1028,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
tools = self._inject_delegation_tools(
|
tools = self._inject_delegation_tools(
|
||||||
tools, task.agent, agents_for_delegation
|
tools, task.agent, agents_for_delegation
|
||||||
)
|
)
|
||||||
return cast(List[BaseTool], tools)
|
return cast(list[BaseTool], tools)
|
||||||
|
|
||||||
def _log_task_start(self, task: Task, role: str = "None"):
|
def _log_task_start(self, task: Task, role: str = "None"):
|
||||||
if self.output_log_file:
|
if self.output_log_file:
|
||||||
@@ -1037,8 +1037,8 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _update_manager_tools(
|
def _update_manager_tools(
|
||||||
self, task: Task, tools: Union[List[Tool], List[BaseTool]]
|
self, task: Task, tools: Union[list[Tool], list[BaseTool]]
|
||||||
) -> List[BaseTool]:
|
) -> list[BaseTool]:
|
||||||
if self.manager_agent:
|
if self.manager_agent:
|
||||||
if task.agent:
|
if task.agent:
|
||||||
tools = self._inject_delegation_tools(tools, task.agent, [task.agent])
|
tools = self._inject_delegation_tools(tools, task.agent, [task.agent])
|
||||||
@@ -1046,9 +1046,9 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
tools = self._inject_delegation_tools(
|
tools = self._inject_delegation_tools(
|
||||||
tools, self.manager_agent, self.agents
|
tools, self.manager_agent, self.agents
|
||||||
)
|
)
|
||||||
return cast(List[BaseTool], tools)
|
return cast(list[BaseTool], tools)
|
||||||
|
|
||||||
def _get_context(self, task: Task, task_outputs: List[TaskOutput]) -> str:
|
def _get_context(self, task: Task, task_outputs: list[TaskOutput]) -> str:
|
||||||
if not task.context:
|
if not task.context:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@@ -1070,7 +1070,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
output=output.raw,
|
output=output.raw,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _create_crew_output(self, task_outputs: List[TaskOutput]) -> CrewOutput:
|
def _create_crew_output(self, task_outputs: list[TaskOutput]) -> CrewOutput:
|
||||||
if not task_outputs:
|
if not task_outputs:
|
||||||
raise ValueError("No task outputs available to create crew output.")
|
raise ValueError("No task outputs available to create crew output.")
|
||||||
|
|
||||||
@@ -1119,7 +1119,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
return task_outputs
|
return task_outputs
|
||||||
|
|
||||||
def _find_task_index(
|
def _find_task_index(
|
||||||
self, task_id: str, stored_outputs: List[Any]
|
self, task_id: str, stored_outputs: list[Any]
|
||||||
) -> Optional[int]:
|
) -> Optional[int]:
|
||||||
return next(
|
return next(
|
||||||
(
|
(
|
||||||
@@ -1291,7 +1291,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
if not task.callback:
|
if not task.callback:
|
||||||
task.callback = self.task_callback
|
task.callback = self.task_callback
|
||||||
|
|
||||||
def _interpolate_inputs(self, inputs: Dict[str, Any]) -> None:
|
def _interpolate_inputs(self, inputs: dict[str, Any]) -> None:
|
||||||
"""Interpolates the inputs in the tasks and agents."""
|
"""Interpolates the inputs in the tasks and agents."""
|
||||||
[
|
[
|
||||||
task.interpolate_inputs_and_add_conversation_history(
|
task.interpolate_inputs_and_add_conversation_history(
|
||||||
@@ -1325,7 +1325,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
self,
|
self,
|
||||||
n_iterations: int,
|
n_iterations: int,
|
||||||
eval_llm: Union[str, InstanceOf[BaseLLM]],
|
eval_llm: Union[str, InstanceOf[BaseLLM]],
|
||||||
inputs: Optional[Dict[str, Any]] = None,
|
inputs: Optional[dict[str, Any]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test and evaluate the Crew with the given inputs for n iterations concurrently using concurrent.futures."""
|
"""Test and evaluate the Crew with the given inputs for n iterations concurrently using concurrent.futures."""
|
||||||
try:
|
try:
|
||||||
@@ -1523,7 +1523,7 @@ class Crew(FlowTrackable, BaseModel):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def reset_knowledge(self, knowledges: List[Knowledge]) -> None:
|
def reset_knowledge(self, knowledges: list[Knowledge]) -> None:
|
||||||
"""Reset crew and agent knowledge storage."""
|
"""Reset crew and agent knowledge storage."""
|
||||||
for ks in knowledges:
|
for ks in knowledges:
|
||||||
ks.reset()
|
ks.reset()
|
||||||
|
|||||||
@@ -13,11 +13,7 @@ from typing import (
|
|||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
ClassVar,
|
ClassVar,
|
||||||
Dict,
|
|
||||||
List,
|
|
||||||
Optional,
|
Optional,
|
||||||
Set,
|
|
||||||
Tuple,
|
|
||||||
Type,
|
Type,
|
||||||
Union,
|
Union,
|
||||||
get_args,
|
get_args,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import time
|
|||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||||
|
|
||||||
import json5
|
import json5
|
||||||
from json_repair import repair_json
|
from json_repair import repair_json
|
||||||
|
|||||||
Reference in New Issue
Block a user