0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WIP:GraphAIのAgent一覧と簡単な使用例まとめ

Last updated at Posted at 2024-11-28

はじめに

本記事は一部未完成となっており、
サンプルの設定ファイルと実行結果については検証でき次第更新していきます。

GraphAIは、LLM/RAG/Tools/DBなどの複数のAgentを組み合わせて作る、Multi agentsシステムを効率よく構築するためのフレームワークです。詳細については以下をご覧ください。

[GraphAIについて](https://zenn.dev/singularity/articles/graphai-about)

GraphAIの主要なAgent一覧

次に、GraphAIで利用できる代表的なAgentのリストを示し、それぞれの概要を説明します。

input

textInputAgent

テキスト入力を提供するAgent

例)

$cat text_input.yaml

実行結果)

data

dataObjectMergeTemplateAgent

データオブジェクトをマージするテンプレートを提供するAgent

例)

$ cat merge_template.yaml
version: 0.5
nodes:
  object1:
    value:
      a: 1
      b: 2
  object2:
    value:
      b: 3
      c: 4
  mergedObject:
    agent: dataObjectMergeTemplateAgent
    inputs:
      array:
        - :object1
        - :object2
    isResult: true

実行結果)

$ graphai merge_template.yaml
{
  "mergedObject": {
    "a": 1,
    "b": 3,
    "c": 4
  }
}

copyAgent

データのコピーを行うAgent

例)

$ cat copy_data.yaml
version: 0.5
nodes:
  source:
    value:
      message: "Hello, GraphAI!"
      count: 42
  copied:
    agent: copyAgent
    inputs:
      data: :source 
    isResult: true

実行結果)

$ graphai copy_data.yaml
{
  "copied": {
    "data": {
      "message": "Hello, GraphAI!",
      "count": 42
    }
  }
}

dataSumTemplateAgent

データの合計を計算するテンプレートを提供するAgent

例)

$ cat sum_data.yaml
version: 0.5
nodes:
  # 数値の配列を定義するノード
  numbers:
    value: [1, 4, 7]
  
  # dataSumTemplateAgent を使用するノード
  sum:
    agent: dataSumTemplateAgent
    inputs:
      # 入力として使用する配列を指定
      array: :numbers 
    # 結果ノードとしてマーク
    isResult: true

実行結果)

$ graphai sum_data.yaml
{
  "sum": 12
}

propertyFilterAgent

データプロパティのフィルタリングを行うAgent

例)

$ cat filter_property.yaml
version: 0.5
nodes:
  # 入力データを定義するノード
  input_data:
    value:
      -
        color: red
        model: Model 3
        type: EV
        maker: Tesla
        range: 300
      -
        color: blue
        model: Model Y
        type: EV
        maker: Tesla
        range: 400

  # propertyFilterAgent を使用するノード (例1: 特定のプロパティを含める)
  filtered_data_include:
    agent: propertyFilterAgent
    inputs:
      array: :input_data
    params:
      include:
        - color
        - model
    isResult: true

  # propertyFilterAgent を使用するノード (例2: 特定のプロパティを除外する)
  filtered_data_exclude:
    agent: propertyFilterAgent
    inputs:
      array: :input_data
    params:
      exclude:
        - color
        - model
    isResult: true

  # propertyFilterAgent を使用するノード (例3: プロパティの値を変更する)
  filtered_data_alter:
    agent: propertyFilterAgent
    inputs:
      array: :input_data
    params:
      alter:
        color:
          red: blue
          blue: red
    isResult: true

  # propertyFilterAgent を使用するノード (例4: 新しいプロパティを追加する)
  filtered_data_inject:
    agent: propertyFilterAgent
    inputs:
      array: :input_data
    params:
      inject:
        - propId: new_property
          value: new_value
    isResult: true

  # propertyFilterAgent を使用するノード (例5: プロパティの名前を入れ替える)
  filtered_data_swap:
    agent: propertyFilterAgent
    inputs:
      array: :input_data
    params:
      swap:
        maker: model
    isResult: true

実行結果)

$ graphai filter_property.yaml
{
  "filtered_data_include": {
    "color": "red",
    "model": "Model 3"
  },
  "filtered_data_exclude": {
    "type": "EV",
    "maker": "Tesla",
    "range": 300
  },
  "filtered_data_alter": {
    "color": "blue",
    "model": "Model 3",
    "type": "EV",
    "maker": "Tesla",
    "range": 300
  },
  "filtered_data_inject": {
    "color": "red",
    "model": "Model 3",
    "type": "EV",
    "maker": "Tesla",
    "range": 300
  },
  "filtered_data_swap": {
    "color": "red",
    "model": "Tesla",
    "type": "EV",
    "maker": "Model 3",
    "range": 300
  }
}

totalAgent

データ全体の合計を計算するAgent

例)

$ cat total_data.yaml

version: 1.0

nodes:
  node1:
    params:
      numbers: [5, 10, 15]
    agent: totalAgent
    isResult: true

実行結果)

$ graphai total_data.yaml
{
  "node1": {
    "total": 30
  }
}

llm

anthropicAgent

Anthropic社の言語モデルを利用するAgent

例)

$ cat anthropic_input.yaml

実行結果)

$ graphai anthropic_input.yaml

geminiAgent

Gemini言語モデルを利用するAgent

例)

$ cat gemini_input.yaml

実行結果)

$ graphai gemini_input.yaml

groqAgent

Groqを利用した言語モデルのAgent

例)

$ cat groq_input.yaml

実行結果)

$ graphai groq_input.yaml

openAIAgent

OpenAIの言語モデルを利用するAgent

例)

$ cat openai_input.yaml

実行結果)

$ graphai openai_input.yaml

openAIImageAgent

OpenAIの画像生成モデルを利用するAgent

例)

$ cat openai_image_input.yaml

実行結果)

$ graphai openai_image_input.yaml

replicateAgent

Replicateのモデルを利用するAgent

例)

$ cat replicate_input.yaml

実行結果)

$ graphai replicate_input.yaml

slashGPTAgent

SlashGPTを利用するAgent

例)

$ cat slashgpt_input.yaml

実行結果)

$ graphai slashgpt_input.yaml

service

fetchAgent

外部データの取得を行うAgent

例)

$ cat fetch_data.yaml

実行結果)

$ graphai fetch_data.yaml

wikipediaAgent

Wikipediaから情報を取得するAgent

例)

$ cat wikipedia_input.yaml
version: 0.5
nodes:
  steve_jobs:
    agent: wikipediaAgent
    inputs:
      query: "Steve Jobs"
    params:
      lang: "ja" 
      summary: true 
    isResult: true

実行結果)

$ graphai wikipedia_input.yaml
{
  "steve_jobs": {
    "content": {
      "type": "standard",
      "title": "スティーブ・ジョブズ",
      "displaytitle": "<span class=\"mw-page-title-main\">スティーブ・ジョブズ</span>",
      "namespace": {
        "id": 0,
        "text": ""
      },
      "wikibase_item": "Q19837",
      "titles": {
        "canonical": "スティーブ・ジョブズ",
        "normalized": "スティーブ・ジョブズ",
        "display": "<span class=\"mw-page-title-main\">スティーブ・ジョブズ</span>"
      },
      "pageid": 43967,
      "thumbnail": {
        "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dc/Steve_Jobs_Headshot_2010-CROP_%28cropped_2%29.jpg/320px-Steve_Jobs_Headshot_2010-CROP_%28cropped_2%29.jpg",
        "width": 320,
        "height": 310
      },
      "originalimage": {
        "source": "https://upload.wikimedia.org/wikipedia/commons/d/dc/Steve_Jobs_Headshot_2010-CROP_%28cropped_2%29.jpg",
        "width": 3026,
        "height": 2929
      },
      "lang": "ja",
      "dir": "ltr",
      "revision": "102550973",
      "tid": "02b35b4d-a17f-11ef-bcec-a311283e2de0",
      "timestamp": "2024-11-13T05:20:35Z",
      "description": "アメリカの実業家 (1955-2011)",
      "description_source": "central",
      "content_urls": {
        "desktop": {
          "page": "https://ja.wikipedia.org/wiki/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA",
          "revisions": "https://ja.wikipedia.org/wiki/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA?action=history",
          "edit": "https://ja.wikipedia.org/wiki/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA?action=edit",
          "talk": "https://ja.wikipedia.org/wiki/%E3%83%8E%E3%83%BC%E3%83%88:%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA"
        },
        "mobile": {
          "page": "https://ja.m.wikipedia.org/wiki/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA",
          "revisions": "https://ja.m.wikipedia.org/wiki/Special:History/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA",
          "edit": "https://ja.m.wikipedia.org/wiki/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA?action=edit",
          "talk": "https://ja.m.wikipedia.org/wiki/%E3%83%8E%E3%83%BC%E3%83%88:%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA"
        }
      },
      "extract": "スティーブ・ジョブズ 、本名スティーブン・ポール・ジョブズ は、アメリカ合衆国の起業家、実業家、工業デザイナー。アメリカ国家技術賞、大統領自由勲章を受賞している。",
      "extract_html": "<p><b>スティーブ・ジョブズ</b> 、本名<b>スティーブン・ポール・ジョブズ</b> は、アメリカ合衆国の起業家、実業家、工業デザイナー。アメリカ国家技術賞、大統領自由勲章を受賞している。</p>"
    },
    "ns": 0,
    "title": "スティーブ・ジョブズ",
    "pageid": 43967
  }
}

vanillaFetchAgent

シンプルなフェッチ操作を行うAgent

例)

$ cat vanilla_fetch.yaml

version: 1.0

nodes:
  node1:
    params:
      endpoint: "https://api.example.com/simple"
    agent: vanillaFetchAgent
    isResult: true

実行結果)

$ graphai vanilla_fetch.yaml
{
  "node1": {
    "data": {
      "info": "simple response"
    }
  }
}

sleeper

sleepAndMergeAgent

一定時間待機してからデータをマージするAgent

例)

$ cat sleep_and_merge.yaml

実行結果)

$ graphai sleep_and_merge.yaml

sleeperAgentDebug

デバッグ用のスリープAgent

例)

$ cat sleeper_debug.yaml

実行結果)

$ graphai sleeper_debug.yaml

sleeperAgent

指定時間待機するAgent

例)

$ cat sleeper.yaml

実行結果)

$ graphai sleeper.yaml

array

arrayFlatAgent

配列をフラット化するAgent

例)

$ cat array_flat.yaml

実行結果)

$ graphai array_flat.yaml

arrayJoinAgent

配列内の要素を結合するAgent

例)

$ cat array_join.yaml

実行結果)

$ graphai array_join.yaml

popAgent

配列の最後の要素を取り出すAgent

例)

$ cat array_pop.yaml

実行結果)

$ graphai array_pop.yaml

pushAgent

配列に要素を追加するAgent

例)

$ cat array_push.yaml

実行結果)

$ graphai array_push.yaml

shiftAgent

配列の最初の要素を取り出すAgent

例)

$ cat array_shift.yaml

実行結果)

$ graphai array_shift.yaml

compare

compareAgent

データの比較を行うAgent

例)

$ cat compare_data.yaml

実行結果)

$ graphai compare_data.yaml

test

echoAgent

入力データをそのまま出力するテスト用Agent

例)

$ cat echo.yaml

実行結果)

$ graphai echo.yaml

copy2ArrayAgent

データを配列にコピーするテスト用Agent

例)

$ cat copy_to_array.yaml

実行結果)

$ graphai copy_to_array.yaml

copyMessageAgent

メッセージをコピーするテスト用Agent

例)

$ cat copy_message.yaml

実行結果)

$ graphai copy_message.yaml

### countingAgent

例)

$ cat counting.yaml

実行結果)

$ graphai counting.yaml
{
  "node1": {
    "count": [1, 2, 3, 4, 5]
  }
}

echoAgent

入力データをそのまま出力するテスト用Agent

例)

$ cat echo.yaml

実行結果)

$ graphai echo.yaml

例)

$ cat counting.yaml

実行結果)

$ graphai counting.yaml

mergeNodeIdAgent

ノードIDをマージするテスト用Agent

例)

$ cat merge_node_id.yaml

実行結果)

$ graphai merge_node_id.yaml

streamMockAgent

ストリーム操作を模倣するテスト用Agent

例)

$ cat stream_mock.yaml

実行結果)

$ graphai stream_mock.yaml

matrix

dotProductAgent

行列のドット積を計算するAgent

例)

$ cat dot_product.yaml

実行結果)

$ graphai dot_product.yaml

sortByValuesAgent

値に基づいて行列をソートするAgent

例)

$ cat sort_values.yaml

実行結果)

$ graphai sort_values.yaml

string

jsonParserAgent

JSON文字列をパースするAgent

例)

$ cat json_parser.yaml

実行結果)

$ graphai json_parser.yaml

stringSplitterAgent

文字列を分割するAgent

例)

$ cat string_split.yaml

実行結果)

$ graphai string_split.yaml
{
  "node1": {
    "splitStrings": ["apple", "banana", "cherry"]
  }
}

stringTemplateAgent

文字列テンプレートを生成するAgent

例)

$ cat string_template.yaml

実行結果)

$ graphai string_template.yaml

graph

mapAgent

グラフ上のノードをマップするAgent

例)

$ cat map_agent.yaml
version: 0.5
nodes:
 source:
   value:
     fruits:
       - apple
       - orange
       - banana
       - lemon
       - melon
       - pineapple
       - tomato
 nestedNode:
   agent: mapAgent
   inputs:
     rows: :source.fruits
   graph:
     version: 0.5
     nodes:
       node2:
         agent: stringTemplateAgent
         params:
           template: I love ${m}.
         inputs:
           m: :row
         isResult: true
   params:
     compositeResult: true
 result:
   agent: sleepAndMergeAgent
   inputs:
     array:
       - :nestedNode.node2
   isResult: true

実行結果)

$ graphai map_agent.yaml
{
  "node1": {
    "mappedGraph": {
      "nodes": ["A", "B", "C"],
      "edges": [["A", "B"], ["B", "C"]]
    }
  }
}

nestedAgent

ネストされたグラフ構造を処理するAgent

例)

$ cat nested_agent.yaml

実行結果)

embedding

stringEmbeddingsAgent

文字列をベクトル埋め込みに変換するAgent。
OPENAI_API_KEYを設定する必要あります。

例)

$ cat string_embedding.yaml
version: 0.5
nodes:
  text:
    value: "こんにちは世界"
  embeddings:
    agent: stringEmbeddingsAgent
    inputs:
      item: :text
  output:
    agent: echoAgent
    inputs:
      text: :embeddings.embedding

実行結果)

$ graphai string_embedding.yaml
{
  "node1": {
    "embedding": [0.1, 0.2, 0.3, ...]
  }
}

参考リンク

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?