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 从公开仓库中收录这些内容。

举报或申请下架