Summary
Webchat and other WebSocket clients can't display thinking/reasoning content during streaming - it only appears after the turn completes when history is reloaded.
Current Behavior
- Agent has extended thinking enabled (e.g.,
thinkingLevel: "low")
- During streaming,
assistant events only contain text/delta - no thinking
- Thinking content is only available via
chat.history after the turn completes
- Clients have to reload history post-completion to show thinking blocks
Expected Behavior
Thinking content should be emitted as agent events during streaming, allowing clients to display it in real-time (like claude.ai does).
Proposed Solution
In src/agents/pi-embedded-subscribe.ts, the emitReasoningStream function currently only calls params.onReasoningStream. It should also emit an agent event:
const emitReasoningStream = (text: string) => {
if (!state.streamReasoning || !params.onReasoningStream) return;
const formatted = formatReasoningMessage(text);
if (!formatted) return;
if (formatted === state.lastStreamedReasoning) return;
state.lastStreamedReasoning = formatted;
// ADD: Emit as agent event for webchat/WS clients
emitAgentEvent({
runId: params.runId,
stream: "thinking", // or include in "assistant" with data.thinking
data: { thinking: formatted },
});
void params.onReasoningStream({ text: formatted });
};
Summary
Webchat and other WebSocket clients can't display thinking/reasoning content during streaming - it only appears after the turn completes when history is reloaded.
Current Behavior
thinkingLevel: "low")assistantevents only containtext/delta- no thinkingchat.historyafter the turn completesExpected Behavior
Thinking content should be emitted as agent events during streaming, allowing clients to display it in real-time (like claude.ai does).
Proposed Solution
In
src/agents/pi-embedded-subscribe.ts, theemitReasoningStreamfunction currently only callsparams.onReasoningStream. It should also emit an agent event: