Output Dev Llm Streaming

作者 growthxaia4f6bd40ab0e無授權條款440 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Implement LLM text streaming in Output workflow steps with generateTextWithStreaming, Agent.generateWithStreaming, streamText, or Agent.stream. Use when adding token progress, onChunk callbacks, or handling streamText onEnd/onError with Temporal retries.

AI 產生的概覽

指導在 Output 工作流程步驟中實作 LLM 文字串流,涵蓋串流 API、回呼與錯誤處理。

功能
此技能說明如何為 LLM 驅動的 Output 工作流程步驟加入 token 或分塊進度。它比較 generateTextWithStreaming、Agent.generateWithStreaming 等完整生成 API 與 streamText、Agent.stream 等直接串流存取方式。它也說明如何擷取串流錯誤,讓失敗能觸發 Temporal 活動重試,並列出支援的呼叫參數與回呼。
適用情境
適用於為 LLM 步驟加入 token 進度或 onChunk 回呼、在完整生成與直接串流存取之間做選擇,或讓串流失敗在 Temporal 中可重試的情境。也適用於串流輸出 Agent 回應或保存串流對話。
執行需求
需要 @outputai/llm 套件與 TypeScript 環境,並需了解 Output 工作流程步驟與 Temporal 重試。此技能不含指令碼,僅為說明文件。

LLM Text Streaming

When to Use This Skill

  • Adding token or chunk progress to an LLM-powered step
  • Choosing between completed generation and direct stream access
  • Using onChunk, or onEnd / onError on streamText() / Agent.stream()
  • Making stream failures trigger Temporal activity retries
  • Streaming Agent responses or persisting streamed conversations

Choose the API

NeedUse
Complete single-shot resultgenerateText()
Complete result plus onChunk progressgenerateTextWithStreaming()
Direct access to textStream or streamstreamText()
Complete Agent result plus onChunk progressAgent.generateWithStreaming()
Direct access to the Agent streamAgent.stream()

In workflow steps, prefer generateTextWithStreaming() or Agent.generateWithStreaming() when onChunk progress is sufficient. They consume the stream internally, return complete results like generateText() or Agent.generate(), and reject on provider, transport, or abort errors. Rejection allows Temporal to record the failed activity attempt and apply the step retry policy.

streamText() and Agent.stream() remain supported for code that needs direct control over stream consumption.

generateTextWithStreaming()

typescript
import { generateTextWithStreaming } from '@outputai/llm';
const result = await generateTextWithStreaming( {  prompt: 'draft@v1',  variables: { topic },  onChunk( { chunk } ) {    if ( chunk.type === 'text-delta' ) {      process.stdout.write( chunk.text );    }  }} );
return result.result;

The result has the same complete response fields as generateText(), including result, text, output, usage, finishReason, and cost. Structured output passed with aiSdk.Output.* is available through result.output.

Agent.generateWithStreaming()

typescript
const result = await agent.generateWithStreaming( {  onChunk( { chunk } ) {    if ( chunk.type === 'text-delta' ) {      process.stdout.write( chunk.text );    }  }} );

generateWithStreaming() returns a complete Agent response and automatically stores messages when the Agent has a messageStore.

Direct stream error handling

AI SDK streaming delivers provider and transport failures through onError. Iterating textStream does not reliably throw the original error. When using streamText() in a workflow step, capture the error and throw it after consumption:

typescript
import { streamText } from '@outputai/llm';
const captured: { error: unknown } = { error: null };const result = streamText( {  prompt: 'draft@v1',  variables: { topic },  onError( { error } ) {    captured.error = error;  }} );
const chunks: string[] = [];for await ( const chunk of result.textStream ) {  chunks.push( chunk );}
if ( captured.error ) {  throw captured.error;}
return chunks.join( '' );

Registering onError without throwing the captured error can let the step return an empty successful result, preventing Temporal from retrying it. Awaiting a completion property may also produce a generic no-output error instead of the original provider error.

Agent.stream() stores conversation messages in its wrapped onEnd when finishReason is not 'error'. Use Agent.generateWithStreaming() when a complete stored response meets the requirement.

Streaming call arguments: prompt, promptDir, variables, tools, output, toolChoice, stopWhen, abortSignal, plus onChunk (generateTextWithStreaming) or onChunk / onEnd / onError (streamText). Agent methods: messages, abortSignal, toolChoice, plus those same stream callbacks.

Rules

  • Prefer the completed streaming APIs in Temporal steps unless direct stream access is required.
  • Do not rely on onError alone to fail a step using streamText().
  • Throw the captured error only after stream consumption finishes.
  • Keep onChunk side effects bounded. A Temporal signal per token creates a history event per signal, so batch high-frequency updates.
  • Do not describe streamText() or Agent.stream() as deprecated.

Related Skills

  • output-dev-step-function - Put LLM calls inside Temporal activity steps
  • output-dev-agent-class - Construct and use reusable Agents
  • output-dev-prompt-file - Create prompt files for generation
  • output-error-try-catch - Handle step and workflow failures

來源與署名

來源:growthxai/output位於coding_assistants/claude/plugins/outputai/skills/output-dev-llm-streaming提交a4f6bd4

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架