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:
runId:
from:
AGENT:
USER:
SYSTEM:
WORKFLOW:
文本块Direct link to 文本块
🌐 Text Chunks
text-startDirect link to text-start
表示文本生成的开始。
🌐 Signals the beginning of text generation.
type:
payload:
id:
providerMetadata?:
text-deltaDirect link to text-delta
生成过程中递增的文本内容。
🌐 Incremental text content during generation.
type:
payload:
id:
text:
providerMetadata?:
text-endDirect link to text-end
表示文本生成结束。
🌐 Signals the end of text generation.
type:
payload:
id:
providerMetadata?:
推断模块Direct link to 推断模块
🌐 Reasoning Chunks
reasoning-startDirect link to reasoning-start
标志着推断生成的开始(适用于支持推断的模型)。
🌐 Signals the beginning of reasoning generation (for models that support reasoning).
type:
payload:
id:
signature?:
providerMetadata?:
reasoning-deltaDirect link to reasoning-delta
生成过程中逐步推断的文本。
🌐 Incremental reasoning text during generation.
type:
payload:
id:
text:
providerMetadata?:
reasoning-endDirect link to reasoning-end
表示推断生成的结束。
🌐 Signals the end of reasoning generation.
type:
payload:
id:
signature?:
providerMetadata?:
reasoning-signatureDirect 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:
payload:
id:
signature:
providerMetadata?:
工具块Direct link to 工具块
🌐 Tool Chunks
tool-callDirect link to tool-call
正在调用一个工具。
🌐 A tool is being called.
type:
payload:
toolCallId:
toolName:
args?:
providerExecuted?:
output?:
providerMetadata?:
tool-resultDirect link to tool-result
工具执行的结果。
🌐 Result from a tool execution.
type:
payload:
toolCallId:
toolName:
result:
isError?:
providerExecuted?:
args?:
providerMetadata?:
tool-call-input-streaming-startDirect link to tool-call-input-streaming-start
表示流式工具调用参数的开始。
🌐 Signals the start of streaming tool call arguments.
type:
payload:
toolCallId:
toolName:
providerExecuted?:
dynamic?:
providerMetadata?:
tool-call-deltaDirect link to tool-call-delta
流式处理期间的增量工具调用参数。
🌐 Incremental tool call arguments during streaming.
type:
payload:
argsTextDelta:
toolCallId:
toolName?:
providerMetadata?:
tool-call-input-streaming-endDirect link to tool-call-input-streaming-end
表示流式工具调用参数的结束。
🌐 Signals the end of streaming tool call arguments.
type:
payload:
toolCallId:
providerMetadata?:
tool-errorDirect link to tool-error
工具执行过程中发生错误。
🌐 An error occurred during tool execution.
type:
payload:
id?:
toolCallId:
toolName:
args?:
error:
providerExecuted?:
providerMetadata?:
源和文件块Direct link to 源和文件块
🌐 Source and File Chunks
sourceDirect link to source
包含内容的来源信息。
🌐 Contains source information for content.
type:
payload:
id:
sourceType:
title:
mimeType?:
filename?:
url?:
providerMetadata?:
fileDirect link to file
包含文件数据。
🌐 Contains file data.
type:
payload:
data:
base64?:
mimeType:
providerMetadata?:
控制块Direct link to 控制块
🌐 Control Chunks
startDirect link to start
表示开始流式传输。
🌐 Signals the start of streaming.
type:
payload:
[key: string]:
step-startDirect link to step-start
表示处理步骤的开始。
🌐 Signals the start of a processing step.
type:
payload:
messageId?:
request:
warnings?:
step-finishDirect link to step-finish
表示处理步骤已完成。
🌐 Signals the completion of a processing step.
type:
payload:
id?:
messageId?:
stepResult:
output:
metadata:
totalUsage?:
response?:
providerMetadata?:
rawDirect link to raw
包含来自提供商的原始数据。
🌐 Contains raw data from the provider.
type:
payload:
[key: string]:
finishDirect link to finish
流已成功完成。
🌐 Stream has completed successfully.
type:
payload:
stepResult:
output:
metadata:
messages:
response:
errorDirect link to error
流播放时发生错误。
🌐 An error occurred during streaming.
type:
payload:
error:
abortDirect link to abort
流已中止。
🌐 Stream was aborted.
type:
payload:
[key: string]:
对象和输出块Direct link to 对象和输出块
🌐 Object and Output Chunks
objectDirect 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:
tool-outputDirect 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:
payload:
output:
step-outputDirect 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:
payload:
output:
元数据和特殊块Direct link to 元数据和特殊块
🌐 Metadata and Special Chunks
response-metadataDirect 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:
payload:
signature?:
[key: string]:
watchDirect 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:
payload:
workflowState?:
eventTimestamp?:
[key: string]:
tripwireDirect 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:
payload:
reason:
retry?:
metadata?:
processorId?:
使用示例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;
}
}
相关类型Direct link to 相关类型
🌐 Related Types
- .stream() - 返回发出这些块的流的方法
- MastraModelOutput - 发出这些数据块的流对象
- workflow.stream() - 返回为工作流生成这些数据块的流的方法