praval.memory.short_term_memory
Short-term working memory for Praval agents
This provides fast, in-memory storage for: - Current conversation context - Recent agent interactions - Active tasks and goals - Temporary state information
Classes
|
Fast, in-memory storage for short-term agent memory |
- class praval.memory.short_term_memory.ShortTermMemory(max_entries=1000, retention_hours=24, cleanup_interval=3600)[source]
Bases:
objectFast, in-memory storage for short-term agent memory
Features: - Thread-safe operations - Automatic cleanup of old memories - Context-aware retrieval - Working memory capacity limits
- Parameters:
max_entries (int)
retention_hours (int)
cleanup_interval (int)
- __init__(max_entries=1000, retention_hours=24, cleanup_interval=3600)[source]
Initialize short-term memory
- Parameters:
max_entries (
int) – Maximum number of entries to keepretention_hours (
int) – How long to keep memories (hours)cleanup_interval (
int) – How often to cleanup old memories (seconds)
- store(memory)[source]
Store a memory entry
- Parameters:
memory (
MemoryEntry) – The memory entry to store- Return type:
str- Returns:
The ID of the stored memory
- retrieve(memory_id)[source]
Retrieve a specific memory by ID
- Parameters:
memory_id (
str) – The ID of the memory to retrieve- Return type:
Optional[MemoryEntry]- Returns:
The memory entry if found, None otherwise
- search(query)[source]
Search memories using text similarity
- Parameters:
query (
MemoryQuery) – The search query- Return type:
- Returns:
Search results with matching memories
- get_recent(agent_id=None, limit=10)[source]
Get recent memories
- Parameters:
agent_id (
Optional[str]) – Filter by specific agentlimit (
int) – Maximum number of memories to return
- Return type:
List[MemoryEntry]- Returns:
List of recent memory entries
- get_context(agent_id, context_size=5)[source]
Get contextual memories for an agent
- Parameters:
agent_id (
str) – The agent to get context forcontext_size (
int) – Number of contextual memories
- Return type:
List[MemoryEntry]- Returns:
List of contextual memory entries