> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # 从 AgentNetwork 迁移到 `.network()` 从 `@mastra/core` 的 `v0.20.0` 版本开始,以下变更生效。 ## 从 AI SDK v4 升级到 v5 - 将所有模型 Provider 包升级一个主版本。 > **备注:** 这样可以确保它们现在都是 v5 模型。 ## 必须配置 Memory - Agent 网络现在必须有 Memory 才能正常运行。 > **备注:** 你必须为 Agent 配置 Memory。 ## 迁移路径 如果你之前使用 `AgentNetwork` 原语,可以用 `Agent` 替换 `AgentNetwork`。 迁移前: ```typescript 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.') ``` 迁移后: ```typescript 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`。 迁移前: ```typescript 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.') ``` 迁移后: ```typescript 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.') ```