mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-23 07:08:14 +00:00
fix: address mypy type errors in multiple files
- Fix return type and argument handling in cache_tools.py - Add missing return statements in agent.py - Fix _inject_date_to_task signature to accept Task object - Remove unused type:ignore comments in tool_usage.py - Add type annotations to internal methods in mem0_storage.py
This commit is contained in:
@@ -620,6 +620,7 @@ class Agent(BaseAgent):
|
|||||||
self._logger.log(
|
self._logger.log(
|
||||||
"info", "Coding tools not available. Install crewai_tools. "
|
"info", "Coding tools not available. Install crewai_tools. "
|
||||||
)
|
)
|
||||||
|
return []
|
||||||
|
|
||||||
def get_output_converter(
|
def get_output_converter(
|
||||||
self, llm: BaseLLM, text: str, model: str, instructions: str
|
self, llm: BaseLLM, text: str, model: str, instructions: str
|
||||||
@@ -671,7 +672,7 @@ class Agent(BaseAgent):
|
|||||||
|
|
||||||
return description
|
return description
|
||||||
|
|
||||||
def _inject_date_to_task(self, task: str) -> str:
|
def _inject_date_to_task(self, task: Task) -> None:
|
||||||
"""Inject the current date into the task description if inject_date is enabled."""
|
"""Inject the current date into the task description if inject_date is enabled."""
|
||||||
if self.inject_date:
|
if self.inject_date:
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ class Mem0Storage(Storage):
|
|||||||
Extends Storage to handle embedding and searching across entities using Mem0.
|
Extends Storage to handle embedding and searching across entities using Mem0.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, type, crew=None, config=None):
|
def __init__(
|
||||||
|
self, type: str, crew: Any = None, config: dict[str, Any] | None = None
|
||||||
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._validate_type(type)
|
self._validate_type(type)
|
||||||
@@ -26,21 +28,21 @@ class Mem0Storage(Storage):
|
|||||||
self._extract_config_values()
|
self._extract_config_values()
|
||||||
self._initialize_memory()
|
self._initialize_memory()
|
||||||
|
|
||||||
def _validate_type(self, type):
|
def _validate_type(self, type: str) -> None:
|
||||||
supported_types = {"short_term", "long_term", "entities", "external"}
|
supported_types = {"short_term", "long_term", "entities", "external"}
|
||||||
if type not in supported_types:
|
if type not in supported_types:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid type '{type}' for Mem0Storage. Must be one of: {', '.join(supported_types)}"
|
f"Invalid type '{type}' for Mem0Storage. Must be one of: {', '.join(supported_types)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _extract_config_values(self):
|
def _extract_config_values(self) -> None:
|
||||||
self.mem0_run_id = self.config.get("run_id")
|
self.mem0_run_id = self.config.get("run_id")
|
||||||
self.includes = self.config.get("includes")
|
self.includes = self.config.get("includes")
|
||||||
self.excludes = self.config.get("excludes")
|
self.excludes = self.config.get("excludes")
|
||||||
self.custom_categories = self.config.get("custom_categories")
|
self.custom_categories = self.config.get("custom_categories")
|
||||||
self.infer = self.config.get("infer", True)
|
self.infer = self.config.get("infer", True)
|
||||||
|
|
||||||
def _initialize_memory(self):
|
def _initialize_memory(self) -> None:
|
||||||
api_key = self.config.get("api_key") or os.getenv("MEM0_API_KEY")
|
api_key = self.config.get("api_key") or os.getenv("MEM0_API_KEY")
|
||||||
org_id = self.config.get("org_id")
|
org_id = self.config.get("org_id")
|
||||||
project_id = self.config.get("project_id")
|
project_id = self.config.get("project_id")
|
||||||
@@ -61,7 +63,7 @@ class Mem0Storage(Storage):
|
|||||||
else Memory()
|
else Memory()
|
||||||
)
|
)
|
||||||
|
|
||||||
def _create_filter_for_search(self):
|
def _create_filter_for_search(self) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
dict: A filter dictionary containing AND conditions for querying data.
|
dict: A filter dictionary containing AND conditions for querying data.
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ class CacheTools(BaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def hit_cache(self, key: str) -> str:
|
def hit_cache(self, key: str) -> str:
|
||||||
|
import json
|
||||||
|
|
||||||
split = key.split("tool:")
|
split = key.split("tool:")
|
||||||
tool = split[1].split("|input:")[0].strip()
|
tool = split[1].split("|input:")[0].strip()
|
||||||
tool_input = split[1].split("|input:")[1].strip()
|
tool_input_str = split[1].split("|input:")[1].strip()
|
||||||
return self.cache_handler.read(tool, tool_input)
|
tool_input = json.loads(tool_input_str) if tool_input_str else None
|
||||||
|
result = self.cache_handler.read(tool, tool_input)
|
||||||
|
return result if result is not None else ""
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ class ToolUsage:
|
|||||||
if self.tools_handler and self.tools_handler.cache:
|
if self.tools_handler and self.tools_handler.cache:
|
||||||
result = self.tools_handler.cache.read(
|
result = self.tools_handler.cache.read(
|
||||||
tool=calling.tool_name, input_data=calling.arguments
|
tool=calling.tool_name, input_data=calling.arguments
|
||||||
) # type: ignore
|
)
|
||||||
from_cache = result is not None
|
from_cache = result is not None
|
||||||
|
|
||||||
available_tool = next(
|
available_tool = next(
|
||||||
@@ -322,7 +322,7 @@ class ToolUsage:
|
|||||||
and available_tool.result_as_answer # type: ignore # Item "None" of "Any | None" has no attribute "cache_function"
|
and available_tool.result_as_answer # type: ignore # Item "None" of "Any | None" has no attribute "cache_function"
|
||||||
):
|
):
|
||||||
result_as_answer = available_tool.result_as_answer # type: ignore # Item "None" of "Any | None" has no attribute "result_as_answer"
|
result_as_answer = available_tool.result_as_answer # type: ignore # Item "None" of "Any | None" has no attribute "result_as_answer"
|
||||||
data["result_as_answer"] = result_as_answer # type: ignore
|
data["result_as_answer"] = result_as_answer
|
||||||
|
|
||||||
if self.agent and hasattr(self.agent, "tools_results"):
|
if self.agent and hasattr(self.agent, "tools_results"):
|
||||||
self.agent.tools_results.append(data)
|
self.agent.tools_results.append(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user