> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # 從 AgentNetwork 遷移至 `.network()` 由 `@mastra/core` 的 `v0.20.0` 起,以下變更適用。 ## 從 AI SDK v4 升級至 v5 - 將所有模型 Provider 套件提升一個主要版本。 > **備註:** 這可確保它們現在全都是 v5 模型。 ## 必須使用記憶體 - Agent 網絡現在必須使用記憶體才能正常運作。 > **備註:** 你必須為 Agent 設定記憶體。 ## 遷移路徑 如果你正在使用 `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.') ```