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