DifyとローカルLLMを使用して複数のエージェントを設定して議論する方法

LLM

この記事では、DifyとOllamaを使用してローカルLLMを構築し、複数のLLMエージェントを設定してAIが社会に与える影響について議論を行い、その結果を記事として生成する手順について説明します。

前提条件

  • Ollamaをローカル環境で起動しておく必要があります。起動方法については、こちらを参照してください。
Download Ollama on Windows
Download Ollama on Windows
Ollama モデルファイル
注意: Modelfile の構文は開発中です。モデルファイルは、Ollamaでモデルを作成・共有するための設計図です。おススメ記事フォーマットModelfile のフォーマット:# コメントINSTRUCTION 引数インストラクション説...

モデルプロバイダーの追加

モデルタイプを選択:

file

  • 「ollama」を選択します。

必要な情報を入力:

file

  • モデル名: llm-jp-13b-v2

  • Base URL: http://host.docker.internal:11434

  • Completion Mode: 「Chat」

  • モデルコンテキストサイズ: 4096

  • 最大トークン数の上限: 4096

  • Vision Support: 「No」を選択

ワークフローの作成

4人のエージェントのシステムプロンプトを設定:

file

  • 楽観的AI研究者、慎重派経済学者、AIジャーナリスト、倫理学者の4人のエージェントを作成します。

  • それぞれのシステムメッセージに、エージェントの立場と視点を反映した内容を設定します。例えば、楽観的AI研究者のシステムメッセージは以下のようになります。


あなたは楽観的なAI研究者です。以下のインプットに対して、AIの可能性を信じ、社会へのポジティブな影響を強調しながら答えてください。

{input}

AI研究者:

ユーザー入力とシステムレスポンスの設定:

file

  • ユーザーが議論するテーマ(例: 人工知能は人間の仕事を奪うのか)が入力されるようにします。

  • 各エージェントの応答プロンプトには、インプットと前のエージェントの意見を考慮するよう指示します。

ブロックの接続

各エージェントのブロックを作成:

  • ブロックを設定し、各エージェントの出力を生成するブロックを記述します。

file

表示ブロックを作成:

  • 各エージェントの出力を表示するブロックを設定します。

file

ブロックを連結:

  • 議論の流れに沿って、各エージェントのブロックと表示ブロックを順番に連結します。

file

完成

これで、ローカルLLMを使用して複数のエージェントがAIについて議論を行い、その結果を出力にする設定が完了しました。この設定を実行すると、各エージェントが入力に基づいて順番に応答し、多角的な議論が展開されます。

ただし、事前にOllamaをローカル環境で起動しておく必要がありますので、ご留意ください。

DSLファイル


app:
  description: ''
  icon: snowman_without_snow
  icon_background: '#D3F8DF'
  mode: advanced-chat
  name: Multi-Perspective AI Debate
workflow:
  features:
    file_upload:
      image:
        enabled: false
        number_limits: 3
        transfer_methods:
        - local_file
        - remote_url
    opening_statement: ''
    retriever_resource:
      enabled: false
    sensitive_word_avoidance:
      enabled: false
    speech_to_text:
      enabled: false
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
      language: ''
      voice: ''
  graph:
    edges:
    - data:
        sourceType: start
        targetType: llm
      id: 1711527768326-1711527784865
      source: '1711527768326'
      sourceHandle: source
      target: '1711527784865'
      targetHandle: target
      type: custom
    - data:
        sourceType: answer
        targetType: llm
      id: 1716775953161-1716775619258
      source: '1716775953161'
      sourceHandle: source
      target: '1716775619258'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1711527784865-1716776291546
      source: '1711527784865'
      sourceHandle: source
      target: '1716776291546'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716776291546-1716776255897
      source: '1716776291546'
      sourceHandle: source
      target: '1716776255897'
      targetHandle: target
      type: custom
    - data:
        sourceType: answer
        targetType: llm
      id: 1716776255897-1711527861837
      source: '1716776255897'
      sourceHandle: source
      target: '1711527861837'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1711527861837-1716776460437
      source: '1711527861837'
      sourceHandle: source
      target: '1716776460437'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716776460437-1716775953161
      source: '1716776460437'
      sourceHandle: source
      target: '1716775953161'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1716775619258-1716776501998
      source: '1716775619258'
      sourceHandle: source
      target: '1716776501998'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716776501998-1711527970616
      source: '1716776501998'
      sourceHandle: source
      target: '1711527970616'
      targetHandle: target
      type: custom
    - data:
        sourceType: answer
        targetType: llm
      id: 1711527970616-1716777781638
      source: '1711527970616'
      sourceHandle: source
      target: '1716777781638'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1716777781638-1716777823449
      source: '1716777781638'
      sourceHandle: source
      target: '1716777823449'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716777823449-1716777828148
      source: '1716777823449'
      sourceHandle: source
      target: '1716777828148'
      targetHandle: target
      type: custom
    nodes:
    - data:
        desc: ''
        selected: false
        title: Start
        type: start
        variables: []
      dragging: false
      height: 54
      id: '1711527768326'
      position:
        x: 80
        y: 282
      positionAbsolute:
        x: 80
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "# \u8B70\u8AD6\u3059\u308B\u30C6\u30FC\u30DE\n{{#sys.query#}}\n\
            \n\u697D\u89B3\u7684AI\u7814\u7A76\u8005:"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 4096
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: llm-jp-13b-v2
          provider: ollama
        prompt_template:
        - id: 6c4a2969-ff55-4a63-8711-9920b0bcf807
          role: system
          text: "\u3042\u306A\u305F\u306F\u697D\u89B3\u7684\u306AAI\u7814\u7A76\u8005\
            \u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\u30C3\u30C8\u306B\
            \u5BFE\u3057\u3066\u3001AI\u306E\u53EF\u80FD\u6027\u3092\u4FE1\u3058\u3001\
            \u793E\u4F1A\u3078\u306E\u30DD\u30B8\u30C6\u30A3\u30D6\u306A\u5F71\u97FF\
            \u3092\u5F37\u8ABF\u3057\u306A\u304C\u3089\u7B54\u3048\u3066\u304F\u3060\
            \u3055\u3044\u3002\n\n\n"
        selected: false
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u8005"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      dragging: false
      height: 98
      id: '1711527784865'
      position:
        x: 364
        y: 282
      positionAbsolute:
        x: 364
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "# \u8B70\u8AD6\u3059\u308B\u30C6\u30FC\u30DE\n{{#sys.query#}}\n\
            {{#1716776291546.output#}}\n\n\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005\
            :"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 512
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: llm-jp-13b-v2
          provider: ollama
        prompt_template:
        - id: 17774cf5-0f56-4814-885b-347ea826cb02
          role: system
          text: "\u3042\u306A\u305F\u306F\u614E\u91CD\u6D3E\u306E\u7D4C\u6E08\u5B66\
            \u8005\u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\u30C3\u30C8\
            \u306B\u5BFE\u3057\u3066\u3001\u6280\u8853\u9769\u65B0\u304C\u52B4\u50CD\
            \u5E02\u5834\u306B\u4E0E\u3048\u308B\u5F71\u97FF\u306B\u3064\u3044\u3066\
            \u614E\u91CD\u306A\u898B\u65B9\u3092\u793A\u3057\u306A\u304C\u3089\u3001\
            1\u4EBA\u76EE\u306E\u610F\u898B\u306B\u53CD\u8AD6\u3057\u3066\u304F\u3060\
            \u3055\u3044\u3002\n\n"
        selected: true
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      height: 98
      id: '1711527861837'
      position:
        x: 669.0937298845706
        y: 282
      positionAbsolute:
        x: 669.0937298845706
        y: 282
      selected: true
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716776501998.output#}}'
        desc: ''
        selected: false
        title: "AI\u30B8\u30E3\u30FC\u30CA\u30EA\u30B9\u30C8_Disp"
        type: answer
        variables:
        - value_selector:
          - '1711527888920'
          - output
          variable: output
      height: 106
      id: '1711527970616'
      position:
        x: 949.0710669287596
        y: 453.4984609693367
      positionAbsolute:
        x: 949.0710669287596
        y: 453.4984609693367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "# \u8B70\u8AD6\u3059\u308B\u30C6\u30FC\u30DE\n{{#sys.query#}}\n\
            {{#1716776460437.output#}}\n\n\nAI\u30B8\u30E3\u30FC\u30CA\u30EA\u30B9\
            \u30C8:"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 512
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: llm-jp-13b-v2
          provider: ollama
        prompt_template:
        - id: 17774cf5-0f56-4814-885b-347ea826cb02
          role: system
          text: "\u3042\u306A\u305F\u306FAI\u306E\u52D5\u5411\u306B\u3064\u3044\u3066\
            \u5BA2\u89B3\u7684\u306B\u5831\u9053\u3059\u308B\u30B8\u30E3\u30FC\u30CA\
            \u30EA\u30B9\u30C8\u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\
            \u30C3\u30C8\u3068\u3001\u3053\u308C\u307E\u3067\u306E\u8B70\u8AD6\u3092\
            \u8E0F\u307E\u3048\u3066\u3001\u793E\u4F1A\u3078\u306E\u5F71\u97FF\u306B\
            \u3064\u3044\u3066\u51B7\u9759\u306B\u5206\u6790\u3057\u3001\u6D77\u5916\
            \u306E\u4E8B\u4F8B\u306A\u3069\u3082\u4EA4\u3048\u3066\u8AD6\u3058\u3066\
            \u304F\u3060\u3055\u3044\u3002\n\n"
        selected: false
        title: "AI\u30B8\u30E3\u30FC\u30CA\u30EA\u30B9\u30C8"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      height: 98
      id: '1716775619258'
      position:
        x: 949.0710669287596
        y: 282
      positionAbsolute:
        x: 949.0710669287596
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716776460437.output#}}'
        desc: ''
        selected: false
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005_Disp"
        type: answer
        variables:
        - value_selector:
          - '1711527888920'
          - output
          variable: output
      height: 106
      id: '1716775953161'
      position:
        x: 669.0937298845706
        y: 453.4984609693367
      positionAbsolute:
        x: 669.0937298845706
        y: 453.4984609693367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716776291546.output#}}'
        desc: ''
        selected: false
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u8005_Disp"
        type: answer
        variables: []
      height: 106
      id: '1716776255897'
      position:
        x: 364
        y: 459.59231491240956
      positionAbsolute:
        x: 364
        y: 459.59231491240956
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## \u697D\u89B3\u7684AI\u7814\u7A76\u8005\r\n\r\n\
          {{ LLM_output }}\r\n\r\n"
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u8005_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1711527784865'
          - text
          variable: LLM_output
      height: 54
      id: '1716776291546'
      position:
        x: 364
        y: 387.336618158831
      positionAbsolute:
        x: 364
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## \u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005\r\n\
          \r\n{{ LLM_output }}\r\n\r\n"
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1711527861837'
          - text
          variable: LLM_output
      height: 54
      id: '1716776460437'
      position:
        x: 669.0937298845706
        y: 387.336618158831
      positionAbsolute:
        x: 669.0937298845706
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## AI\u30B8\u30E3\u30FC\u30CA\u30EA\u30B9\u30C8\r\
          \n\r\n{{ LLM_output }}\r\n\r\n"
        title: "AI\u30B8\u30E3\u30FC\u30CA\u30EA\u30B9\u30C8_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1711527861837'
          - text
          variable: LLM_output
      height: 54
      id: '1716776501998'
      position:
        x: 949.0710669287596
        y: 387.336618158831
      positionAbsolute:
        x: 949.0710669287596
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "\n# \u8B70\u8AD6\u3059\u308B\u30C6\u30FC\u30DE\n\
            {{#sys.query#}}\n\n{{#1716776501998.output#}}\n\n\u502B\u7406\u5B66\u8005\
            :"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 512
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: llm-jp-13b-v2
          provider: ollama
        prompt_template:
        - id: 17774cf5-0f56-4814-885b-347ea826cb02
          role: system
          text: "\u3042\u306A\u305F\u306F\u502B\u7406\u5B66\u8005\u3067\u3059\u3002\
            \u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\u30C3\u30C8\u3068\u3001\u3053\u308C\
            \u307E\u3067\u306E\u8B70\u8AD6\u3092\u8E0F\u307E\u3048\u3066\u3001AI\u3068\
            \u793E\u4F1A\u306E\u95A2\u4FC2\u6027\u306B\u3064\u3044\u3066\u502B\u7406\
            \u7684\u89B3\u70B9\u304B\u3089\u8003\u5BDF\u3057\u3066\u304F\u3060\u3055\
            \u3044\u3002\u52B9\u7387\u6027\u3060\u3051\u3067\u306A\u304F\u3001\u4EBA\
            \u9593\u306E\u5C0A\u53B3\u3084\u751F\u304D\u304C\u3044\u306B\u3082\u89E6\
            \u308C\u306A\u304C\u3089\u3001\u3042\u308B\u3079\u304D\u793E\u4F1A\u306E\
            \u59FF\u3092\u8AD6\u3058\u3066\u304F\u3060\u3055\u3044\u3002\n\n\n\n"
        selected: false
        title: "\u502B\u7406\u5B66\u8005"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      height: 98
      id: '1716777781638'
      position:
        x: 1242.245842277085
        y: 282
      positionAbsolute:
        x: 1242.245842277085
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## \u502B\u7406\u5B66\u8005\r\n\r\n{{ LLM_output\
          \ }}\r\n\r\n"
        title: "\u502B\u7406\u5B66\u8005_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1711527861837'
          - text
          variable: LLM_output
      height: 54
      id: '1716777823449'
      position:
        x: 1242.245842277085
        y: 387.336618158831
      positionAbsolute:
        x: 1242.245842277085
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716777823449.output#}}'
        desc: ''
        selected: false
        title: "\u502B\u7406\u5B66\u8005_Disp"
        type: answer
        variables:
        - value_selector:
          - '1711527888920'
          - output
          variable: output
      height: 106
      id: '1716777828148'
      position:
        x: 1242.245842277085
        y: 453.4984609693367
      positionAbsolute:
        x: 1242.245842277085
        y: 453.4984609693367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    viewport:
      x: 26.89304516476716
      y: 4.686051075992964
      zoom: 1.1486983549970353

コメント

タイトルとURLをコピーしました