docs/src/content/en/guides/migrations/agentnetwork.mdx
.network()As of v0.20.0 for @mastra/core, the following changes apply.
:::note
This will ensure that they're all v5 models now.
:::
:::note
You must configure memory for the agent.
:::
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.4',
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.4',
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.4',
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({
name: 'agent-network',
agents: { agent1, agent2 },
workflows: { workflow1 },
tools: { tool1, tool2 },
model: 'openai/gpt-5.4',
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.')