본문 바로가기
WIKI 기술 지식 베이스

Workflow tutorial

원문 보기 위키 갱신

출처: 문서

본문

워크플로 튜토리얼

Chain-of-Thought(CoT) 에이전트를 사용하면 대화형 채팅 같은 일반적인 사용 사례의 설정을 자동화할 수 있어요. _에이전트_는 ML 모델과 도구를 오케스트레이션하고 실행해요. _도구_는 특정 작업 집합을 수행해요. 이 페이지에서는 CoT 에이전트를 설정하는 전체 예제를 소개해요. 에이전트와 도구에 대한 자세한 내용은 에이전트와 도구를 참고하세요.

설정에는 다음과 같은 API 요청 순서가 필요하며, 프로비저닝된 리소스는 이후 요청에서 사용돼요. 다음 목록은 이 워크플로에 필요한 단계를 개괄적으로 보여줘요. 단계 이름은 템플릿에 있는 이름과 대응돼요:

  1. 클러스터에 모델 배포하기
  2. 배포된 모델을 추론에 사용하기
    • 특정 작업을 수행하는 여러 도구를 설정해요:
    • 이 도구들을 조합해 사용하는 하나 이상의 에이전트를 설정해요:
      • sub_agent: list_index_tool을 사용하는 에이전트를 생성해요.
    • 이 에이전트들을 나타내는 도구를 설정해요:
      • agent_tool: sub_agent를 도구로 사용할 수 있도록 감싸요.
    • root_agent: 작업을 도구나 다른 에이전트에 위임할 수 있는 루트 에이전트를 설정해요.

다음 섹션에서는 각 단계를 자세히 설명해요. 전체 워크플로 템플릿은 전체 YAML 워크플로 템플릿을 참고하세요.

워크플로 그래프

이전 섹션에서 설명한 워크플로는 템플릿으로 구성돼요. 단계의 순서는 여러 가지 방식으로 지정할 수 있다는 점에 유의하세요. 예제 템플릿에서는 ml_model_tool 단계가 root_agent 단계 바로 앞에 지정되어 있지만, deploy_model_3 단계 이후부터 root_agent 단계 이전까지 어느 지점에든 지정할 수 있어요. 다음 다이어그램은 템플릿에 지정된 순서대로 모든 단계에 대해 OpenSearch가 생성하는 방향 비순환 그래프(DAG)를 보여줘요.

예제 워크플로 단계 그래프{:style="width: 100%; max-width: 600px;" class="img-centered"}

1. 클러스터에 모델 배포하기

클러스터에 모델을 배포하려면 모델에 대한 커넥터를 생성하고, 모델을 등록한 다음, 모델을 배포해야 해요.

create_connector_1

워크플로의 첫 번째 단계는 외부에서 호스팅되는 모델에 대한 커넥터를 생성하는 거예요(다음 예제에서는 이 단계를 create_connector_1이라고 불러요). user_inputs 필드의 내용은 ML Commons Create Connector API와 정확히 일치해요:

nodes:
- id: create_connector_1
  type: create_connector
  user_inputs:
    name: OpenAI Chat Connector
    description: The connector to public OpenAI model service for gpt-4o-mini
    version: '1'
    protocol: http
    parameters:
      endpoint: api.openai.com
      model: gpt-4o-mini
    credential:
      openAI_key: '12345'
    actions:
    - action_type: predict
      method: POST
      url: https://${parameters.endpoint}/v1/chat/completions

커넥터를 생성하면 OpenSearch가 connector_id를 반환하는데, 모델을 등록할 때 이 값이 필요해요.

register_model_2

모델을 등록할 때 previous_node_inputs 필드는 필요한 connector_id를 create_connector_1 단계의 출력에서 가져오라고 OpenSearch에 지시해요. Register Model API에 필요한 다른 입력값들은 user_inputs 필드에 포함돼요:

- id: register_model_2
  type: register_remote_model
  previous_node_inputs:
    create_connector_1: connector_id
  user_inputs:
    name: openAI-gpt-4o-mini
    function_name: remote
    description: test model

이 단계의 출력은 model_id예요. 그다음 등록된 모델을 클러스터에 배포해야 해요.

deploy_model_3

Deploy Model API는 previous_node_inputs 필드에 지정된 대로 이전 단계의 model_id를 필요로 해요:

- id: deploy_model_3
  type: deploy_model
  # This step needs the model_id produced as an output of the previous step
  previous_node_inputs:
    register_model_2: model_id

Deploy Model API를 직접 사용하면 작업 ID가 반환되기 때문에, 배포가 완료되었는지 확인하려면 Get ML Task API를 사용해야 해요. 자동화된 워크플로는 이러한 수동 상태 확인을 없애고 최종 model_id를 바로 반환해요.

단계 순서 지정

이 단계들을 순서대로 배치하려면 그래프에서 엣지로 연결해야 해요. 단계에 previous_node_input 필드가 있으면 OpenSearch가 이 단계를 위해 source와 dest 필드를 가진 노드를 자동으로 생성해요. source의 출력은 dest의 입력으로 필요해요. 예를 들어 register_model_2 단계는 create_connector_1 단계의 connector_id를 필요로 해요. 마찬가지로 deploy_model_3 단계는 register_model_2 단계의 model_id를 필요로 해요. 따라서 OpenSearch는 출력과 필요한 입력을 맞추고, 필요한 입력이 없으면 오류를 발생시키기 위해 그래프의 처음 두 엣지를 다음과 같이 생성해요:

edges:
- source: create_connector_1
  dest: register_model_2
- source: register_model_2
  dest: deploy_model_3

previous_node_inputs를 정의하면 엣지 정의는 선택 사항이에요. {: .note}

2. 배포된 모델을 추론에 사용하기

CoT 에이전트는 배포된 모델을 도구에서 사용할 수 있어요. 이 단계는 엄밀히 말해 특정 API에 대응하지 않고, Register Agent API에 필요한 본문의 구성 요소를 나타내요. 이렇게 하면 등록 요청이 간단해지고, 동일한 도구를 여러 에이전트에서 재사용할 수 있어요. 에이전트와 도구에 대한 자세한 내용은 에이전트와 도구를 참고하세요.

list_index_tool

CoT 에이전트가 사용할 다른 도구들도 설정할 수 있어요. 예를 들어 다음과 같이 list_index_tool을 설정할 수 있어요. 이 도구는 이전 단계에 의존하지 않아요:

- id: list_index_tool
  type: create_tool
  user_inputs:
    name: ListIndexTool
    type: ListIndexTool
    parameters:
      max_iteration: 5

sub_agent

에이전트 설정에서 list_index_tool을 사용하려면 에이전트의 previous_node_inputs 필드에 도구 중 하나로 지정해요. 필요에 따라 previous_node_inputs에 다른 도구를 추가할 수도 있어요. 에이전트가 도구와 함께 추론하려면 대규모 언어 모델(LLM)도 필요해요. LLM은 llm.model_id 필드로 정의돼요. 이 예제에서는 deploy_model_3 단계의 model_id가 사용된다고 가정해요. 하지만 다른 모델이 이미 배포되어 있다면, 이전에 배포된 그 모델의 model_id를 대신 user_inputs 필드에 포함할 수도 있어요:

- id: sub_agent
  type: register_agent
  previous_node_inputs:
    # When llm.model_id is not present this can be used as a fallback value
    deploy-model-3: model_id
    list_index_tool: tools
  user_inputs:
    name: Sub Agent
    type: conversational
    description: this is a test agent
    parameters:
      hello: world
    llm.parameters:
      max_iteration: '5'
      stop_when_no_tool_found: 'true'
    memory:
      type: conversation_index
    app_type: chatbot

에이전트가 이전 노드에서 필드를 가져올 수 있도록 OpenSearch가 다음과 같은 엣지를 자동으로 생성해요:

- source: list_index_tool
  dest: sub_agent
- source: deploy_model_3
  dest: sub_agent

agent_tool

에이전트를 다른 에이전트의 도구로 사용할 수 있어요. 에이전트를 등록하면 출력에 agent_id가 생성돼요. 다음 단계는 이전 단계의 agent_id를 사용하는 도구를 정의해요:

- id: agent_tool
  type: create_tool
  previous_node_inputs:
    sub_agent: agent_id
  user_inputs:
    name: AgentTool
    type: AgentTool
    description: Agent Tool
    parameters:
      max_iteration: 5

이 단계에서 previous_node_input을 지정하기 때문에 OpenSearch가 엣지 연결을 자동으로 생성해요:

- source: sub_agent
  dest: agent_tool

ml_model_tool

도구는 ML 모델을 참조할 수 있어요. 이 예제는 이전 단계에서 배포한 모델로부터 필요한 model_id를 가져와요:

- id: ml_model_tool
  type: create_tool
  previous_node_inputs:
    deploy-model-3: model_id
  user_inputs:
    name: MLModelTool
    type: MLModelTool
    alias: language_model_tool
    description: A general tool to answer any question.
    parameters:
      prompt: Answer the question as best you can.
      response_filter: choices[0].message.content

previous_node_input을 사용할 수 있도록 OpenSearch가 엣지를 자동으로 생성해요:

- source: deploy-model-3
  dest: ml_model_tool

root_agent

대화형 채팅 애플리케이션은 tools 필드에 ML 모델 도구와 에이전트 도구를 포함하는 단일 루트 에이전트와 통신해요. 또한 배포된 모델로부터 llm.model_id를 가져와요. 일부 에이전트는 도구가 특정 순서로 배치되어야 하는데, 이는 사용자 입력에 tools_order 필드를 포함해 강제할 수 있어요:

- id: root_agent
  type: register_agent
  previous_node_inputs:
    deploy-model-3: model_id
    ml_model_tool: tools
    agent_tool: tools
  user_inputs:
    name: DEMO-Test_Agent_For_CoT
    type: conversational
    description: this is a test agent
    parameters:
      prompt: Answer the question as best you can.
    llm.parameters:
      max_iteration: '5'
      stop_when_no_tool_found: 'true'
    tools_order: ['agent_tool', 'ml_model_tool']
    memory:
      type: conversation_index
    app_type: chatbot

OpenSearch가 previous_node_input 소스에 대한 엣지를 자동으로 생성해요:

- source: deploy-model-3
  dest: root_agent
- source: ml_model_tool
  dest: root_agent
- source: agent_tool
  dest: root_agent

이 워크플로에 대해 OpenSearch가 생성하는 전체 DAG는 워크플로 그래프를 참고하세요.

전체 YAML 워크플로 템플릿

다음은 provision 워크플로 단계를 모두 포함한 최종 템플릿을 YAML 형식으로 나타낸 거예요:

YAML 템플릿 {: .text-delta}
# This template demonstrates provisioning the resources for a 
# Chain-of-Thought chat bot
name: tool-register-agent
description: test case
use_case: REGISTER_AGENT
version:
  template: 1.0.0
  compatibility:
  - 2.12.0
  - 3.0.0
workflows:
  # This workflow defines the actions to be taken when the Provision Workflow API is used
  provision:
    nodes:
    # The first three nodes create a connector to a remote model, registers and deploy that model
    - id: create_connector_1
      type: create_connector
      user_inputs:
        name: OpenAI Chat Connector
        description: The connector to public OpenAI model service for gpt-4o-mini
        version: '1'
        protocol: http
        parameters:
          endpoint: api.openai.com
          model: gpt-4o-mini
        credential:
          openAI_key: '12345'
        actions:
        - action_type: predict
          method: POST
          url: https://${parameters.endpoint}/v1/chat/completions
    - id: register_model_2
      type: register_remote_model
      previous_node_inputs:
        create_connector_1: connector_id
      user_inputs:
        # deploy: true could be added here instead of the deploy step below
        name: openAI-gpt-4o-mini
        description: test model
    - id: deploy_model_3
      type: deploy_model
      previous_node_inputs:
        register_model_2: model_id
    # For example purposes, the model_id obtained as the output of the deploy_model_3 step will be used
    # for several below steps.  However, any other deployed model_id can be used for those steps.
    # This is one example tool from the Agent Framework.
    - id: list_index_tool
      type: create_tool
      user_inputs:
        name: ListIndexTool
        type: ListIndexTool
        parameters:
          max_iteration: 5
    # This simple agent only has one tool, but could be configured with many tools
    - id: sub_agent
      type: register_agent
      previous_node_inputs:
        deploy-model-3: model_id
        list_index_tool: tools
      user_inputs:
        name: Sub Agent
        type: conversational
        parameters:
          hello: world
        llm.parameters:
          max_iteration: '5'
          stop_when_no_tool_found: 'true'
        memory:
          type: conversation_index
        app_type: chatbot
    # An agent can be used itself as a tool in a nested relationship
    - id: agent_tool
      type: create_tool
      previous_node_inputs:
        sub_agent: agent_id
      user_inputs:
        name: AgentTool
        type: AgentTool
        parameters:
          max_iteration: 5
    # An ML Model can be used as a tool
    - id: ml_model_tool
      type: create_tool
      previous_node_inputs:
        deploy-model-3: model_id
      user_inputs:
        name: MLModelTool
        type: MLModelTool
        alias: language_model_tool
        parameters:
          prompt: Answer the question as best you can.
          response_filter: choices[0].message.content
    # This final agent will be the interface for the CoT chat user
    # Using a flow agent type tools_order matters
    - id: root_agent
      type: register_agent
      previous_node_inputs:
        deploy-model-3: model_id
        ml_model_tool: tools
        agent_tool: tools
      user_inputs:
        name: DEMO-Test_Agent
        type: flow
        parameters:
          prompt: Answer the question as best you can.
        llm.parameters:
          max_iteration: '5'
          stop_when_no_tool_found: 'true'
        tools_order: ['agent_tool', 'ml_model_tool']
        memory:
          type: conversation_index
        app_type: chatbot
    # These edges are all automatically created with previous_node_input
    edges:
    - source: create_connector_1
      dest: register_model_2
    - source: register_model_2
      dest: deploy_model_3
    - source: list_index_tool
      dest: sub_agent
    - source: deploy_model_3
      dest: sub_agent
    - source: sub_agent
      dest: agent_tool
    - source: deploy-model-3
      dest: ml_model_tool
    - source: deploy-model-3
      dest: root_agent
    - source: ml_model_tool
      dest: root_agent
    - source: agent_tool
      dest: root_agent

전체 JSON 워크플로 템플릿

다음은 동일한 템플릿을 JSON 형식으로 나타낸 거예요:

JSON 템플릿 {: .text-delta}
{
  "name": "tool-register-agent",
  "description": "test case",
  "use_case": "REGISTER_AGENT",
  "version": {
    "template": "1.0.0",
    "compatibility": [
      "2.12.0",
      "3.0.0"
    ]
  },
  "workflows": {
    "provision": {
      "nodes": [
        {
          "id": "create_connector_1",
          "type": "create_connector",
          "user_inputs": {
            "name": "OpenAI Chat Connector",
            "description": "The connector to public OpenAI model service for gpt-4o-mini",
            "version": "1",
            "protocol": "http",
            "parameters": {
              "endpoint": "api.openai.com",
              "model": "gpt-4o-mini"
            },
            "credential": {
              "openAI_key": "12345"
            },
            "actions": [
              {
                "action_type": "predict",
                "method": "POST",
                "url": "https://${parameters.endpoint}/v1/chat/completions"
              }
            ]
          }
        },
        {
          "id": "register_model_2",
          "type": "register_remote_model",
          "previous_node_inputs": {
            "create_connector_1": "connector_id"
          },
          "user_inputs": {
            "name": "openAI-gpt-4o-mini",
            "description": "test model"
          }
        },
        {
          "id": "deploy_model_3",
          "type": "deploy_model",
          "previous_node_inputs": {
            "register_model_2": "model_id"
          }
        },
        {
          "id": "list_index_tool",
          "type": "create_tool",
          "user_inputs": {
            "name": "ListIndexTool",
            "type": "ListIndexTool",
            "parameters": {
              "max_iteration": 5
            }
          }
        },
        {
          "id": "sub_agent",
          "type": "register_agent",
          "previous_node_inputs": {
            "deploy-model-3": "llm.model_id",
            "list_index_tool": "tools"
          },
          "user_inputs": {
            "name": "Sub Agent",
            "type": "conversational",
            "parameters": {
              "hello": "world"
            },
            "llm.parameters": {
              "max_iteration": "5",
              "stop_when_no_tool_found": "true"
            },
            "memory": {
              "type": "conversation_index"
            },
            "app_type": "chatbot"
          }
        },
        {
          "id": "agent_tool",
          "type": "create_tool",
          "previous_node_inputs": {
            "sub_agent": "agent_id"
          },
          "user_inputs": {
            "name": "AgentTool",
            "type": "AgentTool",
            "parameters": {
              "max_iteration": 5
            }
          }
        },
        {
          "id": "ml_model_tool",
          "type": "create_tool",
          "previous_node_inputs": {
            "deploy-model-3": "model_id"
          },
          "user_inputs": {
            "name": "MLModelTool",
            "type": "MLModelTool",
            "alias": "language_model_tool",
            "parameters": {
              "prompt": "Answer the question as best you can.",
              "response_filter": "choices[0].message.content"
            }
          }
        },
        {
          "id": "root_agent",
          "type": "register_agent",
          "previous_node_inputs": {
            "deploy-model-3": "llm.model_id",
            "ml_model_tool": "tools",
            "agent_tool": "tools"
          },
          "user_inputs": {
            "name": "DEMO-Test_Agent",
            "type": "flow",
            "parameters": {
              "prompt": "Answer the question as best you can."
            },
            "llm.parameters": {
              "max_iteration": "5",
              "stop_when_no_tool_found": "true"
            },
            "tools_order": [
              "agent_tool",
              "ml_model_tool"
            ],
            "memory": {
              "type": "conversation_index"
            },
            "app_type": "chatbot"
          }
        }
      ],
      "edges": [
        {
          "source": "create_connector_1",
          "dest": "register_model_2"
        },
        {
          "source": "register_model_2",
          "dest": "deploy_model_3"
        },
        {
          "source": "list_index_tool",
          "dest": "sub_agent"
        },
        {
          "source": "deploy_model_3",
          "dest": "sub_agent"
        },
        {
          "source": "sub_agent",
          "dest": "agent_tool"
        },
        {
          "source": "deploy-model-3",
          "dest": "ml_model_tool"
        },
        {
          "source": "deploy-model-3",
          "dest": "root_agent"
        },
        {
          "source": "ml_model_tool",
          "dest": "root_agent"
        },
        {
          "source": "agent_tool",
          "dest": "root_agent"
        }
      ]
    }
  }
}

다음 단계

에이전트와 도구에 대해 더 자세히 알아보려면 에이전트와 도구를 참고하세요.

더 알아보기 (Learn more)