再帰のマルチエージェントテンプレート

中級

これはAI, Marketing分野の自動化ワークフローで、11個のノードを含みます。主にIf, Set, Code, Agent, ChatTriggerなどのノードを使用、AI技術を活用したスマート自動化を実現。 GPT-4o再帰のライティング&エディットエージェントを使って書面コンテンツを生成

前提条件
  • OpenAI API Key
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "id": "UnFtEvTPouN6XIIH",
  "meta": {
    "instanceId": "ea11c547d31842d8c1ffb2f9490761ea576cf90dbdb1ce86a951bf99131d1a44",
    "templateCredsSetupCompleted": true
  },
  "name": "Recursive Multi-Agent TEMPLATE",
  "tags": [],
  "nodes": [
    {
      "id": "84b115d5-0c47-4bc9-8997-e45c16e3aa18",
      "name": "チャットメッセージ受信時",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        40,
        0
      ],
      "webhookId": "037b5b5d-7a59-4812-8327-42f9c7812d5d",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "085fd153-5564-4920-b278-e5fc93f32134",
      "name": "ウィンドウバッファメモリ",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        920,
        280
      ],
      "parameters": {
        "sessionKey": "={{ $('When chat message received').item.json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "0220fe2a-8e8e-4d11-803e-b942f1cf16c5",
      "name": "set variables",
      "type": "n8n-nodes-base.set",
      "position": [
        1380,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "25fcda79-c515-4e2e-bfc0-3b13259c33a0",
              "name": "status",
              "type": "string",
              "value": "={{ $json.output.status }}"
            },
            {
              "id": "26f212df-ed09-4372-ad2f-e069698ab33c",
              "name": "edits",
              "type": "string",
              "value": "={{ $json.output.edits }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0dc0e194-4129-42e3-aedd-6fbd6b875338",
      "name": "chatInput",
      "type": "n8n-nodes-base.set",
      "position": [
        260,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "709fb115-0654-48f6-bbdd-d0661b1135ba",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $json.chatInput }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "426831d6-2ddb-4ede-99a7-c0c504e6687f",
      "name": "構造化出力パーサー",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1200,
        280
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"status\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"edits\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "4be8a98c-c01f-4e8c-bec7-c6ef4119c392",
      "name": "OpenAI チャットモデル",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        680,
        280
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "93qOKf12nDGJSW30",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "b22dd35c-5df2-4966-a7b6-4b146c5d9a09",
      "name": "handle edits",
      "type": "n8n-nodes-base.code",
      "position": [
        460,
        0
      ],
      "parameters": {
        "jsCode": "let edits = \"\";\ntry {\n\t// Try to retrieve the edits from the node named \"Edit Fields\"\n\tedits =  $node[\"set variables\"].json[\"edits\"] || \"\";\n} catch (err) {\n\t// If the node hasn't executed or its data isn't available, default to empty string\n\tedits = \"\";\n}\nreturn { edits };"
      },
      "typeVersion": 2
    },
    {
      "id": "85524870-798a-4561-a227-06c8f0aa3c26",
      "name": "If Status Complete",
      "type": "n8n-nodes-base.if",
      "position": [
        1600,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d2c4ff3a-1674-4edf-b0a0-153543f52900",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Editing Agent').item.json.output.status }}",
              "rightValue": "complete"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e28c4317-1e16-445f-8119-7d53937b651b",
      "name": "Writing エージェント",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        660,
        0
      ],
      "parameters": {
        "text": "=Always review chat history.\n\nWrite a blurb based on my input topic:\n{{ $('chatInput').item.json.chatInput }}\n\nIf there are any suggested edits, make sure to incorporated them into the blurb:\n{{ $json.edits }}\n\nONLY OUTPUT THE BLURB, NO ADDITIONAL WORDS. ",
        "options": {
          "systemMessage": "=You are a writer. Write a short blurb about the topic given to you by the user. "
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "fe9d9f32-8be3-49a7-8699-322192e16474",
      "name": "Editing エージェント",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "maxTries": 5,
      "position": [
        1020,
        0
      ],
      "parameters": {
        "text": "=You are an editor. \n\nReview the input and recommend specific edits to improve the writing. \n\nYou are working with a writing agent that should implement your edits. \n\nHere are the variables that you output and what they mean:\n- status: this is either \"complete\" or \"incomplete\" output string. Once the writing agent implements your edits, you should set \"status\" = \"complete\". If this is the first time you've reviewed their work, status should be set to \"incomplete\". If the writing agent did not correctly implement your edits, you should set status to \"incomplete\".\n- edits: this is your specific suggested edits. The writing agent will be able to see these edits and update the text to incorporate the edits.\n\nUse the structured output parser and output clean JSON in this format (example):\n{\n\"status\": \"complete\",\n\"edits\": \"The writing agent has successfully implemented all the suggested edits. The text is now concise, informative, and focused on the main point while providing a brief introduction to AI. No further edits are necessary at this time.\"\n}\n\nDO NOT INCLUDE ANY OTHER TEXT BESIDES THE JSON OUTPUT.\n\nHere is the input text from the writing agent:\n{{ $json.output }}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "retryOnFail": false,
      "typeVersion": 1.7
    },
    {
      "id": "e77541dd-0774-4545-a846-0106aa79fbf5",
      "name": "chatOutput",
      "type": "n8n-nodes-base.set",
      "position": [
        1820,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "753c404e-fce4-4173-95d2-6fde9c543d5f",
              "name": "output",
              "type": "string",
              "value": "={{ $('Writing Agent').first().json.output }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "549707c8-55db-4e8e-aecc-68615b6034ee",
      "name": "付箋",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        600,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 340,
        "height": 320,
        "content": "## Writing Agent\nThis agent writes and rewrites based on feedback from the editing agent."
      },
      "typeVersion": 1
    },
    {
      "id": "67c3ebb8-6d81-4add-a882-07fd0cc86f50",
      "name": "付箋1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        980,
        -160
      ],
      "parameters": {
        "color": 5,
        "width": 340,
        "height": 320,
        "content": "## Editing Agent\nThis agent suggest edits to improve the writing output of the writing agent. It then evaluates whether the edits were incorporated into the writing."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8b9969b0-ae7b-45c0-9f41-72ea972d67cb",
  "connections": {
    "0dc0e194-4129-42e3-aedd-6fbd6b875338": {
      "main": [
        [
          {
            "node": "b22dd35c-5df2-4966-a7b6-4b146c5d9a09",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "b22dd35c-5df2-4966-a7b6-4b146c5d9a09": {
      "main": [
        [
          {
            "node": "Writing Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Editing Agent": {
      "main": [
        [
          {
            "node": "0220fe2a-8e8e-4d11-803e-b942f1cf16c5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Writing Agent": {
      "main": [
        [
          {
            "node": "Editing Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "0220fe2a-8e8e-4d11-803e-b942f1cf16c5": {
      "main": [
        [
          {
            "node": "85524870-798a-4561-a227-06c8f0aa3c26",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Writing Agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Editing Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "85524870-798a-4561-a227-06c8f0aa3c26": {
      "main": [
        [
          {
            "node": "e77541dd-0774-4545-a846-0106aa79fbf5",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "b22dd35c-5df2-4966-a7b6-4b146c5d9a09",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "Editing Agent",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "Writing Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Editing Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "0dc0e194-4129-42e3-aedd-6fbd6b875338",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

このワークフローの使い方は?

上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。

このワークフローはどんな場面に適していますか?

中級 - 人工知能, マーケティング

有料ですか?

このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。

ワークフロー情報
難易度
中級
ノード数11
カテゴリー2
ノードタイプ8
難易度説明

経験者向け、6-15ノードの中程度の複雑さのワークフロー

作成者
Matty Reed

Matty Reed

@mattyreed1

Student and Teacher | Designer and Builder | Helping Founders Flourish

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34