Skip to content

Semantic Memory Models

Agent Memory Hub v0.4.0 introduces typed, semantic memory models. This allows you to work with structured concepts like "Events", "Facts", and "Profiles" rather than raw JSON blobs.

Philosophy

By enforcing schema on memory, we enable:

  1. Reliable Extraction: Ensure memories generated by LLMs conform to a known structure.
  2. Smarter Retrieval: Filter by type (e.g., "Give me all facts about Python").
  3. Knowledge Graphs: Link memories together using IDs and source references.

Available Models

1. EpisodicMemory

Records an event, conversation turn, or tool execution.

  • content: The textual description of what happened.
  • source: E.g., "conversation", "calendar", "tool_trace".
  • participants: List of actor IDs involved.

2. SemanticMemory

Represents a distinctive fact or piece of knowledge (Subject-Predicate-Object).

  • subject: "User"
  • predicate: "prefers"
  • object: "Dark Mode"
  • truth_score: 0.0 to 1.0 confidence.

3. EntityMemory

A profile for a stable entity.

  • entity_id: Unique reference (e.g., "user_123").
  • attributes: Dictionary of traits (age, name, role).

Usage Example

from agent_memory_hub import MemoryClient
from agent_memory_hub.models import EpisodicMemory, SemanticMemory, MemoryScope

client = MemoryClient(agent_id="researcher", session_id="sess_1")

# 1. Store a Fact
fact = SemanticMemory(
    agent_id="researcher",
    subject="Python",
    predicate="released_year",
    object="1991",
    scope=MemoryScope.GLOBAL,
    tags=["programming", "history"]
)
client.write_model(fact)

# 2. Store an Episode
episode = EpisodicMemory(
    agent_id="researcher",
    content="User asked about Python history.",
    participants=["user_1", "researcher"]
)
client.write_model(episode)