Agent クラス
Agent
クラスは、Mastra で AI エージェントを作成するための基盤となるクラスです。応答の生成、インタラクションのストリーミング、音声機能の扱いに関するメソッドを提供します。
使い方の例
src/mastra/agents/test-agent.ts
import { openai } from "@ai-sdk/openai";
import { Agent } from "@mastra/core/agent";
export const agent = new Agent({
name: "test-agent",
instructions: 'message for agent',
model: openai("gpt-4o")
});
コンストラクターのパラメータ
id?:
string
エージェントの任意の一意の識別子。指定しない場合は `name` が既定値になります。
name:
string
エージェントの一意の識別子。
description?:
string
エージェントの目的や機能に関する任意の説明。
instructions:
string | ({ runtimeContext: RuntimeContext }) => string | Promise<string>
エージェントの振る舞いを導くための指示。固定の文字列、または動的に文字列を返す関数を指定できます。
model:
MastraLanguageModel | ({ runtimeContext: RuntimeContext }) => MastraLanguageModel | Promise<MastraLanguageModel>
エージェントが使用する言語モデル。静的に提供することも、実行時に解決することもできます。
agents?:
Record<string, Agent> | ({ runtimeContext: RuntimeContext }) => Record<string, Agent> | Promise<Record<string, Agent>>
エージェントがアクセスできるサブエージェント。静的に提供することも、動的に解決することもできます。
tools?:
ToolsInput | ({ runtimeContext: RuntimeContext }) => ToolsInput | Promise<ToolsInput>
エージェントがアクセスできるツール。静的に提供することも、動的に解決することもできます。
workflows?:
Record<string, Workflow> | ({ runtimeContext: RuntimeContext }) => Record<string, Workflow> | Promise<Record<string, Workflow>>
エージェントが実行できるワークフロー。静的に指定することも、動的に解決することもできます。
defaultGenerateOptions?:
AgentGenerateOptions | ({ runtimeContext: RuntimeContext }) => AgentGenerateOptions | Promise<AgentGenerateOptions>
`generate()` 呼び出し時に使用される既定のオプション。
defaultStreamOptions?:
AgentStreamOptions | ({ runtimeContext: RuntimeContext }) => AgentStreamOptions | Promise<AgentStreamOptions>
`stream()` 呼び出し時に使用される既定のオプション。
defaultVNextStreamOptions?:
AgentExecutionOptions | ({ runtimeContext: RuntimeContext }) => AgentExecutionOptions | Promise<AgentExecutionOptions>
vNext モードで `stream()` を呼び出す際に使用される既定のオプション。
mastra?:
Mastra
Mastra ランタイム インスタンスへの参照(自動的に注入されます)。
scorers?:
MastraScorers | ({ runtimeContext: RuntimeContext }) => MastraScorers | Promise<MastraScorers>
実行時評価とテレメトリのためのスコアリング設定。静的または動的に提供できます。
evals?:
Record<string, Metric>
エージェントの応答を採点するための評価指標。
memory?:
MastraMemory | ({ runtimeContext: RuntimeContext }) => MastraMemory | Promise<MastraMemory>
状態付きコンテキストの保存および取得に使用されるメモリ モジュール。
voice?:
CompositeVoice
音声入出力の設定。
inputProcessors?:
Processor[] | ({ runtimeContext: RuntimeContext }) => Processor[] | Promise<Processor[]>
エージェントで処理される前にメッセージを変更または検証する入力プロセッサ。`processInput` 関数を実装する必要があります。
outputProcessors?:
Processor[] | ({ runtimeContext: RuntimeContext }) => Processor[] | Promise<Processor[]>
クライアントに送信する前にエージェントからのメッセージを変更または検証する出力プロセッサ。`processOutputResult` と/または `processOutputStream` 関数を実装する必要があります。
戻り値
agent:
Agent<TAgentId, TTools, TMetrics>
指定された構成の新しい Agent インスタンス。