メインコンテンツへ移動

AgentNetwork から .network() へ移行する

@mastra/corev0.20.0 以降では、以下の変更が適用されます。

AI SDK v4 から v5 へアップグレードする
AI SDK v4 から v5 へアップグレードするへの直接リンク

  • すべてのモデル Provider パッケージをメジャーバージョンアップしてください。
注記

これにより、すべて v5 モデルになります。

Memory が必須に
Memory が必須にへの直接リンク

  • Agent Network を正しく動作させるには、Memory が必要になりました。
注記

Agent に Memory を設定する必要があります。

移行方法
移行方法への直接リンク

AgentNetwork プリミティブを使用していた場合は、AgentNetworkAgent に置き換えます。

変更前:

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 プリミティブを使用していた場合は、NewAgentNetworkAgent に置き換えます。

変更前:

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