跳到主要内容

从 AgentNetwork 迁移到 .network()

@mastra/corev0.20.0 版本开始,以下变更生效。

从 AI SDK v4 升级到 v5
从 AI SDK v4 升级到 v5的直接链接

  • 将所有模型 Provider 包升级一个主版本。
备注

这样可以确保它们现在都是 v5 模型。

必须配置 Memory
必须配置 Memory的直接链接

  • Agent 网络现在必须有 Memory 才能正常运行。
备注

你必须为 Agent 配置 Memory。

迁移路径
迁移路径的直接链接

如果你之前使用 AgentNetwork 原语,可以用 Agent 替换 AgentNetwork

迁移前:

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.')

迁移后:

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.')

如果你之前使用 NewAgentNetwork 原语,可以用 Agent 替换 NewAgentNetwork

迁移前:

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.')

迁移后:

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.')