🤖

GraphAI GraphData(ワークフロー)をAgent化するnestedAgentGeneratorの紹介

2025/01/15に公開

GraphAIには、ワークフローを定義するGraphDataをagent内で実行するnestedAgentがあります。
nestedAgentはGraphData内に入れ子で定義されているサブグラフのGraphData(ワークフロー)を実行します。
このため、nestedAgentで使いたいGraphDataを再利用しようと思った場合には、TypeScript側で親GraphDataに子GraphDataを追加するなどの処理が必要で、必ずしも再利用が容易にできませんでした。

これを解決するためにnestedAgentをgeneratorとして再利用し、nestedAgentGeneratorを追加しました。
https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/graph_agents/nested_agent.ts

vanilla agentのnested_agentの一部として配置しています。
利用するにはvanilla agent (@graphai/vanilla)をインストールしインポートします

import { nestedAgentGenerator } from "@graphai/vanilla/lib/graph_agents/nested_agent";

これを使うとnestedAgentGeneratorGraphDataを渡すとそのグラフを実行するagentを作成することができます。
使い方は簡単で

const newAgent = nestedAgentGenerator(graphData);

とgraphDataを渡すだけです。

これでnewAgentは、graphDataを実行するagentとなります。
agentFunctionInfoを追加しパッケージ化すればnpmでagentとして配布も可能です。

const newAgentInfo = {
  name: "newAgent",
  agent: newAgent,
  mock: newAgent,
  samples: [],
  description: "",
  category: [],
  author: "",
  repository: "",
  tools: [],
  license: "",
};

export default newAgentInfo;

利用時にも1つポイントがあります。
現状、サブグラフをもつagentでないと、nestedAgentに必要な情報が渡らないのでダミーのサブグラフを親グラフに追加しておく必要があります。

    nestedGraphWorkFlow: {
      agent: "newAgent",
      inputs: {},
      graph: { version: 0, nodes: {} },
    },

Introduction to nestedAgentGenerator for Converting GraphAI GraphData (Workflows) into Agents

The nestedAgentGenerator in GraphAI allows you to easily convert GraphData (workflows) into executable agents. This enables flexible execution of nested subgraphs within workflows while improving reusability and simplifying the integration process.

Key features:

  • Efficiently handles workflows defined in GraphData.
  • Facilitates the reuse of nested subgraphs.
  • Enables seamless packaging and distribution via npm when combined with agentFunctionInfo.

GraphAI has a nestedAgent that executes GraphData within an agent to define workflows.
The nestedAgent executes subgraph GraphData (workflows) that are nested and defined within the main GraphData.

As a result, when you try to reuse GraphData for the nestedAgent, you need to process it on the TypeScript side, such as adding child GraphData to the parent GraphData. This means reuse is not always straightforward.

To address this issue, we have introduced nestedAgentGenerator, which allows the nestedAgent to be reused as a generator.
https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/graph_agents/nested_agent.ts

It is included as part of the nested_agent in the vanilla agent.
To use it, install and import the vanilla agent (@graphai/vanilla).

import { nestedAgentGenerator } from "@graphai/vanilla/lib/graph_agents/nested_agent";

By using this, you can create an agent that executes a graph by passing GraphData to the nestedAgentGenerator.

It's simple to use—just pass the following:

const newAgent = nestedAgentGenerator(graphData);

and graphData.

With this, newAgent becomes an agent that executes the provided graphData.

By adding agentFunctionInfo and packaging it, you can distribute it as an agent via npm.

const newAgentInfo = {
  name: "newAgent",
  agent: newAgent,
  mock: newAgent,
  samples: [],
  description: "",
  category: [],
  author: "",
  repository: "",
  tools: [],
  license: "",
};

export default newAgentInfo;

There is one important point to note when using it.

Currently, unless the agent contains a subgraph, the necessary information for the nestedAgent cannot be passed. Therefore, you need to add a dummy subgraph to the parent graph in advance.

    nestedGraphWorkFlow: {
      agent: "newAgent",
      inputs: {},
      graph: { version: 0, nodes: {} },
    },
シンギュラリティ・ソサエティ

Discussion