handleWorkflowStream()
用于 AI SDK 兼容格式中流式工作流执行的框架无关处理器。当你需要在 Hono 或 Mastra 自身的 apiRoutes 功能之外处理工作流流式传输时,可以直接使用此函数。
🌐 Framework-agnostic handler for streaming workflow execution in AI SDK-compatible format. Use this function directly when you need to handle workflow streaming outside Hono or Mastra's own apiRoutes feature.
handleWorkflowStream() 返回一个 ReadableStream,你可以用 createUIMessageStreamResponse() 封装它。
如果你想在 Mastra 服务器中创建工作流程路线,请使用 workflowRoute()。
🌐 Use workflowRoute() if you want to create a workflow route inside a Mastra server.
当工作流步骤将代理的流传输给工作流写入器(例如 await response.fullStream.pipeTo(writer))时,代理的文本块和工具调用会实时转发到 UI 流,即使代理在工作流步骤内运行也是如此。
🌐 When a workflow step pipes an agent's stream to the workflow writer (e.g., await response.fullStream.pipeTo(writer)), the agent's text chunks and tool calls are forwarded to the UI stream in real time, even when the agent runs inside workflow steps.
有关更多详细信息,请参见 工作流流式处理。
🌐 See Workflow Streaming for more details.
使用示例Direct link to 使用示例
🌐 Usage example
Next.js 应用路由示例:
🌐 Next.js App Router example:
import { handleWorkflowStream } from '@mastra/ai-sdk';
import { createUIMessageStreamResponse } from 'ai';
import { mastra } from '@/src/mastra';
export async function POST(req: Request) {
const params = await req.json();
const stream = await handleWorkflowStream({
mastra,
workflowId: 'weatherWorkflow',
params,
});
return createUIMessageStreamResponse({ stream });
}
参数Direct link to 参数
🌐 Parameters