• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdevelopment

output-dev-llm-streaming

プラグイン
outputai
ソース
GitHub で見る ↗
説明

LLM のテキストストリーミング(大量のテキストを小分けにしてリアルタイムで送信する機能)を出力ワークフロー ステップに実装します。 **使用方法:** - `generateTextWithStreaming` - `Agent.generateWithStreaming` - `streamText` - `Agent.stream` **次のような場合に使用:** - トークン(言語処理の最小単位)の進捗表示を追加する - onChunk コールバック(処理の途中経過を受け取る仕組み)を設定する - streamText の onFinish/onError を Temporal リトライ(エラー時の自動再試行)と組み合わせて処理する

原文を表示

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 onFinish/onError with Temporal retries.

ユースケース
  • トークンの進捗表示を追加する
  • onChunkコールバックを設定する
  • ストリーミング出力にリトライ処理を組み合わせる
本文(日本語訳)

LLM テキストストリーミング

次のような場合に使用

  • LLM(大規模言語モデル)を使った処理ステップにトークン(言語処理の最小単位)やチャンク(データの分割単位)の進捗を追加したい
  • 生成完了の結果と直接ストリーム(連続したデータの流れ)アクセスのどちらかを選びたい
  • streamText() または Agent.stream() 上で onChunk、onFinish/onError を使いたい
  • ストリーミング失敗を Temporal(ワークフロー管理フレームワーク)のアクティビティ再試行の引き金にしたい
  • Agent(自動処理エージェント)の応答をストリーミングしたり、ストリーム化された会話を保存したりしたい

API を選ぶ

必要な機能 使用する API
単発の完全な結果 generateText()
完全な結果と onChunk 進捗情報 generateTextWithStreaming()
textStream または fullStream への直接アクセス streamText()
Agent の完全な結果と onChunk 進捗情報 Agent.generateWithStreaming()
Agent ストリームへの直接アクセス Agent.stream()

ワークフロー処理ステップでは、onChunk による進捗情報で十分な場合は generateTextWithStreaming() または Agent.generateWithStreaming() を優先します。

これらは内部でストリームを処理し、generateText() や Agent.generate() と同じように完全な結果を返し、プロバイダー(サービス提供元)のエラー、通信エラー、キャンセルエラーの場合は処理を中断します。中断により、Temporal は失敗したアクティビティを記録し、設定されたステップ再試行ポリシーを適用できます。

streamText() と Agent.stream() は、ストリーム処理を自分で完全に制御する必要があるコードのために引き続きサポートされています。

generateTextWithStreaming()

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;

結果には、generateText() と同じ完全な応答フィールド(result、text、output、usage、finishReason、cost)が含まれます。aiSdk.Output.* で指定した構造化出力は result.output からアクセスできます。

Agent.generateWithStreaming()

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

generateWithStreaming() は完全な Agent 応答を返し、Agent が messageStore(メッセージ保存機能)を持つ場合は自動的にメッセージを保存します。

直接ストリームのエラーハンドリング

AI SDK ストリーミングは、プロバイダーと通信のエラーを onError 経由で通知します。textStream を反復処理するだけでは、元のエラーが確実に例外として発生しません。ワークフロー処理ステップで streamText() を使う場合は、エラーを捕捉してから処理を中断してください:

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( '' );

onError を登録しても捕捉したエラーを発生させなければ、ステップが成功した結果を返してしまい、Temporal が再試行できなくなります。完了用プロパティを await する方法も、元のプロバイダーエラーではなく汎用的な「出力なし」エラーを生じる可能性があります。

Agent.stream() は、finishReason が 'error' でない場合、ラップされた onFinish で会話メッセージを保存します。完全に保存された応答で要件が満たされる場合は Agent.generateWithStreaming() を使用してください。

ストリーミング呼び出しの引数:prompt、promptDir、variables、tools、output、toolChoice、stopWhen、abortSignal、および onChunk(generateTextWithStreaming)または onChunk/onFinish/onError(streamText)。Agent メソッド:messages、abortSignal、toolChoice、およびそれらと同じストリーム関数。

ルール

  • 直接ストリームアクセスが必要でない限り、Temporal ステップでは完成したストリーミング API を優先してください。
  • streamText() でステップを失敗させるため、onError だけに頼らないでください。
  • ストリーム処理が完了したあとで、捕捉したエラーを発生させてください。
  • onChunk の副作用を制限してください。トークンごとの Temporal シグナルはシグナルごとに履歴イベントを作成するため、高頻度の更新はまとめてください。
  • streamText() または Agent.stream() を非推奨と説明しないでください。

関連スキル

  • output-dev-step-function - LLM 呼び出しを Temporal アクティビティステップ内に配置する
  • output-dev-agent-class - 再利用可能な Agent の構築と使用
  • output-dev-prompt-file - 生成用のプロンプトファイルを作成する
  • output-error-try-catch - ステップとワークフローの失敗を処理する
原文(English)を表示

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 onFinish / onError on streamText() / Agent.stream()
  • Making stream failures trigger Temporal activity retries
  • Streaming Agent responses or persisting streamed conversations

Choose the API

Need Use
Complete single-shot result generateText()
Complete result plus onChunk progress generateTextWithStreaming()
Direct access to textStream or fullStream streamText()
Complete Agent result plus onChunk progress Agent.generateWithStreaming()
Direct access to the Agent stream Agent.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()

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()

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:

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 onFinish 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 / onFinish / 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

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。