Skip to content

Agent cannot distinguish owner's messages from contact's messages in DM history #12482

@mactsk

Description

@mactsk

Description

When the agent receives DM conversation history, all messages appear identically formatted regardless of who sent them. The fromMe flag from msg.key.fromMe is not propagated to the inboundMessage object, so the agent has no way to tell which messages are from the gateway owner and which are from the contact.

Expected Behavior

In DM conversations, the agent should be able to distinguish speakers:

  • Messages from the contact: [WhatsApp from +39xxx +5s] hello
  • Messages from the owner: [WhatsApp from +39xxx +10s] (self) hi, how are you?

This is important for the agent to understand conversation dynamics and respond appropriately (e.g., not re-answering the owner's own questions, understanding the flow of dialogue).

Current Behavior

Both messages appear identically:

[WhatsApp from +39xxx +5s] hello
[WhatsApp from +39xxx +10s] hi, how are you?

The agent cannot tell who said what, leading to confusion in multi-turn DM conversations.

Suggested Fix

Three small changes needed:

1. Propagate fromMe to inboundMessage

In the inboundMessage object construction (where msg fields are mapped), add:

fromMe: Boolean(msg.key?.fromMe)

2. Pass fromMe through buildInboundLine

In buildInboundLine(), include fromMe in the params passed to formatInboundEnvelope:

return formatInboundEnvelope({
    channel: "WhatsApp",
    from: ...,
    timestamp: msg.timestamp,
    body: baseLine,
    chatType: msg.chatType,
    fromMe: msg.fromMe,  // add this
    sender: { ... },
    previousTimestamp,
    envelope
});

3. Format (self) prefix in formatInboundEnvelope

Extend the body formatting to mark owner's DM messages:

// Before:
const body = !isDirect && resolvedSender ? `${resolvedSender}: ${params.body}` : params.body;

// After:
const body = !isDirect && resolvedSender
    ? `${resolvedSender}: ${params.body}`
    : isDirect && params.fromMe
        ? `(self) ${params.body}`
        : params.body;

Why This Matters

Without sender distinction, the LLM sees an ambiguous conversation where it cannot attribute messages to speakers. This is especially problematic when:

  • The owner asks a question and the contact replies — the agent might think the owner asked twice
  • The agent is asked to summarize or continue a conversation
  • Multiple messages are exchanged rapidly

Related: #12480 (owner outbound messages need to pass access control first for this to be useful)

Environment

  • OpenClaw 2026.2.2-3
  • WhatsApp channel (likely affects other channels too)
  • macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions