memory-lancedb-pro icon indicating copy to clipboard operation
memory-lancedb-pro copied to clipboard

Feature request: speaker-aware extraction and a speaker field on memories (multi-participant channels collapse every speaker into "User")

Open gorkem2020 opened this issue 4 months ago • 5 comments

Problem

In multi-participant channels (several humans, or humans plus other assistant agents sharing a room), every inbound message reaches the agent as a user-role turn. Smart extraction then attributes everything it learns to "the user": the extraction prompt receives the conversation as one undifferentiated text blob with a single User: <name> header, and the prompt's noise rules explicitly list sender IDs among things to never extract (src/extraction-prompts.ts). The memory schema has no speaker concept either: MemoryEntry carries scope and the metadata carries source_session, which identify the lane a memory came from, but nothing records who actually said it.

The result on a live multi-agent install: memories like "User prefers X" where X was stated by a peer assistant, durably stored, then recalled and injected as the operator's own preference. Once a wrong fact is admitted it keeps getting confirmed by recall. The research literature calls this provenance collapse; among popular frameworks the transcript layer usually keeps speaker identity (AutoGen source, AG2 name, CrewAI TaskOutput.agent) while the memory layer loses it, with Mem0's per-message name/user_id/agent_id being the notable exception.

What just changed on the host side

OpenClaw merged durable sender attribution today: openclaw#90552 persists senderId, senderName, and senderUsername inside the message.__openclaw envelope of durable user-turn transcript rows for group and channel routes (with openclaw#98336 as a first in-core consumer). So the reliable speaker source the memory layer needs is now landing upstream of this plugin.

Proposal

  1. Speaker-aware extraction input: when building the extraction window, pass per-message speaker labels (from message.__openclaw.senderName/senderId when present) instead of one anonymous blob, and drop the never-extract-sender instruction in favor of attribute-per-speaker guidance.
  2. A speaker/subject field on memories: record who a fact is about and who stated it (e.g. speaker in SmartMemoryMetadata, plus speaker-namespaced fact_keys), so "sam.rivera prefers X" and "the operator prefers X" are distinct facts that no longer collide or overwrite each other.
  3. Attribution-aware recall phrasing: injected memories say who the fact belongs to, so downstream models stop reading peer facts as operator facts.

Open design question for you: is a fallback worth having for hosts predating openclaw#90552 (the sender is still visible inside the current-turn inbound envelope text, so it is parseable), or would you rather keep this clean and key it entirely on the __openclaw sender metadata?

Happy to send a PR along whichever shape you prefer. We run a multi-agent install where this is the top remaining memory-quality issue, so there is a real environment to validate against.

gorkem2020 avatar Jul 06 '26 14:07 gorkem2020

This is a well-framed proposal and the failure mode is real — "peer assistant states X, memory records 'User prefers X', recall re-injects it as the operator's own preference, and each recall re-confirms it" is provenance collapse with a self-reinforcing loop on top. The framework comparison (transcript layer keeps speaker identity, memory layer drops it) matches what I've seen too, and it's the right way to locate where the loss happens.

Direction-wise I'd split this into two layers with very different costs:

1. Schema + passthrough (cheap, safe to do first). Add an optional speaker field to MemoryEntry. Existing rows simply have no speaker — reads treat absent as unknown, no migration needed. Anything the write path already knows about the originating turn gets recorded. This is backward-compatible and immediately useful for auditing wrong-attribution cases even before extraction gets smarter.

2. Speaker-aware extraction (the hard part, and it's upstream-constrained). The extraction prompt can only attribute what it can see. Today the conversation arrives as one user-role blob, so the binding question is: what per-message sender metadata does the hook payload actually carry, per channel type? That varies across channels (group chats vs DMs vs agent-to-agent), and where the sender isn't in the payload at all, no prompt engineering can recover it. So step 2 needs a small survey of what's available at the hook boundary before committing to a prompt design — otherwise we'd be speccing attribution the plugin can't populate.

One rule I'd want baked in from the start: when attribution is uncertain, store unknown, never guess. Your own provenance argument cuts this way — a wrongly-attributed memory is worse than an unattributed one, because it carries false confidence into every future recall. That also implies recall injection should eventually surface the speaker tag (e.g. "peer agent claimed:") so the model downstream can weight it, but that's a later step.

If you want to take a run at layer 1 (schema + passthrough + the hook-payload survey for layer 2), I'd be glad to review. Layer 2 scoping can live in this issue once we know what the payloads carry.

AliceLJY avatar Jul 17 '26 13:07 AliceLJY

We hit this exact provenance collapse in a multi-participant room test, so +1 that it is real and worth fixing. Proposal, sequenced cheap-to-hard along the split suggested above:

  1. Schema and passthrough (small, safe, no migration): an optional speaker field on memory metadata (statedBy / about), absent meaning unknown. The write path fills it whenever the capture payload carries sender identity, and fact_key gains a speaker namespace when the speaker is known, so facts stated by different participants stop colliding into one row.

  2. Speaker-aware extraction (the real fix): the extractor currently strips the sender envelope as noise before the LLM sees the transcript. Inverting that, parsing sender name/id into per-message speaker labels ("alice: ..." / "operator: ..."), replacing the never-extract-sender prompt rule with attribute-per-speaker guidance, plus one mixed-speaker few-shot, lets extraction emit a speaker per candidate. One precondition to verify per deployment: that the host actually delivers the sender-attribution envelope on the relevant channels (see openclaw#90552).

  3. Recall phrasing (small): injected memories state whose fact it is, so downstream models stop presenting peer facts as the operator's.

Layer 1 can land independently any time; layers 2 and 3 touch the same prompt regions as the currently open prompt-architecture PRs (#938 family), so we would sequence them after those settle to keep diffs reviewable. We can start working on this next week, beginning with layer 1 as its own small PR if that split works for you.

gorkem2020 avatar Jul 19 '26 08:07 gorkem2020

Status: #964 (merged 2026-08-08) covers part of this. Extraction now wraps turns in <user_message> / <assistant_message> tags, so assistant-side context is no longer attributed to the user.

Still open on master: telling apart multiple humans or peer agents within user-role turns, and the optional speaker / statedBy field (layer 1 of your plan). Nothing on master stores per-memory speaker provenance yet. Adding a schema field is @win4r's call. @gorkem2020, if you still plan to do the layer-1 PR, a short note on the field name and how fact_key namespacing behaves for existing rows would help that decision.

AliceLJY avatar Oct 27 '26 09:10 AliceLJY

Thanks for the status update, and for confirming that #964 already covers the assistant-side half.

We have since moved our deployment to one person per conversation (DMs and webchat only), so we no longer run into the multi-speaker case and won't be sending the layer-1 PR after all. Sorry for leaving that hanging. The failure mode is still real for anyone running multi-participant channels, so feel free to keep this open as a feature request, or close it if you would rather track it another way.

gorkem2020 avatar Oct 27 '26 14:10 gorkem2020

Thanks for following up, and no worries about the PR. Since the failure mode still applies to multi-participant channels, I'll keep this open as a feature request. Remaining scope: distinguishing multiple humans or peer agents within user-role turns, and an optional speaker field on memories (schema decision with @win4r).

AliceLJY avatar Oct 28 '26 02:10 AliceLJY