Skip to main content

ChunkType

ChunkType 类型定义了在代理流响应过程中可以发送的流块的 mastra 格式。

🌐 The ChunkType type defines the mastra format of stream chunks that can be emitted during streaming responses from agents.

基础属性
Direct link to 基础属性

🌐 Base Properties

所有块都包括这些基本属性:

🌐 All chunks include these base properties:

type:

string
The specific chunk type identifier

runId:

string
Unique identifier for this execution run

from:

ChunkFrom
Source of the chunk
enum

AGENT:

'AGENT'
Chunk from agent execution

USER:

'USER'
Chunk from user input

SYSTEM:

'SYSTEM'
Chunk from system processes

WORKFLOW:

'WORKFLOW'
Chunk from workflow execution

文本块
Direct link to 文本块

🌐 Text Chunks

text-start
Direct link to text-start

表示文本生成的开始。

🌐 Signals the beginning of text generation.

type:

"text-start"
Chunk type identifier

payload:

TextStartPayload
Text start information
TextStartPayload

id:

string
Unique identifier for this text generation

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

text-delta
Direct link to text-delta

生成过程中递增的文本内容。

🌐 Incremental text content during generation.

type:

"text-delta"
Chunk type identifier

payload:

TextDeltaPayload
Incremental text content
TextDeltaPayload

id:

string
Unique identifier for this text generation

text:

string
The incremental text content

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

text-end
Direct link to text-end

表示文本生成结束。

🌐 Signals the end of text generation.

type:

"text-end"
Chunk type identifier

payload:

TextEndPayload
Text end information
TextEndPayload

id:

string
Unique identifier for this text generation

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

推断模块
Direct link to 推断模块

🌐 Reasoning Chunks

reasoning-start
Direct link to reasoning-start

标志着推断生成的开始(适用于支持推断的模型)。

🌐 Signals the beginning of reasoning generation (for models that support reasoning).

type:

"reasoning-start"
Chunk type identifier

payload:

ReasoningStartPayload
Reasoning start information
ReasoningStartPayload

id:

string
Unique identifier for this reasoning generation

signature?:

string
Reasoning signature if available

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

reasoning-delta
Direct link to reasoning-delta

生成过程中逐步推断的文本。

🌐 Incremental reasoning text during generation.

type:

"reasoning-delta"
Chunk type identifier

payload:

ReasoningDeltaPayload
Incremental reasoning content
ReasoningDeltaPayload

id:

string
Unique identifier for this reasoning generation

text:

string
The incremental reasoning text

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

reasoning-end
Direct link to reasoning-end

表示推断生成的结束。

🌐 Signals the end of reasoning generation.

type:

"reasoning-end"
Chunk type identifier

payload:

ReasoningEndPayload
Reasoning end information
ReasoningEndPayload

id:

string
Unique identifier for this reasoning generation

signature?:

string
Final reasoning signature if available

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

reasoning-signature
Direct link to reasoning-signature

包含支持高级推断的模型(如 OpenAI 的 o1 系列)的推断签名。该签名表示关于模型内部推断过程的元数据,例如努力程度或推断方法,但不包含实际的推断内容本身。

🌐 Contains the reasoning signature from models that support advanced reasoning (like OpenAI's o1 series). The signature represents metadata about the model's internal reasoning process, such as effort level or reasoning approach, but not the actual reasoning content itself.

type:

"reasoning-signature"
Chunk type identifier

payload:

ReasoningSignaturePayload
Metadata about the model's reasoning process characteristics
ReasoningSignaturePayload

id:

string
Unique identifier for the reasoning session

signature:

string
Signature describing the reasoning approach or effort level (e.g., reasoning effort settings)

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

工具块
Direct link to 工具块

🌐 Tool Chunks

tool-call
Direct link to tool-call

正在调用一个工具。

🌐 A tool is being called.

type:

"tool-call"
Chunk type identifier

payload:

ToolCallPayload
Tool call information
ToolCallPayload

toolCallId:

string
Unique identifier for this tool call

toolName:

string
Name of the tool being called

args?:

Record<string, any>
Arguments passed to the tool

providerExecuted?:

boolean
Whether the provider executed the tool

output?:

any
Tool output if available

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

tool-result
Direct link to tool-result

工具执行的结果。

🌐 Result from a tool execution.

type:

"tool-result"
Chunk type identifier

payload:

ToolResultPayload
Tool execution result
ToolResultPayload

toolCallId:

string
Unique identifier for the tool call

toolName:

string
Name of the executed tool

result:

any
The result of the tool execution

isError?:

boolean
Whether the result is an error

providerExecuted?:

boolean
Whether the provider executed the tool

args?:

Record<string, any>
Arguments that were passed to the tool

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

tool-call-input-streaming-start
Direct link to tool-call-input-streaming-start

表示流式工具调用参数的开始。

🌐 Signals the start of streaming tool call arguments.

type:

"tool-call-input-streaming-start"
Chunk type identifier

payload:

ToolCallInputStreamingStartPayload
Tool call input streaming start information
ToolCallInputStreamingStartPayload

toolCallId:

string
Unique identifier for this tool call

toolName:

string
Name of the tool being called

providerExecuted?:

boolean
Whether the provider executed the tool

dynamic?:

boolean
Whether the tool call is dynamic

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

tool-call-delta
Direct link to tool-call-delta

流式处理期间的增量工具调用参数。

🌐 Incremental tool call arguments during streaming.

type:

"tool-call-delta"
Chunk type identifier

payload:

ToolCallDeltaPayload
Incremental tool call arguments
ToolCallDeltaPayload

argsTextDelta:

string
Incremental text delta for tool arguments

toolCallId:

string
Unique identifier for this tool call

toolName?:

string
Name of the tool being called

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

tool-call-input-streaming-end
Direct link to tool-call-input-streaming-end

表示流式工具调用参数的结束。

🌐 Signals the end of streaming tool call arguments.

type:

"tool-call-input-streaming-end"
Chunk type identifier

payload:

ToolCallInputStreamingEndPayload
Tool call input streaming end information
ToolCallInputStreamingEndPayload

toolCallId:

string
Unique identifier for this tool call

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

tool-error
Direct link to tool-error

工具执行过程中发生错误。

🌐 An error occurred during tool execution.

type:

"tool-error"
Chunk type identifier

payload:

ToolErrorPayload
Tool error information
ToolErrorPayload

id?:

string
Optional identifier

toolCallId:

string
Unique identifier for the tool call

toolName:

string
Name of the tool that failed

args?:

Record<string, any>
Arguments that were passed to the tool

error:

unknown
The error that occurred

providerExecuted?:

boolean
Whether the provider executed the tool

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

源和文件块
Direct link to 源和文件块

🌐 Source and File Chunks

source
Direct link to source

包含内容的来源信息。

🌐 Contains source information for content.

type:

"source"
Chunk type identifier

payload:

SourcePayload
Source information
SourcePayload

id:

string
Unique identifier

sourceType:

'url' | 'document'
Type of source

title:

string
Title of the source

mimeType?:

string
MIME type of the source

filename?:

string
Filename if applicable

url?:

string
URL if applicable

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

file
Direct link to file

包含文件数据。

🌐 Contains file data.

type:

"file"
Chunk type identifier

payload:

FilePayload
File data
FilePayload

data:

string | Uint8Array
The file data

base64?:

string
Base64 encoded data if applicable

mimeType:

string
MIME type of the file

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

控制块
Direct link to 控制块

🌐 Control Chunks

start
Direct link to start

表示开始流式传输。

🌐 Signals the start of streaming.

type:

"start"
Chunk type identifier

payload:

StartPayload
Start information
StartPayload

[key: string]:

any
Additional start data

step-start
Direct link to step-start

表示处理步骤的开始。

🌐 Signals the start of a processing step.

type:

"step-start"
Chunk type identifier

payload:

StepStartPayload
Step start information
StepStartPayload

messageId?:

string
Optional message identifier

request:

object
Request information including body and other data

warnings?:

LanguageModelV2CallWarning[]
Any warnings from the language model call

step-finish
Direct link to step-finish

表示处理步骤已完成。

🌐 Signals the completion of a processing step.

type:

"step-finish"
Chunk type identifier

payload:

StepFinishPayload
Step completion information
StepFinishPayload

id?:

string
Optional identifier

messageId?:

string
Optional message identifier

stepResult:

object
Step execution result with reason, warnings, and continuation info

output:

object
Output information including usage statistics

metadata:

object
Execution metadata including request and provider info

totalUsage?:

LanguageModelV2Usage
Total usage statistics

response?:

LanguageModelV2ResponseMetadata
Response metadata

providerMetadata?:

SharedV2ProviderMetadata
Provider-specific metadata

raw
Direct link to raw

包含来自提供商的原始数据。

🌐 Contains raw data from the provider.

type:

"raw"
Chunk type identifier

payload:

RawPayload
Raw provider data
RawPayload

[key: string]:

any
Raw data from the provider

finish
Direct link to finish

流已成功完成。

🌐 Stream has completed successfully.

type:

"finish"
Chunk type identifier

payload:

FinishPayload
Completion information
FinishPayload

stepResult:

object
Step execution result

output:

object
Output information including usage

metadata:

object
Execution metadata

messages:

object
Message history

response:

object
Response metadata and messages from the model provider

error
Direct link to error

流播放时发生错误。

🌐 An error occurred during streaming.

type:

"error"
Chunk type identifier

payload:

ErrorPayload
Error information
ErrorPayload

error:

unknown
The error that occurred

abort
Direct link to abort

流已中止。

🌐 Stream was aborted.

type:

"abort"
Chunk type identifier

payload:

AbortPayload
Abort information
AbortPayload

[key: string]:

any
Additional abort data

对象和输出块
Direct link to 对象和输出块

🌐 Object and Output Chunks

object
Direct link to object

在使用带有定义模式的输出生成时触发。包含符合指定 Zod 或 JSON 模式的部分或完整结构化数据。这个数据块通常在某些执行环境中被跳过,用于流式生成结构化对象。

🌐 Emitted when using output generation with defined schemas. Contains partial or complete structured data that conforms to the specified Zod or JSON schema. This chunk is typically skipped in some execution contexts and used for streaming structured object generation.

type:

"object"
Chunk type identifier

object:

Partial<OUTPUT>
Partial or complete structured data matching the defined schema. The type is determined by the OUTPUT schema parameter.

tool-output
Direct link to tool-output

包含代理或工作流执行的输出,尤其用于跟踪使用统计和完成事件。通常会封装其他块类型(如完成块)以提供嵌套的执行上下文。

🌐 Contains output from agent or workflow execution, particularly used for tracking usage statistics and completion events. Often wraps other chunk types (like finish chunks) to provide nested execution context.

type:

"tool-output"
Chunk type identifier

payload:

ToolOutputPayload
Wrapped execution output with metadata
ToolOutputPayload

output:

ChunkType
Nested chunk data, often containing finish events with usage statistics

step-output
Direct link to step-output

包含工作流步骤执行的输出,主要用于使用情况跟踪和步骤完成事件。类似于工具输出,但专门针对单个工作流步骤。

🌐 Contains output from workflow step execution, used primarily for usage tracking and step completion events. Similar to tool-output but specifically for individual workflow steps.

type:

"step-output"
Chunk type identifier

payload:

StepOutputPayload
Workflow step execution output with metadata
StepOutputPayload

output:

ChunkType
Nested chunk data from step execution, typically containing finish events or other step results

元数据和特殊块
Direct link to 元数据和特殊块

🌐 Metadata and Special Chunks

response-metadata
Direct link to response-metadata

包含有关大型语言模型提供商响应的元数据。一些提供商在生成文本后会发出此信息,以提供额外的上下文,例如模型ID、时间戳和响应头。此部分用于内部状态跟踪,不会影响消息的组装。

🌐 Contains metadata about the LLM provider's response. Emitted by some providers after text generation to provide additional context like model ID, timestamps, and response headers. This chunk is used internally for state tracking and doesn't affect message assembly.

type:

"response-metadata"
Chunk type identifier

payload:

ResponseMetadataPayload
Provider response metadata for tracking and debugging
ResponseMetadataPayload

signature?:

string
Response signature if available

[key: string]:

any
Additional provider-specific metadata fields (e.g., id, modelId, timestamp, headers)

watch
Direct link to watch

包含来自代理执行的监控和可观察性数据。根据 stream() 使用的上下文,可能包括工作流状态信息、执行进度或其他运行时详细信息。

🌐 Contains monitoring and observability data from agent execution. Can include workflow state information, execution progress, or other runtime details depending on the context where stream() is used.

type:

"watch"
Chunk type identifier

payload:

WatchPayload
Monitoring data for observability and debugging of agent execution
WatchPayload

workflowState?:

object
Current workflow execution state (when used in workflows)

eventTimestamp?:

number
Timestamp when the event occurred

[key: string]:

any
Additional monitoring and execution data

tripwire
Direct link to tripwire

当流因为内容被处理器阻止而被强制终止时,会触发此事件。这是一种安全机制,用于防止有害或不适当的内容被传输。有效负载包含关于内容被阻止的原因以及是否请求重试的信息。

🌐 Emitted when the stream is forcibly terminated due to content being blocked by a processor. This acts as a safety mechanism to prevent harmful or inappropriate content from being streamed. The payload includes information about why the content was blocked and whether a retry was requested.

type:

"tripwire"
Chunk type identifier

payload:

TripwirePayload
Information about why the stream was terminated by safety mechanisms
TripwirePayload

reason:

string
Explanation of why the content was blocked (e.g., 'Output processor blocked content')

retry?:

boolean
Whether the processor requested a retry of the step

metadata?:

unknown
Additional metadata from the processor (e.g., scores, categories)

processorId?:

string
ID of the processor that triggered the tripwire

使用示例
Direct link to 使用示例

🌐 Usage Example

const stream = await agent.stream("Hello");

for await (const chunk of stream.fullStream) {
switch (chunk.type) {
case "text-delta":
console.log("Text:", chunk.payload.text);
break;

case "tool-call":
console.log("Calling tool:", chunk.payload.toolName);
break;

case "tool-result":
console.log("Tool result:", chunk.payload.result);
break;

case "reasoning-delta":
console.log("Reasoning:", chunk.payload.text);
break;

case "finish":
console.log("Finished:", chunk.payload.stepResult.reason);
console.log("Usage:", chunk.payload.output.usage);
break;

case "error":
console.error("Error:", chunk.payload.error);
break;
}
}

🌐 Related Types