Skip to content

feat: CompositeBackend for memory path routing (durable vs thread-scoped) #850

@Aureliolo

Description

@Aureliolo

Summary

Implement a CompositeBackend that routes specific memory paths to different storage backends, enabling durable persistence for some memory types while keeping others thread-scoped.

Research Source

Design

Concept

A wrapper implementing the existing MemoryBackend protocol that dispatches to different concrete backends based on path prefix:

class CompositeBackend:
    routes: dict[str, MemoryBackend]  # path prefix -> backend
    default: MemoryBackend            # fallback for unmatched paths

Routing Rules

Path Prefix Backend Persistence
/memories/ StoreBackend (durable) Across sessions
/preferences/ StoreBackend (durable) Across sessions
/scratch/ StateBackend (thread-scoped) Current session only
/working/ StateBackend (thread-scoped) Current session only
(default) StateBackend Current session only

Behavior

  • Paths start empty; agent creates files on-demand
  • Pre-seeding available via Store API
  • Follows existing MemoryBackend protocol -- no interface changes
  • Configuration via YAML:
memory:
  backend: "composite"
  composite:
    routes:
      memories: "mem0"       # durable
      preferences: "mem0"   # durable
      scratch: "session"     # thread-scoped
      working: "session"     # thread-scoped
    default: "session"

Key Files

  • src/synthorg/memory/backends/ -- existing backend implementations
  • src/synthorg/memory/retriever.py -- retrieval pipeline
  • src/synthorg/memory/injection.py -- injection strategy enum

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    prio:mediumShould do, but not blockingscope:medium1-3 days of workspec:memoryDESIGN_SPEC Section 7 - Memory & Persistencetype:featureNew feature implementationv0.6Minor version v0.6v0.6.5Patch release v0.6.5

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions