Agent Network Streaming Issue (AI SDK v5)

Hi guys, I have old production app (50K+ users) that I am trying to convert to AI assistent chat bot. I have built a working versionwith Vercel AI SDK, but decided to migrate to Mastra (greedy). Stuck for 3 weeks on agent.network() streaming. Streaming is still broken after 0.21 upgrade. Need guidance urgently - my option is to revert to AI SDK but that wastes 3 weeks of migration work. Really want to stay with Mastra.

Setup

  • Mastra 0.21.0 + AI SDK v5, orchestrator with 8 sub-agents (Gmail, SEO, Sheets, Calendar, Ghost, Web, Voting, General), OpenRouter gpt-4o-mini
const networkStream = await orchestrator.network(content, options);
for await (const part of toAISdkFormat(networkStream, { from: 'network' })) {
    writer.write(part);
}


What We Observe


✅ What Works

  • Agent routing is flawless - orchestrator correctly identifies and delegates to appropriate sub-agents
  • Sub-agents execute successfully - tools called, operations completed
  • Terminal logs show proper execution flow: orchestrator → sub-agent → tool execution → completion
### ❌ Streaming Issues

  1. No text-delta chunks during execution

[CHAT-API] 📊 Stream iteration complete, chunks: 21 text collected: 0 chars

  • Stream only emits data-network metadata chunks
  • Zero text-delta chunks throughout entire execution
  • No real-time text updates to UI
  1. Text only available after full completion

const networkResult = await networkStream.result;
console.log(networkResult?.result?.result); // Contains actual response text

  • Text appears in networkResult.result.result path
  • Arrives as single blob after all agents finish
  • Not streamed incrementally
  1. Frontend receives raw metadata

// chat.tsx - had to add this filtering
onData: (dataPart) => {
    if (dataPart.type === 'data-network') {
        return; // Filter out or UI shows raw JSON objects
    }
}

  • Without filtering, UI displays raw data-network JSON
  • After page refresh, database-saved chunks appear as [object Object] in UI
## Current Workaround

// Extract text after stream completes
if (!finalOutput) {
    const networkResult = await networkStream.result;
    const finalText = networkResult?.result?.result;

    if (finalText && typeof finalText === 'string') {
        writer.write({ type: 'text-delta', delta: finalText, id: messageId });
    }
}


This works but defeats the purpose of streaming - user sees nothing until full execution completes.

Questions


  1. **Is `agent.network()` designed to stream text-delta chunks in real-time?**
    • Or is it purely for internal routing with final result extraction?
    • Should we expect incremental text updates during sub-agent execution?
  2. **What should `data-network` chunks contain and how should they be handled?**
    • Should these be filtered from UI display?
    • Are they being saved to database incorrectly?
    • Should they only be used internally by Mastra?
  3. **Are we using the right API for UI streaming?**
    • Should multi-agent streaming use agent.stream() with manual routing logic instead?
    • Is network() intended for backend orchestration only?
  4. **What's the expected data flow?**
    • Should orchestrator stream its own "thinking" text while routing?
    • Should sub-agent responses be streamed back through the network stream?
    • Or is the pattern: route silently → extract final result → display?
## What We Need

Confirmation on the intended streaming behavior of agent.network() for real-time UI updates. The routing works perfectly - just trying to understand if we're using the right API pattern for streaming multi-agent responses to users.

@_roamin_ @Ward I would really appreciate your assistance on this. 🙏
image.png
image.png
image.png
Was this page helpful?