mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 16:48:30 +00:00
- Replace Dict, List, Set, Tuple with dict, list, set, tuple throughout codebase - Add missing type annotations to crew_events.py methods - Add proper type annotations to test_crew_cancellation.py - Use type: ignore[method-assign] comments for mock assignments - Maintain backward compatibility while modernizing type hints This resolves lint and type-checker failures in CI while preserving the cancellation functionality. Co-Authored-By: João <joao@crewai.com>
67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
from typing import Any, Optional, TYPE_CHECKING
|
|
|
|
from pydantic import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from crewai.agent import Agent
|
|
from crewai.task import Task
|
|
|
|
|
|
class Memory(BaseModel):
|
|
"""
|
|
Base class for memory, now supporting agent tags and generic metadata.
|
|
"""
|
|
|
|
embedder_config: Optional[dict[str, Any]] = None
|
|
crew: Optional[Any] = None
|
|
|
|
storage: Any
|
|
_agent: Optional["Agent"] = None
|
|
_task: Optional["Task"] = None
|
|
|
|
def __init__(self, storage: Any, **data: Any):
|
|
super().__init__(storage=storage, **data)
|
|
|
|
@property
|
|
def task(self) -> Optional["Task"]:
|
|
"""Get the current task associated with this memory."""
|
|
return self._task
|
|
|
|
@task.setter
|
|
def task(self, task: Optional["Task"]) -> None:
|
|
"""Set the current task associated with this memory."""
|
|
self._task = task
|
|
|
|
@property
|
|
def agent(self) -> Optional["Agent"]:
|
|
"""Get the current agent associated with this memory."""
|
|
return self._agent
|
|
|
|
@agent.setter
|
|
def agent(self, agent: Optional["Agent"]) -> None:
|
|
"""Set the current agent associated with this memory."""
|
|
self._agent = agent
|
|
|
|
def save(
|
|
self,
|
|
value: Any,
|
|
metadata: Optional[dict[str, Any]] = None,
|
|
) -> None:
|
|
metadata = metadata or {}
|
|
|
|
self.storage.save(value, metadata)
|
|
|
|
def search(
|
|
self,
|
|
query: str,
|
|
limit: int = 3,
|
|
score_threshold: float = 0.35,
|
|
) -> list[Any]:
|
|
return self.storage.search(
|
|
query=query, limit=limit, score_threshold=score_threshold
|
|
)
|
|
|
|
def set_crew(self, crew: Any) -> "Memory":
|
|
self.crew = crew
|
|
return self
|