DEV Community

mage0535
mage0535

Posted on • Originally published at hermes-agent.nousresearch.com

Knowledge-and-Memory-Management: Direction 1-3 Finalization

The Knowledge-and-Memory-Management repository has just wrapped documentation for three core directions, marking a clear milestone for developers building persistent, context-aware agents. These directions are not speculative blueprints—they represent actual finalized features derived from the project's evolution over multiple releases. If you’ve been waiting for stable APIs around knowledge representation and memory recall, this is the signal to integrate them.

Direction 1: Structured Knowledge Graphs with Dynamic Entities

The first direction, finalized as kmm.graph, replaces earlier ad-hoc key-value stores with a formalized entity-relationship model. Each knowledge unit is now a typed node with attached metadata, supporting both scalar values and nested properties. Relationships are directional and versioned, meaning you can trace how connections evolve over time without manual diffs.

Key highlights from the final docs:

  • Self-contained schemas: Each graph instance enforces a schema, automatically rejecting malformed inserts.
  • Query filters: Support for property-based filtering, path traversal with depth limits, and anchor-based pagination.
  • Event hooks: on_merge and on_detach callbacks for triggering side effects when entities change.

For example, storing and retrieving a project dependency now looks like this:

from kmm.graph import EntityGraph, EntityType, Relation

graph = EntityGraph(schema_version="3.0")

# Define types
Person = EntityType("person", fields={"name": str, "role": str})
Project = EntityType("project", fields={"name": str})

# Create entities
alice = graph.add_entity(Person, id="user_01", name="Alice", role="maintainer")
toolbox = graph.add_entity(Project, id="proj_02", name="Toolbox v4")

# Relate them
graph.add_relation(alice, toolbox, Relation("manages", since="2025-03-01"))

# Query with path traversal
results = graph.query("user_01", path_depth=2, relation_type="manages")
print(results)  # [Relation('manages', ...)]
Enter fullscreen mode Exit fullscreen mode

The documentation is explicit about transaction boundaries and conflict resolution, so you can safely run concurrent writes without corrupting the graph.

Direction 2: Temporal Anchoring for Episodic Memory

Direction 2, kmm.episode, introduces a fine-grained temporal memory subsystem. Unlike older append-only logs, this module supports retroactive labeling and interval compression. Each memory record is tied to one or more time anchors, which can be absolute timestamps or relative sequence numbers. The final docs clarify the compression semantics: memories older than a configurable threshold get merged into summary embeddings, but critical anchors (explicitly marked) remain untouched.

Implementation decisions worth noting:

  • Anchor decay: Unreferenced anchors older than two sessions are automatically recycled, with a configurable grace period.
  • Conflict resolution: If two processes insert memories for the same anchor interval, the system applies a user-defined policy (most recent, most frequent, or custom scorer).
  • Serialization format: Memories serialize to a compact .kmm binary by default, but JSON output is available for debugging.

The API for retrieving a chronological slice is spare but powerful:

from kmm.episode import MemoryStore

store = MemoryStore(policy="most_recent")
store.record("API v2 deprecated", anchor="2025-03-10T12:00:00Z")

# Retrieve memories within a window
recent = store.slice(
    start="2025-03-01T00:00:00Z",
    end="2025-03-15T00:00:00Z",
    compress=True
)
Enter fullscreen mode Exit fullscreen mode

Notice the compress parameter—this is where Direction 2 meets Direction 3.

Direction 3: Hierarchical Retrieval via Composite Drivers

Direction 3, kmm.retrieval, finalizes the abstraction layer that orchestrates multiple retrieval backends. The key feature is the composite driver: you configure a pipeline of retrievers (vector, graph, episode) that each produce ranked results. A final ranker merges them using learnable weights. The docs finalized the driver configuration format and the retry/fallback behavior when a backend is unavailable.

Critical details for experienced deployers:

  • Backend registration: Drivers register themselves via a kmm.retrieval.drivers entry point, enabling third-party plugins without forking the core.
  • Time-to-live caches: Intermediate results are cached per pipeline hash; cache invalidation is automatic on memory anchor changes.
  • Failure modes: Each retriever must implement status() and cold_start() methods. The composite driver will skip a retriever that reports unhealthy and retry later.

The final docs provide a reference configuration for a three-stage pipeline:

from kmm.retrieval import CompositeRetriever, PipelineConfig

config = PipelineConfig(
    retriever_order=["vector", "graph", "episode"],
    weights=[0.5, 0.3, 0.2],
    fallback="vector"
)

retriever = CompositeRetriever(config)
results = retriever.retrieve(
    query="What changed in API v2?",
    top_k=5
)
Enter fullscreen mode Exit fullscreen mode

This isn’t just an interface—it comes with a detailed breakdown of time complexity per stage and guidelines for tuning the weights based on dataset characteristics.

Why This Matters Now

For teams building long-running agents or decision systems, these three directions eliminate the bespoke glue code that previously was necessary. The kmm.graph direction gives you a queryable schema without a full graph database setup. kmm.episode handles the temporal semantics that naive vector stores ignore. And kmm.retrieval lets you switch between backends without changing application logic. The documentation is thorough on edge cases—duplicate anchors, partial writes, and serialization errors—which alone saves days of debugging.

If you’re already invested in the Knowledge-and-Memory-Management ecosystem, update to the latest commit and migrate your schemas. The APIs are backward-compatible for the most common patterns, but the new hooks and conflict policies require explicit opt-in. The finalization record also notes that Directions 4 and 5 (federated sync and user-level memory policies) are in early design, so now is the time to solidify your foundation.

Top comments (0)