GraphAI - AgentFunctionInfoについて
AgentFunctionInfoについて
AgentをComputed Nodeから呼び出される関数で、単純に入力(inputsとparams)を受け取り結果を返します。Agentはnpmで配布されますがその関数のみではなく、Agentに関する情報を定義したAgentFunctionInfoとして提供されます。AgentFunctionInfoの1つの要素としてAgentの関数が含まれます。
AgentFunctionInfoには、Agent名、概要、必要な環境変数、サンプルデータ、スキーマなど様々な情報が含まれています。
特にスキーマとサンプルはとても重要です。
GraphAIではそれらの情報を使って
- AgentのUnit Test
- AgentのDocumentの自動生成
- Expressと組み合わせたときに、提供するAgentの情報をAPIとして提供
- AgentFilterと組み合わせて、Agentの入力値のValidation
などなど、様々な機能を自動化しています。
Test
@receptron/test_utils
にAgentFunctionInfoを使ったTest Runnerがあります。
import { agentTestRunner } from "@receptron/test_utils";
const main = async () => {
for await (const agentInfo of Object.values(packages)) {
await agentTestRunner(agentInfo);
}
};
samplesの各sampleのinputs/paramsを使ってAgentを実行し、結果とresultが一致するかテストします。
多くのAgentでこれを使って自動的にUnit testをしています。
GraphAIのレポジトリでは、各Agentで yarn run test
としてテストしています。
Document
Agentのスキーマと、サンプルデータ、それらを使ったGOD FormatのサンプルをmdのDocumentとして生成します。
生成されたDocumentはGithub上でまとめられます。
ドキュメントを作るツールはnpmパッケージとして提供されており、packageのnpm rootで
npx agentdoc
と、実行できます。
package.json
、および/lib/index
から情報を読み取ってdocumentを作成します。
agentdocのソースはこちら。
express
app.get(apiPrefix + "/", agentsList(agentDictionary, hostName, apiPrefix));
のように、agentDictionaryを渡すと、そのサーバで利用できるAgentの一覧、および、それぞれのAgentの情報を返します。
ソースはこちら。
この機能を使うと、他の環境のGraphAI(サーバ、ブラウザ)に対し、そのサーバが提供できるAgentの情報を渡すことができます。呼び出し元のGraphAIはその情報を使ってサーバ上のGraphAIをAPIとして呼び出すことができます。
AgentFilterによるValidation
inputSchema
の定義と実際の入力値を使ってagentのvalidatonができます。
ソースはこちら。
使い方はこちらを参考にしてください。GraphAIのモノレポでは、CIでこちらを実行して各Agentのsample値をチェックしています。
AgentFunctionInfoの定義
ソースはこちらにあります。
2025/3/20現在の型はこちら。
export type AgentFunctionInfoSample = {
inputs: any;
params: DefaultParamsType;
result: any;
graph?: GraphData;
};
export type AgentFunctionInfo = {
name: string;
agent: AgentFunction<any, any, any, any>;
mock: AgentFunction<any, any, any, any>;
inputs?: any; // inputs data schema
output?: any; // output data schema
params?: any; // params data schema
config?: any; // config data schema
outputFormat?: any;
tools?: Record<string, any>[]; // function calling(tools) schema.
samples: AgentFunctionInfoSample[]; // sample data. This is for document and unit test.
description: string;
category: string[];
author: string;
repository: string;
license: string;
cacheType?: CacheTypes;
environmentVariables?: string[]; // Environment variables required for execution
hasGraphData?: boolean; // The agent that executes graph data using nestedAgentGenerator is true
stream?: boolean; // is stream support?
apiKeys?: string[];
npms?: string[];
};
TODO: outputFormat, cacheType, tools, hasGraphDataなどを使っている部分をreferする。
開発時に
AgentFunctionInfoは便利なのですが、開発時にはまだ決まってないことも多いので、必ずしも事前にこれらの情報が用意できません。
agentを作るのは
無記名関数で実装する
const graphData = {
agent: ({namedInputs}) => {
}
}
関数だけ作って、ダミーのAgentFunctionInfoを入れるagentInfoWrapperを使う
const agent = ({namedInputs}) => {
...
};
Generatorを使ってスケルトンからAgentを作って、sampleを利用しunit testベースで仕上げる
などの方法を試してください。

人工知能を活用したアプリケーションやサービスを活用し、内発的動機付けで行動するエンジニア、起業家、社会起業家をサポートするコミュニティーです。 singularitysociety.org
Discussion