Skip to content

Feature: Agent attribution filter for multi-agent setups #16

Description

@johnathanneals-dev

Problem

When multiple AI agents (or multiple Claude Code sessions) share the same Open Brain instance, there's no way to filter memories by which agent created them. The source field tracks the medium (mcp, chat, email), not the authoring agent — so all MCP-connected agents show source: mcp.

This means queries like "what did my coding agent store this week?" or "show me memories from my research session" require semantic search to approximate, and semantic search can't reliably match on structured identity.

Real-world impact

I run a multi-agent setup where several Claude Code sessions share one Open Brain. When one agent searches for another agent's recent work, it gets either:

  • Nothing (semantic mismatch between query and stored content)
  • Unrelated results from other agents that happen to share similar topics

The source filter doesn't help because every agent connects via MCP.

Suggested approach

Option A — Dedicated column (cleaner, small migration):

Add a captured_by TEXT column to the memory table:

ALTER TABLE memory ADD COLUMN captured_by TEXT;
CREATE INDEX idx_memory_captured_by ON memory (captured_by);

Then add it as a parameter to memory_store and as a filter to memory_search:

# In memory_store tool schema:
"captured_by": {"type": "string", "description": "Agent or session that created this memory"}

# In search_memories(), add to filter_conditions:
if captured_by:
    filter_conditions.append("captured_by LIKE %s")
    filter_params.append(f"{captured_by}%")  # prefix match

Prefix match lets agents use broad filters (captured_by: "researcher" matches researcher-session-1, researcher-session-2, etc.) or exact ones.

Option B — Metadata convention (no schema change):

Use metadata.captured_by as a convention and add a metadata-key filter to memory_search. Works within the existing schema but is less discoverable.

Why this matters

Open Brain's tagline is "one database, any AI client." As more people connect multiple agents or sessions to the same instance, agent attribution becomes essential for the memories to stay useful rather than becoming an undifferentiated pile. The source field was designed for a single-agent world — captured_by extends it naturally for multi-agent.

Happy to submit a PR for Option A if there's interest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions