Skip to content

Commit 817e6e8

Browse files
committed
fix(sessions): suppress a2a control echoes
1 parent fc4da58 commit 817e6e8

9 files changed

Lines changed: 224 additions & 26 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Docs: https://docs.openclaw.ai
3030
- Agents/compaction: submit a non-empty runtime-event marker for pre-compaction memory flush turns, so strict Anthropic providers no longer reject the silent flush as an empty user message. Fixes #75305. Thanks @sableassistant3777-source.
3131
- Plugin SDK: re-export `isPrivateIpAddress` from `plugin-sdk/ssrf-runtime`, restoring source-checkout builds for SearXNG and Firecrawl private-network guards. Thanks @vincentkoc.
3232
- Discord/message actions: advertise `upload-file` and route it through Discord's send runtime with agent-scoped media reads, so agents can discover and send file attachments. Fixes #60652 and supersedes #60808, #61087, and #61100. Thanks @claw-io, @efe-arv, @joelnishanth, and @sjhddh.
33+
- Sessions: suppress exact inter-session control replies such as `NO_REPLY` and keep agent-to-agent announce bookkeeping out of visible transcripts. Fixes #53145. Thanks @TarahAssistant.
3334
- CLI/directory: report unsupported directory operations for installed channel plugins instead of prompting to reinstall the plugin when it lacks a directory adapter. Fixes #75770. Thanks @lawong888.
3435
- Web search/SearXNG: show the JSON API `search.formats` prerequisite during SearXNG setup before prompting for the base URL. Supersedes #65592. Thanks @evanpaul14.
3536
- Web search/SearXNG: pass through `img_src` image URLs from SearXNG image-category results. Supersedes #61416. Thanks @sghael.

‎src/agents/openclaw-tools.sessions.test.ts‎

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ describe("sessions tools", () => {
158158
callGatewayMock.mockClear();
159159
installMessagingTestRegistry();
160160
agentStepTesting.setDepsForTest({
161+
agentCommandFromIngress: async () => ({
162+
payloads: [{ text: "ANNOUNCE_SKIP", mediaUrl: null }],
163+
meta: { durationMs: 1 },
164+
}),
161165
callGateway: (opts: unknown) => callGatewayMock(opts),
162166
});
163167
sessionsResolutionTesting.setDepsForTest({
@@ -860,9 +864,9 @@ describe("sessions tools", () => {
860864
runId: "run-1",
861865
delivery: { status: "pending", mode: "announce" },
862866
});
863-
await waitForCalls(() => calls.filter((call) => call.method === "agent").length, 4);
864-
await waitForCalls(() => calls.filter((call) => call.method === "agent.wait").length, 4);
865-
await waitForCalls(() => calls.filter((call) => call.method === "chat.history").length, 4);
867+
await waitForCalls(() => calls.filter((call) => call.method === "agent").length, 3);
868+
await waitForCalls(() => calls.filter((call) => call.method === "agent.wait").length, 3);
869+
await waitForCalls(() => calls.filter((call) => call.method === "chat.history").length, 3);
866870

867871
const waitPromise = tool.execute("call6", {
868872
sessionKey: "main",
@@ -876,14 +880,14 @@ describe("sessions tools", () => {
876880
delivery: { status: "pending", mode: "announce" },
877881
});
878882
expect(typeof (waited.details as { runId?: string }).runId).toBe("string");
879-
await waitForCalls(() => calls.filter((call) => call.method === "agent").length, 8);
880-
await waitForCalls(() => calls.filter((call) => call.method === "agent.wait").length, 8);
881-
await waitForCalls(() => calls.filter((call) => call.method === "chat.history").length, 8);
883+
await waitForCalls(() => calls.filter((call) => call.method === "agent").length, 6);
884+
await waitForCalls(() => calls.filter((call) => call.method === "agent.wait").length, 6);
885+
await waitForCalls(() => calls.filter((call) => call.method === "chat.history").length, 7);
882886

883887
const agentCalls = calls.filter((call) => call.method === "agent");
884888
const waitCalls = calls.filter((call) => call.method === "agent.wait");
885889
const historyOnlyCalls = calls.filter((call) => call.method === "chat.history");
886-
expect(agentCalls).toHaveLength(8);
890+
expect(agentCalls).toHaveLength(6);
887891
for (const call of agentCalls) {
888892
expect(call.params).toMatchObject({
889893
message: expect.stringContaining("[Inter-session message"),
@@ -911,17 +915,8 @@ describe("sessions tools", () => {
911915
),
912916
),
913917
).toBe(true);
914-
expect(
915-
agentCalls.some(
916-
(call) =>
917-
typeof (call.params as { extraSystemPrompt?: string })?.extraSystemPrompt === "string" &&
918-
(call.params as { extraSystemPrompt?: string })?.extraSystemPrompt?.includes(
919-
"Agent-to-agent announce step",
920-
),
921-
),
922-
).toBe(true);
923-
expect(waitCalls).toHaveLength(8);
924-
expect(historyOnlyCalls).toHaveLength(9);
918+
expect(waitCalls).toHaveLength(6);
919+
expect(historyOnlyCalls).toHaveLength(7);
925920
expect(sendCallCount).toBe(0);
926921
});
927922

@@ -1038,6 +1033,13 @@ describe("sessions tools", () => {
10381033
}
10391034
return {};
10401035
});
1036+
agentStepTesting.setDepsForTest({
1037+
agentCommandFromIngress: async () => ({
1038+
payloads: [{ text: "announce now", mediaUrl: null }],
1039+
meta: { durationMs: 1 },
1040+
}),
1041+
callGateway: (opts: unknown) => callGatewayMock(opts),
1042+
});
10411043

10421044
const tool = createOpenClawTools({
10431045
agentSessionKey: requesterKey,
@@ -1059,13 +1061,13 @@ describe("sessions tools", () => {
10591061
});
10601062
await vi.waitFor(
10611063
() => {
1062-
expect(calls.filter((call) => call.method === "agent")).toHaveLength(4);
1064+
expect(calls.filter((call) => call.method === "agent")).toHaveLength(3);
10631065
},
10641066
{ timeout: 2_000, interval: 5 },
10651067
);
10661068

10671069
const agentCalls = calls.filter((call) => call.method === "agent");
1068-
expect(agentCalls).toHaveLength(4);
1070+
expect(agentCalls).toHaveLength(3);
10691071
for (const call of agentCalls) {
10701072
expect(call.params).toMatchObject({
10711073
lane: expect.stringMatching(/^nested(?::|$)/),
@@ -1184,6 +1186,13 @@ describe("sessions tools", () => {
11841186
}
11851187
return {};
11861188
});
1189+
agentStepTesting.setDepsForTest({
1190+
agentCommandFromIngress: async () => ({
1191+
payloads: [{ text: "announce now", mediaUrl: null }],
1192+
meta: { durationMs: 1 },
1193+
}),
1194+
callGateway: (opts: unknown) => callGatewayMock(opts),
1195+
});
11871196

11881197
const tool = createOpenClawTools({
11891198
agentSessionKey: requesterKey,

‎src/agents/tools/agent-step.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,39 @@ describe("runAgentStep", () => {
8484

8585
expect(bundleMcpRuntimeMocks.retireSessionMcpRuntimeForSessionKey).not.toHaveBeenCalled();
8686
});
87+
88+
it("forwards explicit transcript bodies for nested bookkeeping turns", async () => {
89+
const gatewayCalls: CallGatewayOptions[] = [];
90+
const agentCommandFromIngress = vi.fn(async () => ({
91+
payloads: [{ text: "done", mediaUrl: null }],
92+
meta: { durationMs: 1 },
93+
}));
94+
__testing.setDepsForTest({
95+
agentCommandFromIngress,
96+
callGateway: async <T = unknown>(opts: CallGatewayOptions): Promise<T> => {
97+
gatewayCalls.push(opts);
98+
return { runId: "run-nested" } as T;
99+
},
100+
});
101+
runWaitMocks.waitForAgentRunAndReadUpdatedAssistantReply.mockResolvedValue({
102+
status: "ok",
103+
replyText: "done",
104+
});
105+
106+
await runAgentStep({
107+
sessionKey: "agent:main:subagent:child",
108+
message: "internal announce step",
109+
transcriptMessage: "",
110+
extraSystemPrompt: "announce only",
111+
timeoutMs: 10_000,
112+
});
113+
114+
expect(gatewayCalls).toEqual([]);
115+
expect(agentCommandFromIngress).toHaveBeenCalledWith(
116+
expect.objectContaining({
117+
message: expect.stringContaining("internal announce step"),
118+
transcriptMessage: "",
119+
}),
120+
);
121+
});
87122
});

‎src/agents/tools/agent-step.ts‎

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,46 @@ import { waitForAgentRunAndReadUpdatedAssistantReply } from "../run-wait.js";
99
export { readLatestAssistantReply } from "../run-wait.js";
1010

1111
type GatewayCaller = typeof callGateway;
12+
type AgentCommandRunner = typeof import("../../commands/agent.js").agentCommandFromIngress;
1213

1314
const defaultAgentStepDeps = {
15+
agentCommandFromIngress: (async (...args) => {
16+
const { agentCommandFromIngress } = await import("../../commands/agent.js");
17+
return await agentCommandFromIngress(...args);
18+
}) as AgentCommandRunner,
1419
callGateway,
1520
};
1621

1722
let agentStepDeps: {
23+
agentCommandFromIngress: AgentCommandRunner;
1824
callGateway: GatewayCaller;
1925
} = defaultAgentStepDeps;
2026

27+
function extractAgentCommandReply(result: unknown): string | undefined {
28+
const payloads = (result as { payloads?: unknown } | undefined)?.payloads;
29+
if (!Array.isArray(payloads)) {
30+
return undefined;
31+
}
32+
const texts = payloads
33+
.map((payload) =>
34+
payload &&
35+
typeof payload === "object" &&
36+
typeof (payload as { text?: unknown }).text === "string"
37+
? (payload as { text: string }).text
38+
: "",
39+
)
40+
.filter((text) => text.trim().length > 0);
41+
return texts.length > 0 ? texts.join("\n\n") : undefined;
42+
}
43+
2144
export async function runAgentStep(params: {
2245
sessionKey: string;
2346
message: string;
2447
extraSystemPrompt: string;
2548
timeoutMs: number;
2649
channel?: string;
2750
lane?: string;
51+
transcriptMessage?: string;
2852
sourceSessionKey?: string;
2953
sourceChannel?: string;
3054
sourceTool?: string;
@@ -36,15 +60,38 @@ export async function runAgentStep(params: {
3660
sourceChannel: params.sourceChannel,
3761
sourceTool: params.sourceTool ?? "sessions_send",
3862
};
63+
const message = annotateInterSessionPromptText(params.message, inputProvenance);
64+
const lane = params.lane ?? resolveNestedAgentLaneForSession(params.sessionKey);
65+
const channel = params.channel ?? INTERNAL_MESSAGE_CHANNEL;
66+
if (params.transcriptMessage !== undefined) {
67+
const result = await agentStepDeps.agentCommandFromIngress({
68+
message,
69+
transcriptMessage: params.transcriptMessage,
70+
sessionKey: params.sessionKey,
71+
deliver: false,
72+
channel,
73+
lane,
74+
runId: stepIdem,
75+
extraSystemPrompt: params.extraSystemPrompt,
76+
inputProvenance,
77+
senderIsOwner: false,
78+
allowModelOverride: false,
79+
});
80+
await retireSessionMcpRuntimeForSessionKey({
81+
sessionKey: params.sessionKey,
82+
reason: "nested-agent-step-complete",
83+
});
84+
return extractAgentCommandReply(result);
85+
}
3986
const response = await agentStepDeps.callGateway({
4087
method: "agent",
4188
params: {
42-
message: annotateInterSessionPromptText(params.message, inputProvenance),
89+
message,
4390
sessionKey: params.sessionKey,
4491
idempotencyKey: stepIdem,
4592
deliver: false,
46-
channel: params.channel ?? INTERNAL_MESSAGE_CHANNEL,
47-
lane: params.lane ?? resolveNestedAgentLaneForSession(params.sessionKey),
93+
channel,
94+
lane,
4895
extraSystemPrompt: params.extraSystemPrompt,
4996
inputProvenance,
5097
},
@@ -71,7 +118,12 @@ export async function runAgentStep(params: {
71118
}
72119

73120
export const __testing = {
74-
setDepsForTest(overrides?: Partial<{ callGateway: GatewayCaller }>) {
121+
setDepsForTest(
122+
overrides?: Partial<{
123+
agentCommandFromIngress: AgentCommandRunner;
124+
callGateway: GatewayCaller;
125+
}>,
126+
) {
75127
agentStepDeps = overrides
76128
? {
77129
...defaultAgentStepDeps,

‎src/agents/tools/sessions-send-helpers.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export {
1010
ANNOUNCE_SKIP_TOKEN,
1111
REPLY_SKIP_TOKEN,
1212
isAnnounceSkip,
13+
isNonDeliverableSessionsReply,
1314
isReplySkip,
1415
} from "./sessions-send-tokens.js";
1516

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
import { HEARTBEAT_TOKEN, isSilentReplyText, SILENT_REPLY_TOKEN } from "../../auto-reply/tokens.js";
2+
13
export const ANNOUNCE_SKIP_TOKEN = "ANNOUNCE_SKIP";
24
export const REPLY_SKIP_TOKEN = "REPLY_SKIP";
35

6+
const NON_DELIVERABLE_REPLY_TOKENS = [
7+
ANNOUNCE_SKIP_TOKEN,
8+
REPLY_SKIP_TOKEN,
9+
SILENT_REPLY_TOKEN,
10+
HEARTBEAT_TOKEN,
11+
] as const;
12+
413
export function isAnnounceSkip(text?: string) {
514
return (text ?? "").trim() === ANNOUNCE_SKIP_TOKEN;
615
}
716

817
export function isReplySkip(text?: string) {
918
return (text ?? "").trim() === REPLY_SKIP_TOKEN;
1019
}
20+
21+
export function isNonDeliverableSessionsReply(text?: string) {
22+
return NON_DELIVERABLE_REPLY_TOKENS.some((token) => isSilentReplyText(text, token));
23+
}

‎src/agents/tools/sessions-send-tool.a2a.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
import type { CallGatewayOptions } from "../../gateway/call.js";
33
import { setActivePluginRegistry } from "../../plugins/runtime.js";
44
import { createSessionConversationTestRegistry } from "../../test-utils/session-conversation-registry.js";
5+
import { runAgentStep } from "./agent-step.js";
56
import { runSessionsSendA2AFlow, __testing } from "./sessions-send-tool.a2a.js";
67

78
vi.mock("../run-wait.js", () => ({
@@ -19,6 +20,8 @@ describe("runSessionsSendA2AFlow announce delivery", () => {
1920
beforeEach(() => {
2021
setActivePluginRegistry(createSessionConversationTestRegistry());
2122
gatewayCalls = [];
23+
vi.clearAllMocks();
24+
vi.mocked(runAgentStep).mockResolvedValue("Test announce reply");
2225
__testing.setDepsForTest({
2326
callGateway: async <T = Record<string, unknown>>(opts: CallGatewayOptions) => {
2427
gatewayCalls.push(opts);
@@ -66,4 +69,47 @@ describe("runSessionsSendA2AFlow announce delivery", () => {
6669
expect(sendParams.channel).toBe("discord");
6770
expect(sendParams.threadId).toBeUndefined();
6871
});
72+
73+
it.each(["NO_REPLY", "HEARTBEAT_OK", "ANNOUNCE_SKIP", "REPLY_SKIP"])(
74+
"does not re-inject exact control reply %s into agent-to-agent flow",
75+
async (roundOneReply) => {
76+
await runSessionsSendA2AFlow({
77+
targetSessionKey: "agent:main:discord:group:dev",
78+
displayKey: "agent:main:discord:group:dev",
79+
message: "Test message",
80+
announceTimeoutMs: 10_000,
81+
maxPingPongTurns: 2,
82+
requesterSessionKey: "agent:main:discord:group:req",
83+
requesterChannel: "discord",
84+
roundOneReply,
85+
});
86+
87+
expect(runAgentStep).not.toHaveBeenCalled();
88+
expect(gatewayCalls.find((call) => call.method === "send")).toBeUndefined();
89+
},
90+
);
91+
92+
it.each(["NO_REPLY", "HEARTBEAT_OK"])(
93+
"suppresses exact announce control reply %s before channel delivery",
94+
async (announceReply) => {
95+
vi.mocked(runAgentStep).mockResolvedValueOnce(announceReply);
96+
97+
await runSessionsSendA2AFlow({
98+
targetSessionKey: "agent:main:discord:group:dev",
99+
displayKey: "agent:main:discord:group:dev",
100+
message: "Test message",
101+
announceTimeoutMs: 10_000,
102+
maxPingPongTurns: 0,
103+
roundOneReply: "Worker completed successfully",
104+
});
105+
106+
expect(runAgentStep).toHaveBeenCalledWith(
107+
expect.objectContaining({
108+
message: "Agent-to-agent announce step.",
109+
transcriptMessage: "",
110+
}),
111+
);
112+
expect(gatewayCalls.find((call) => call.method === "send")).toBeUndefined();
113+
},
114+
);
69115
});

0 commit comments

Comments
 (0)