Skip to content

Commit b30b191

Browse files
committed
feat: add Network Info and Routing panels
- Implemented the NetworkInfoPanel component to display network details, including: - Overview of the selected network with its name, description, category, and features. - List of agents associated with the network, highlighting active agents. - Collapsible sections for different network categories (routing, pipeline, research) with the ability to select networks. - Created the NetworkRoutingPanel component to visualize the routing flow, featuring: - Status indicators for each routing step (completed, active, error). - Display of available agents in the network. - Dynamic updates based on the current network status (idle, routing, executing, completed, error).
1 parent 2a5abc8 commit b30b191

9 files changed

Lines changed: 1661 additions & 78 deletions

File tree

app/chat/helpers/tool-part-transform.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ export function mapDataToolPartToDynamicToolPart(part: any): DynamicToolUIPart |
4747
payload = candidate.toolInvocation;
4848
break;
4949
}
50-
if (isObject(candidate?.data)) {
51-
// If candidate.data looks like call/args/out, prefer it
52-
if (isObject(candidate.data?.input) || isObject(candidate.data?.output) || candidate.data.id) {
53-
payload = candidate.data;
54-
break;
55-
}
50+
if (isObject(candidate?.data) && (isObject(candidate.data?.input) || isObject(candidate.data?.output) || candidate.data.id)) {
51+
payload = candidate.data;
52+
break;
5653
}
5754
}
5855

app/networks/AGENTS.md

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@
22

33
## Overview
44

5-
The networks page provides an interface for interacting with Mastra agent networks using `@ai-sdk/react` and `DefaultChatTransport` to stream responses from the `/network` route.
5+
The networks page provides an advanced chat interface for interacting with Mastra agent networks. It uses `@ai-sdk/react` with `DefaultChatTransport` to stream responses from the `/network` route, and leverages **AI Elements** components for a rich chat experience.
66

77
## Architecture
88

9-
Follows the same modular pattern as chat and workflows:
10-
119
```text
1210
app/networks/
13-
├── page.tsx # Main page component
11+
├── page.tsx # Main page with chat + routing panel
1412
├── config/
15-
│ └── networks.ts # Network definitions and types
13+
│ └── networks.ts # Network definitions and types
1614
├── providers/
17-
│ └── network-context.tsx # State management with useChat
15+
│ └── network-context.tsx # State management with useChat
1816
└── components/
19-
├── network-header.tsx # Header with network selector
20-
├── network-agents.tsx # Agent list sidebar
21-
├── network-messages.tsx # Conversation display
22-
└── network-input.tsx # Message input
17+
├── network-header.tsx # Header with network selector
18+
├── network-chat.tsx # AI Elements chat (Conversation, Message, Reasoning, Tool)
19+
├── network-routing-panel.tsx # Visual routing flow sidebar
20+
├── network-agents.tsx # Agent list (legacy, optional)
21+
├── network-messages.tsx # Basic messages (legacy)
22+
└── network-input.tsx # Basic input (legacy)
2323
```
2424

25+
## AI Elements Integration
26+
27+
The network chat uses AI Elements components for a rich chat experience:
28+
29+
- **Conversation** - Auto-scrolling message container
30+
- **Message/MessageContent/MessageResponse** - Styled message bubbles with markdown
31+
- **Reasoning** - Collapsible reasoning display for chain-of-thought
32+
- **Tool** - Tool invocation visualization with input/output
33+
- **PromptInput** - Enhanced input with network selector
34+
2535
## AI SDK Integration
2636

27-
Uses `useChat` from `@ai-sdk/react` with `DefaultChatTransport` to connect to Mastra's `/network` route:
37+
Uses `useChat` from `@ai-sdk/react` with `DefaultChatTransport`:
2838

2939
```tsx
3040
import { useChat } from "@ai-sdk/react"
@@ -50,36 +60,49 @@ const { messages, sendMessage, stop, status } = useChat({
5060

5161
All 4 Mastra networks are configured in `config/networks.ts`:
5262

53-
- agentNetwork - Intelligent routing to specialized agents
54-
- dataPipelineNetwork - Data ingestion, transformation, export
55-
- reportGenerationNetwork - Research, analysis, report generation
56-
- researchPipelineNetwork - Multi-source research aggregation
63+
| Network | Description |
64+
|---------|-------------|
65+
| agentNetwork | Intelligent routing to specialized agents |
66+
| dataPipelineNetwork | Data ingestion, transformation, export |
67+
| reportGenerationNetwork | Research, analysis, report generation |
68+
| researchPipelineNetwork | Multi-source research aggregation |
5769

5870
## Usage
5971

6072
```tsx
6173
import { NetworkProvider } from "./providers/network-context"
6274
import { NetworkHeader } from "./components/network-header"
63-
import { NetworkAgents } from "./components/network-agents"
64-
import { NetworkMessages } from "./components/network-messages"
65-
import { NetworkInput } from "./components/network-input"
75+
import { NetworkChat } from "./components/network-chat"
76+
import { NetworkRoutingPanel } from "./components/network-routing-panel"
6677

6778
<NetworkProvider defaultNetwork="agentNetwork">
6879
<NetworkHeader />
69-
<NetworkAgents />
70-
<NetworkMessages />
71-
<NetworkInput />
80+
<NetworkChat />
81+
<NetworkRoutingPanel />
7282
</NetworkProvider>
7383
```
7484

7585
## Context API
7686

7787
`useNetworkContext()` provides:
7888

79-
- `selectedNetwork` - Currently selected network ID
80-
- `networkConfig` - Current network configuration
81-
- `networkStatus` - idle | routing | executing | completed | error
82-
- `messages` - AI SDK message history
83-
- `streamingOutput` - Current streaming text
84-
- `sendMessage(text)` - Send message to network
85-
- `stopExecution()` - Stop streaming
89+
| Property | Type | Description |
90+
|----------|------|-------------|
91+
| `selectedNetwork` | string | Currently selected network ID |
92+
| `networkConfig` | NetworkConfig | Current network configuration |
93+
| `networkStatus` | Status | idle \| routing \| executing \| completed \| error |
94+
| `messages` | UIMessage[] | AI SDK message history |
95+
| `streamingOutput` | string | Current streaming text |
96+
| `routingSteps` | RoutingStep[] | Agent routing visualization |
97+
| `sendMessage(text)` | function | Send message to network |
98+
| `stopExecution()` | function | Stop streaming |
99+
| `clearHistory()` | function | Clear conversation |
100+
101+
## Features
102+
103+
- **Real-time streaming** with stop/cancel support
104+
- **Reasoning visualization** for chain-of-thought models
105+
- **Tool invocation display** showing agent tool calls
106+
- **Network selector** in both header and input
107+
- **Routing flow panel** showing agent execution steps
108+
- **Responsive layout** with collapsible sidebar on mobile

0 commit comments

Comments
 (0)