refactor(agents): preserve raw reasoning stream and push formatting to edge (#78397)

Merged via squash.

Prepared head SHA: bb56f7ee00
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: odysseus0 <8635094+odysseus0@users.noreply.github.com>
Reviewed-by: @odysseus0
This commit is contained in:
Super Zheng
2026-05-08 21:08:21 +08:00
committed by GitHub
parent be28fdcb60
commit e7277b4e3a
24 changed files with 146 additions and 63 deletions

View File

@@ -888,10 +888,9 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
});
await options.onReplyStart?.();
// Core agent sends pre-formatted text from formatReasoningMessage
result.replyOptions.onReasoningStream?.({ text: "Reasoning:\n_thinking step 1_" });
result.replyOptions.onReasoningStream?.({ text: "thinking step 1" });
result.replyOptions.onReasoningStream?.({
text: "Reasoning:\n_thinking step 1_\n_step 2_",
text: "thinking step 1\nstep 2",
});
result.replyOptions.onPartialReply?.({ text: "answer part" });
result.replyOptions.onReasoningEnd?.();
@@ -967,7 +966,7 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
});
await options.onReplyStart?.();
result.replyOptions.onReasoningStream?.({ text: "Reasoning:\n_deep thought_" });
result.replyOptions.onReasoningStream?.({ text: "deep thought" });
result.replyOptions.onReasoningEnd?.();
await options.onIdle?.();
@@ -1005,7 +1004,7 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
});
await options.onReplyStart?.();
result.replyOptions.onReasoningStream?.({ text: "Reasoning:\n_thought_" });
result.replyOptions.onReasoningStream?.({ text: "thought" });
result.replyOptions.onReasoningEnd?.();
await options.deliver({ text: "```ts\nfinal answer\n```" }, { kind: "final" });
await options.onIdle?.();

View File

@@ -1,3 +1,4 @@
import { formatReasoningMessage } from "openclaw/plugin-sdk/agent-runtime";
import { logTypingFailure } from "openclaw/plugin-sdk/channel-feedback";
import { createChannelMessageReplyPipeline } from "openclaw/plugin-sdk/channel-message";
import {
@@ -522,7 +523,9 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
await typingCallbacks?.onReplyStart?.();
},
deliver: async (payload: ReplyPayload, info) => {
const reply = resolveSendableOutboundReplyParts(payload);
const payloadText =
payload.isReasoning && payload.text ? formatReasoningMessage(payload.text) : payload.text;
const reply = resolveSendableOutboundReplyParts({ ...payload, text: payloadText });
const text = reply.text;
const hasText = reply.hasText;
const hasMedia = reply.hasMedia;
@@ -694,7 +697,7 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
return;
}
startStreaming();
queueReasoningUpdate(payload.text);
queueReasoningUpdate(formatReasoningMessage(payload.text));
}
: undefined,
onReasoningEnd: reasoningPreviewEnabled ? () => {} : undefined,