Files
crewAI/src/crewai/memory/memory.py
Devin AI 709b8077dd Fix: Format imports to pass lint checks
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-10 07:02:18 +00:00

51 lines
1.1 KiB
Python

import sys
from pydantic import BaseModel
if sys.version_info < (3, 11):
from typing import Any, Dict, List, Optional
from typing_extensions import Self
else:
from typing import Any, Dict, List, Optional, Self
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
def __init__(self, storage: Any, **data: Any):
super().__init__(storage=storage, **data)
def save(
self,
value: Any,
metadata: Optional[Dict[str, Any]] = None,
agent: Optional[str] = None,
) -> None:
metadata = metadata or {}
if agent:
metadata["agent"] = agent
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) -> Self:
self.crew = crew
return self