從 AgentNetwork 遷移至 .network()
自 @mastra/core 的 v0.20.0 起,適用下列變更。
從 AI SDK v4 升級至 v5「從 AI SDK v4 升級至 v5」的直接連結
- 將所有模型 Provider 套件升級一個主要版本。
備註
這可確保它們現在全都是 v5 模型。
必須使用 Memory「必須使用 Memory」的直接連結
- Agent network 現在必須使用 Memory 才能正常運作。
備註
你必須為 Agent 設定 Memory。
遷移路徑「遷移路徑」的直接連結
如果你原本使用 AgentNetwork 原始元件,可以將 AgentNetwork 替換成 Agent。
遷移前:
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 原始元件,可以將 NewAgentNetwork 替換成 Agent。
遷移前:
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.')