feat(agents): emit reasoning stream to gateway clients without channel callback#796
Open
BingqingLyu wants to merge 1 commit into
Open
feat(agents): emit reasoning stream to gateway clients without channel callback#796BingqingLyu wants to merge 1 commit into
BingqingLyu wants to merge 1 commit into
Conversation
…ing channel callback
The `emitReasoningStream` function currently requires both
`reasoningMode === "stream"` AND a channel-specific `onReasoningStream`
callback to be present. This means gateway-connected clients (webchat,
WebSocket) never receive `stream: "thinking"` agent events because the
gateway does not provide an `onReasoningStream` callback — only
channel-specific integrations like Telegram do.
This change decouples the gateway broadcast (`emitAgentEvent`) from the
channel callback:
- `streamReasoning` is now `true` whenever `reasoningMode === "stream"`,
regardless of whether `onReasoningStream` is provided
- `emitAgentEvent({ stream: "thinking", ... })` fires for all gateway
clients (WebSocket, node subscribers) whenever reasoning is streamed
- The `onReasoningStream` callback is still called when provided
(Telegram, custom integrations) but is no longer a gate
This allows webchat and other gateway-connected clients to display live
reasoning/thinking content during agent turns when `reasoningLevel` is
set to `"stream"` via `sessions.patch`.
Closes openclaw#5086
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
emitAgentEvent({ stream: "thinking" })from theonReasoningStreamcallback inemitReasoningStream()streamReasoningis nowtruewheneverreasoningMode === "stream", regardless of whether anonReasoningStreamcallback is providedstream: "thinking"are broadcast to all gateway-connected clients (WebSocket, node subscribers) even when no channel-specific callback existsProblem
Gateway-connected clients (webchat, WebSocket) never receive
stream: "thinking"agent events because:streamReasoningrequires bothreasoningMode === "stream"ANDtypeof params.onReasoningStream === "function"(line 48)onReasoningStreamcallback — only channel integrations like Telegram doemitAgentEvent()(the gateway broadcast) never fires for webchat, even though the gateway'screateAgentEventHandleralready broadcasts all non-tool events to connected clientsFix
Two minimal changes in
src/agents/pi-embedded-subscribe.ts:onReasoningStreamcallback requirement fromstreamReasoning— it should only depend onreasoningMode === "stream"emitAgentEvent()fire unconditionally whenstreamReasoningis true, and make theonReasoningStreamcallback optional (still called when provided)Impact
stream: "thinking"agent events whenreasoningLevel: "stream"is set viasessions.patchonReasoningStreamcallback is still invoked when providedonReasoningStreamcallback remains optional as defined inSubscribeEmbeddedPiSessionParamsTest plan
onReasoningStream, so behavior unchanged)stream: "thinking"events when session hasreasoningLevel: "stream"Closes openclaw#5086
🤖 Generated with Claude Code