Skip to content

feat(agents): emit reasoning stream to gateway clients without channel callback#796

Open
BingqingLyu wants to merge 1 commit into
mainfrom
fork-pr-47613-feat-stream-reasoning-to-gateway-clients
Open

feat(agents): emit reasoning stream to gateway clients without channel callback#796
BingqingLyu wants to merge 1 commit into
mainfrom
fork-pr-47613-feat-stream-reasoning-to-gateway-clients

Conversation

@BingqingLyu

@BingqingLyu BingqingLyu commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Decouple emitAgentEvent({ stream: "thinking" }) from the onReasoningStream callback in emitReasoningStream()
  • streamReasoning is now true whenever reasoningMode === "stream", regardless of whether an onReasoningStream callback is provided
  • Agent events with stream: "thinking" are broadcast to all gateway-connected clients (WebSocket, node subscribers) even when no channel-specific callback exists

Problem

Gateway-connected clients (webchat, WebSocket) never receive stream: "thinking" agent events because:

  1. streamReasoning requires both reasoningMode === "stream" AND typeof params.onReasoningStream === "function" (line 48)
  2. The gateway does not provide an onReasoningStream callback — only channel integrations like Telegram do
  3. This means emitAgentEvent() (the gateway broadcast) never fires for webchat, even though the gateway's createAgentEventHandler already broadcasts all non-tool events to connected clients

Fix

Two minimal changes in src/agents/pi-embedded-subscribe.ts:

  1. Line 48: Remove the onReasoningStream callback requirement from streamReasoning — it should only depend on reasoningMode === "stream"
  2. Lines 556-586: Make emitAgentEvent() fire unconditionally when streamReasoning is true, and make the onReasoningStream callback optional (still called when provided)

Impact

  • Webchat/WebSocket clients: Will now receive stream: "thinking" agent events when reasoningLevel: "stream" is set via sessions.patch
  • Telegram/existing channels: No behavior change — onReasoningStream callback is still invoked when provided
  • No breaking changes: The onReasoningStream callback remains optional as defined in SubscribeEmbeddedPiSessionParams

Test plan

  • Existing reasoning stream tests pass (they provide onReasoningStream, so behavior unchanged)
  • WebSocket gateway client receives stream: "thinking" events when session has reasoningLevel: "stream"
  • Telegram reasoning stream still works as before

Closes openclaw#5086

🤖 Generated with Claude Code

…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
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.

[Feature]: Stream thinking/reasoning to webchat clients during agent turns

2 participants