跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Migrate from AgentNetwork to .network()

As of v0.20.0 for @mastra/core, the following changes apply.

Upgrade from AI SDK v4 to v5
Upgrade from AI SDK v4 to v5的直接链接

  • Bump all your model provider packages by a major version.
备注

This will ensure that they're all v5 models now.

Memory is required
Memory is required的直接链接

  • Memory is now required for the agent network to function properly.
备注

You must configure memory for the agent.

Migration paths
Migration paths的直接链接

If you were using the AgentNetwork primitive, you can replace the AgentNetwork with Agent.

Before:

import { AgentNetwork } from '@mastra/core/network'

const agent = new AgentNetwork({
name: 'agent-network',
agents: [agent1, agent2],
tools: { tool1, tool2 },
model: 'openai/gpt-5.6-sol',
instructions: 'You are a network agent that can help users with a variety of tasks.',
})

await agent.stream('Find me the weather in Tokyo.')

After:

import { Agent } from '@mastra/core/agent'
import { Memory } from '@mastra/memory'

const memory = new Memory()

const agent = new Agent({
id: 'agent-network',
name: 'agent-network',
agents: { agent1, agent2 },
tools: { tool1, tool2 },
model: 'openai/gpt-5.6-sol',
instructions: 'You are a network agent that can help users with a variety of tasks.',
memory,
})

await agent.network('Find me the weather in Tokyo.')

If you were using the NewAgentNetwork primitive, you can replace the NewAgentNetwork with Agent.

Before:

import { NewAgentNetwork } from '@mastra/core/network/vnext'

const agent = new NewAgentNetwork({
id: 'agent-network',
name: 'agent-network',
agents: { agent1, agent2 },
workflows: { workflow1 },
tools: { tool1, tool2 },
model: 'openai/gpt-5.6-sol',
instructions: 'You are a network agent that can help users with a variety of tasks.',
})

await agent.loop('Find me the weather in Tokyo.')

After:

import { Agent } from '@mastra/core/agent'
import { Memory } from '@mastra/memory'

const memory = new Memory()

const agent = new Agent({
id: 'agent-network',
name: 'agent-network',
agents: { agent1, agent2 },
workflows: { workflow1 },
tools: { tool1, tool2 },
model: 'openai/gpt-5.6-sol',
instructions: 'You are a network agent that can help users with a variety of tasks.',
memory,
})

await agent.network('Find me the weather in Tokyo.')