Skip to main content

从 AgentNetwork 迁移到 .network()

🌐 Migrate from AgentNetwork to .network()

截至 v0.20.0 对于 @mastra/core,适用以下更改。

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

从 AI SDK v4 升级到 v5
Direct link to 从 AI SDK v4 升级到 v5

🌐 Upgrade from AI SDK v4 to v5

  • 将你所有的模型提供商软件包升级一个主要版本。
note

这将确保它们现在都是v5型号。

🌐 This will ensure that they are all v5 models now.

需要内存
Direct link to 需要内存

🌐 Memory is required

  • 现在代理网络需要内存才能正常运行。
note

你必须为代理配置内存。

🌐 You must configure memory for the agent.

迁移路径
Direct link to 迁移路径

🌐 Migration paths

如果你使用的是 AgentNetwork 原语,你可以将 AgentNetwork 替换为 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.1",
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.1",
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 原语,你可以将 NewAgentNetwork 替换为 Agent

🌐 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.1",
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.1",
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.");