Skip to content

Commit b21db28

Browse files
committed
Better fix for STEP_TEXT agents in the cli: stream them as assistant text
1 parent 6107b86 commit b21db28

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

cli/src/utils/sdk-event-handlers.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,24 +354,12 @@ const updateSpawnAgentBlocks = (
354354

355355
if (result?.value) {
356356
const { content, hasError } = extractSpawnAgentResultContent(result.value)
357-
358-
// Check if there's meaningful text content already streamed
359-
const existingTextContent = block.blocks
360-
.filter((b): b is { type: 'text'; content: string } => b.type === 'text')
361-
.map(b => b.content)
362-
.join('')
363-
.trim()
364-
365-
// Use extracted content from result if it's more substantial than existing streamed content.
366-
// This ensures agents with lastMessage output mode (like researcher-web) show their final
367-
// result inside the box, even if they had tool blocks or partial content during execution.
368-
const shouldUseExtractedContent = content && (!existingTextContent || content.length > existingTextContent.length)
369-
357+
// Preserve streamed content (agents like commander stream their output)
370358
const hasStreamedContent = block.blocks.length > 0
371359
if (hasError || content || hasStreamedContent) {
372360
return {
373361
...block,
374-
blocks: shouldUseExtractedContent ? [{ type: 'text', content } as ContentBlock] : block.blocks,
362+
blocks: hasStreamedContent ? block.blocks : [{ type: 'text', content } as ContentBlock],
375363
status: hasError ? ('failed' as const) : ('complete' as const),
376364
}
377365
}

packages/agent-runtime/src/run-programmatic-step.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ async function executeSegmentsArray(
555555
segments: ParsedSegment[],
556556
params: ExecuteToolCallsArrayParams,
557557
): Promise<ToolResultOutput[] | undefined> {
558-
const { agentState } = params
558+
const { agentState, onResponseChunk } = params
559559

560560
let toolResults: ToolResultOutput[] = []
561561

@@ -564,6 +564,9 @@ async function executeSegmentsArray(
564564
// Add text as an assistant message
565565
agentState.messageHistory = [...agentState.messageHistory]
566566
agentState.messageHistory.push(assistantMessage(segment.text))
567+
568+
// Stream assistant text
569+
onResponseChunk(segment.text)
567570
} else {
568571
// Handle tool call segment
569572
const toolResult = await executeSingleToolCall(segment, params)

0 commit comments

Comments
 (0)