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

ShortTermMemory([max_entries, ...])

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: object

Fast, 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 keep

  • retention_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:

MemorySearchResult

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 agent

  • limit (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 for

  • context_size (int) – Number of contextual memories

Return type:

List[MemoryEntry]

Returns:

List of contextual memory entries

clear_agent_memories(agent_id)[source]

Clear all memories for a specific agent

Parameters:

agent_id (str)

get_stats()[source]

Get memory statistics

Return type:

Dict[str, Any]

shutdown()[source]

Shutdown the memory system