diff --git a/CHANGELOG.md b/CHANGELOG.md index 610611539..3672c73be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ - Fix: refactor session store updates, add chat.inject, and harden subagent cleanup flow. (#944) — thanks @tyler6204. - Fix: clean up suspended CLI processes across backends. (#978) — thanks @Nachx639. - Fix: support MiniMax coding plan usage responses with `model_remains`/`current_interval_*` payloads. +- Fix: honor message tool channel for duplicate suppression (prefer `NO_REPLY` after `message` tool sends). (#1053) — thanks @sashcatanzarite. - Fix: suppress WhatsApp pairing replies for historical catch-up DMs on initial link. (#904) - Browser: extension mode recovers when only one tab is attached (stale targetId fallback). - Browser: fix `tab not found` for extension relay snapshots/actions when Playwright blocks `newCDPSession` (use the single available Page). diff --git a/src/agents/pi-embedded-subscribe.tools.test.ts b/src/agents/pi-embedded-subscribe.tools.test.ts new file mode 100644 index 000000000..a98cb5469 --- /dev/null +++ b/src/agents/pi-embedded-subscribe.tools.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; + +import { extractMessagingToolSend } from "./pi-embedded-subscribe.tools.js"; + +describe("extractMessagingToolSend", () => { + it("uses channel as provider for message tool", () => { + const result = extractMessagingToolSend("message", { + action: "send", + channel: "telegram", + to: "123", + }); + + expect(result?.tool).toBe("message"); + expect(result?.provider).toBe("telegram"); + expect(result?.to).toBe("telegram:123"); + }); + + it("prefers provider when both provider and channel are set", () => { + const result = extractMessagingToolSend("message", { + action: "send", + provider: "slack", + channel: "telegram", + to: "channel:C1", + }); + + expect(result?.tool).toBe("message"); + expect(result?.provider).toBe("slack"); + expect(result?.to).toBe("channel:c1"); + }); +}); diff --git a/src/agents/pi-embedded-subscribe.tools.ts b/src/agents/pi-embedded-subscribe.tools.ts index 6f43e0d65..285bd83d1 100644 --- a/src/agents/pi-embedded-subscribe.tools.ts +++ b/src/agents/pi-embedded-subscribe.tools.ts @@ -57,8 +57,10 @@ export function extractMessagingToolSend( const toRaw = typeof args.to === "string" ? args.to : undefined; if (!toRaw) return undefined; const providerRaw = typeof args.provider === "string" ? args.provider.trim() : ""; - const providerId = providerRaw ? normalizeChannelId(providerRaw) : null; - const provider = providerId ?? (providerRaw ? providerRaw.toLowerCase() : "message"); + const channelRaw = typeof args.channel === "string" ? args.channel.trim() : ""; + const providerHint = providerRaw || channelRaw; + const providerId = providerHint ? normalizeChannelId(providerHint) : null; + const provider = providerId ?? (providerHint ? providerHint.toLowerCase() : "message"); const to = normalizeTargetForProvider(provider, toRaw); return to ? { tool: toolName, provider, accountId, to } : undefined; } diff --git a/src/agents/system-prompt.test.ts b/src/agents/system-prompt.test.ts index e63900ef9..cfed9fb45 100644 --- a/src/agents/system-prompt.test.ts +++ b/src/agents/system-prompt.test.ts @@ -216,6 +216,7 @@ describe("buildAgentSystemPrompt", () => { expect(prompt).toContain("message: Send messages and channel actions"); expect(prompt).toContain("### message tool"); + expect(prompt).toContain("respond with ONLY: NO_REPLY"); }); it("includes runtime provider capabilities when present", () => { diff --git a/src/agents/system-prompt.ts b/src/agents/system-prompt.ts index adeb2ae9c..86e5a4cac 100644 --- a/src/agents/system-prompt.ts +++ b/src/agents/system-prompt.ts @@ -95,6 +95,7 @@ function buildMessagingSection(params: { "- Use `message` for proactive sends + channel actions (polls, reactions, etc.).", "- For `action=send`, include `to` and `message`.", `- If multiple channels are configured, pass \`channel\` (${params.messageChannelOptions}).`, + `- If you use \`message\` (\`action=send\`) to deliver your user-visible reply, respond with ONLY: ${SILENT_REPLY_TOKEN} (avoid duplicate replies).`, params.inlineButtonsEnabled ? "- Inline buttons supported. Use `action=send` with `buttons=[[{text,callback_data}]]` (callback_data routes back as a user message)." : params.runtimeChannel