Skip to content

fix(think): label channel speakers in messenger messages#1907

Open
cjol wants to merge 3 commits into
mainfrom
fix/1840-speaker-prefix-pr
Open

fix(think): label channel speakers in messenger messages#1907
cjol wants to merge 3 commits into
mainfrom
fix/1840-speaker-prefix-pr

Conversation

@cjol

@cjol cjol commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This PR adds configurable speaker labels for @cloudflare/think messenger channel traffic and documents the default SpeakerName: text transcript shape. Fixes #1840.

Why

  • Think already prefixes non-DM messenger messages before sending them to the model, but that transcript convention was not documented for agent authors.
  • Smaller models can misread Name: text as an identity cue instead of speaker attribution, especially when the user message is short or the agent persona is strict.
  • Direct messages do not need speaker labels because the conversation is already one-to-one. Keeping labels channel-only avoids adding identity noise where it does not disambiguate anything.
  • The new API is formatter-only rather than a boolean plus name-source enum. Callers can keep the default cascade, choose a provider-specific field, change the shape, or return null to suppress a channel label for a specific author.

Public API Surface

Symbol Kind Notes
MessengerDefinition.channelSpeakerLabel Option Additive formatter for channel speaker labels.
ChannelSpeakerLabel Type Additive formatter type, returns string | null | undefined.
resolveChannelSpeakerLabel Function Additive helper exported from @cloudflare/think/messengers.
toMessengerUserMessage(event, channelSpeakerLabel?) Function signature Adds an optional formatter parameter while preserving existing calls.

Code Changes

  • events.ts centralizes the channel speaker fallback cascade as fullName || userName || userId and treats null or an empty formatter result as label suppression.
  • toMessengerUserMessage applies speaker labels only for non-DM threads, for both text messages and action events.
  • chat-sdk.ts threads channelSpeakerLabel from each messenger definition into the model-facing message conversion path.
  • The README and messenger docs now describe the default channel transcript format, the DM suppression rule, and the formatter hook.
  • The changeset marks @cloudflare/think for a minor release because the messenger definition API gains a new option.

Compatibility

  • Existing channel message formatting stays the same by default: SpeakerName: text using fullName || userName || userId.
  • Regular direct messages remain unprefixed.
  • Direct-message action events are now also unprefixed. If a consumer depended on action labels inside DMs, it should treat the conversation context as the speaker instead of parsing a prefix from the model-facing text.

@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5f09f0c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@cloudflare/think Minor
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment thread packages/think/src/messengers/index.ts
@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1907

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1907

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1907

create-think

npm i https://pkg.pr.new/create-think@1907

hono-agents

npm i https://pkg.pr.new/hono-agents@1907

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1907

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1907

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1907

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1907

commit: 5f09f0c

cjol and others added 2 commits July 9, 2026 17:43
Action events now follow the same channel-only rule as regular messages:
labelled in channels, unlabelled in DMs. The speaker label only serves to
disambiguate multiple humans, which cannot happen in a 1:1 DM.

Co-Authored-By: Beta-Devin AI <248786709+beta-devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat SDK channel messages are prefixed SpeakerName: — undocumented and not configurable

1 participant