Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow YAML Templates #296

Merged

Conversation

dbwiddis
Copy link
Member

Description

Allows users to submit YAML templates. And CBOR or SMILE if they really want to.

Because comments.

Issues Resolved

Fixes #181 in code (still need to add to documentation).

Sample REST Query:

POST localhost:9200/_plugins/_flow_framework/workflow
Content-Type: application/yaml
---
# HEY LOOK HERE IS A COMMENT!
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: openAI_connector
      type: create_connector
      user_inputs:
        name: OpenAI Chat Connector
        description: The connector to public OpenAI model service for GPT 3.5
        protocol: http
        version: '1'
        parameters:
          endpoint: api.openai.com
          model: flow-register-remote-test-gpt-3.5-turbo
        credential:
          openAI_key: '12345'
        actions:
        - action_type: predict
          method: POST
          url: https://api.openai.com/v1/chat/completions
          request_body: "{}"
    - id: gpt-3.5-model
      type: register_remote_model
      previous_node_inputs:
        openAI_connector: connector_id
      user_inputs:
        name: flow-register-remote-test-gpt-3.5-turbo
        function_name: remote
        description: test model
    - id: deployed-gpt-3.5-model
      type: deploy_model
      previous_node_inputs:
        gpt-3.5-model: model_id
    - id: ml_model_tool
      type: create_tool
      previous_node_inputs:
        deployed-gpt-3.5-model: 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
    - id: math_tool
      type: create_tool
      user_inputs:
        name: MathTool
        type: MathTool
        description: A general tool to calculate any math problem. The action input
          must be valid math expression, like 2+3
        parameters:
          max_iteration: 5
    - id: sub_agent
      type: register_agent
      previous_node_inputs:
        deployed-gpt-3.5-model: llm.model_id
        math_tool: tools
      user_inputs:
        name: Sub Agent
        type: cot
        description: this is a test agent
        parameters:
          hello: world
        llm.model_id: ldzS04kBxRPZ5cnWrqpd
        llm.parameters:
          max_iteration: '5'
          stop_when_no_tool_found: 'true'
        memory:
          type: conversation_index
        app_type: chatbot
        created_time: 1689793598499
        last_updated_time: 1689793598530
    - id: agent_tool
      type: create_tool
      previous_node_inputs:
        sub_agent: agent_id
      user_inputs:
        name: AgentTool
        type: AgentTool
        description: Root Agent Tool
        parameters:
          max_iteration: 5
    - id: root_agent_123
      type: register_agent
      previous_node_inputs:
        deployed-gpt-3.5-model: model_id
        ml_model_tool: tools
        agent_tool: tools
      user_inputs:
        name: DEMO-Test_Agent_For_CoT
        type: cot
        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'
        memory:
          type: conversation_index
        app_type: chatbot
        created_time: 1689793598499
        last_updated_time: 1689793598530
    edges:
    - source: openAI_connector
      dest: gpt-3.5-model
    - source: gpt-3.5-model
      dest: deployed-gpt-3.5-model
    - source: deployed-gpt-3.5-model
      dest: root_agent
    - source: deployed-gpt-3.5-model
      dest: ml_model_tool
    - source: deployed-gpt-3.5-model
      dest: sub_agent
    - source: ml_model_tool
      dest: root_agent
    - source: math_tool
      dest: sub_agent
    - source: sub_agent
      dest: agent_tool
    - source: agent_tool
      dest: root_agent

Output:

---
workflow_id: "QAGWa4wBVW3d7_D9Wfod"

REST Query:

GET localhost:9200/_plugins/_flow_framework/workflow/QAGWa4wBVW3d7_D9Wfod

Output

{
    "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": {
            "user_params": {},
            "nodes": [
                {
                    "id": "openAI_connector",
                    "type": "create_connector",
                    "previous_node_inputs": {},
                    "user_inputs": {
                        "name": "OpenAI Chat Connector",
                        "protocol": "http",
                        "description": "The connector to public OpenAI model service for GPT 3.5",
                        "actions": [
                            {
                                "method": "POST",
                                "request_body": "{}",
                                "action_type": "predict",
                                "url": "https://api.openai.com/v1/chat/completions"
                            }
                        ],
                        "credential": {
                            "openAI_key": "AgV4EK0ucd9yfo48L642YJX157hU0frOhzw/N8WBxG7gRW0AXwABABVhd3MtY3J5cHRvLXB1YmxpYy1rZXkAREExSXhremFIN1VKS21sazhpR0tuaWhra2N0NXRSOEt6bzAycjFQL2tSQ3ZYSk0rU3F6clJNMTZ2MWRlUXJTejFsZz09AAEABkN1c3RvbQAUAAAAgAAAAAxShpEQPAuQ4Wc3rgUAMIu+F7BYVKsr5VujyYMXiI/iC9a1GCkIVy6jKiXqDXHeCHY60rb2lqnbUHUg6djjRAIAABAAe5E07qSYg/nMY6GSoEY6zXvyOaCJnr7pJnXooX5Q8VXf1S9Q3G6sOJZvQ7vUKM7Q/////wAAAAEAAAAAAAAAAAAAAAEAAAAFISfU1oAZPO6XAdmuFK3q82+p9XnhAGcwZQIwHEXB72qY1zdi5GBy6iRLFDxJrdjIh4DkpopK1seyrp+OaXiLI3d0G9LY0fDJymWlAjEAybhmt06PMNlND9x3dp804B//p7YeuOXJzGbo39HD1ENf7UOBZRM087Enzxnt5B8t"
                        },
                        "parameters": {
                            "endpoint": "api.openai.com",
                            "model": "flow-register-remote-test-gpt-3.5-turbo"
                        },
                        "version": "1"
                    }
                },
                {
                    "id": "gpt-3.5-model",
                    "type": "register_remote_model",
                    "previous_node_inputs": {
                        "openAI_connector": "connector_id"
                    },
                    "user_inputs": {
                        "description": "test model",
                        "name": "flow-register-remote-test-gpt-3.5-turbo",
                        "function_name": "remote"
                    }
                },
                {
                    "id": "deployed-gpt-3.5-model",
                    "type": "deploy_model",
                    "previous_node_inputs": {
                        "gpt-3.5-model": "model_id"
                    },
                    "user_inputs": {}
                },
                {
                    "id": "ml_model_tool",
                    "type": "create_tool",
                    "previous_node_inputs": {
                        "deployed-gpt-3.5-model": "model_id"
                    },
                    "user_inputs": {
                        "alias": "language_model_tool",
                        "parameters": {
                            "response_filter": "choices[0].message.content",
                            "prompt": "Answer the question as best you can."
                        },
                        "name": "MLModelTool",
                        "description": "A general tool to answer any question.",
                        "type": "MLModelTool"
                    }
                },
                {
                    "id": "math_tool",
                    "type": "create_tool",
                    "previous_node_inputs": {},
                    "user_inputs": {
                        "type": "MathTool",
                        "name": "MathTool",
                        "description": "A general tool to calculate any math problem. The action input must be valid math expression, like 2+3",
                        "parameters": {
                            "max_iteration": "5"
                        }
                    }
                },
                {
                    "id": "sub_agent",
                    "type": "register_agent",
                    "previous_node_inputs": {
                        "deployed-gpt-3.5-model": "llm.model_id",
                        "math_tool": "tools"
                    },
                    "user_inputs": {
                        "llm.parameters": {
                            "max_iteration": "5",
                            "stop_when_no_tool_found": "true"
                        },
                        "parameters": {
                            "hello": "world"
                        },
                        "name": "Sub Agent",
                        "created_time": 1689793598499,
                        "memory": {
                            "type": "conversation_index"
                        },
                        "last_updated_time": 1689793598530,
                        "description": "this is a test agent",
                        "llm.model_id": "ldzS04kBxRPZ5cnWrqpd",
                        "type": "cot",
                        "app_type": "chatbot"
                    }
                },
                {
                    "id": "agent_tool",
                    "type": "create_tool",
                    "previous_node_inputs": {
                        "sub_agent": "agent_id"
                    },
                    "user_inputs": {
                        "type": "AgentTool",
                        "name": "AgentTool",
                        "description": "Root Agent Tool",
                        "parameters": {
                            "max_iteration": "5"
                        }
                    }
                },
                {
                    "id": "root_agent_123",
                    "type": "register_agent",
                    "previous_node_inputs": {
                        "ml_model_tool": "tools",
                        "deployed-gpt-3.5-model": "model_id",
                        "agent_tool": "tools"
                    },
                    "user_inputs": {
                        "type": "cot",
                        "app_type": "chatbot",
                        "name": "DEMO-Test_Agent_For_CoT",
                        "parameters": {
                            "prompt": "Answer the question as best you can."
                        },
                        "last_updated_time": 1689793598530,
                        "memory": {
                            "type": "conversation_index"
                        },
                        "created_time": 1689793598499,
                        "llm.parameters": {
                            "max_iteration": "5",
                            "stop_when_no_tool_found": "true"
                        },
                        "description": "this is a test agent"
                    }
                }
            ],
            "edges": [
                {
                    "source": "openAI_connector",
                    "dest": "gpt-3.5-model"
                },
                {
                    "source": "gpt-3.5-model",
                    "dest": "deployed-gpt-3.5-model"
                },
                {
                    "source": "deployed-gpt-3.5-model",
                    "dest": "root_agent"
                },
                {
                    "source": "deployed-gpt-3.5-model",
                    "dest": "ml_model_tool"
                },
                {
                    "source": "deployed-gpt-3.5-model",
                    "dest": "sub_agent"
                },
                {
                    "source": "ml_model_tool",
                    "dest": "root_agent"
                },
                {
                    "source": "math_tool",
                    "dest": "sub_agent"
                },
                {
                    "source": "sub_agent",
                    "dest": "agent_tool"
                },
                {
                    "source": "agent_tool",
                    "dest": "root_agent"
                }
            ]
        }
    }
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@joshpalis joshpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if we should persist the template format when retrieving it via the Get Workflow API. IE returning the template in YAML if that's how the template was indexed. Looking at this section, I think it's possible to pass the desired media type when invoking channel.newBuilder().

Just an idea though for a potential improvement, this looks good to me overall :)

Signed-off-by: Daniel Widdis <widdis@gmail.com>
@dbwiddis
Copy link
Member Author

Curious if we should persist the template format when retrieving it via the Get Workflow API.

Hmm, interesting.

When I created the template with application/yaml content type, I got a YAML response.

IE returning the template in YAML if that's how the template was indexed.

I'm not sure we store that info anywhere, it's internally just stored as XContent.

Also it'll lose the comments (if any) and possibly change the ordering.

Looking at this section, I think it's possible to pass the desired media type when invoking channel.newBuilder().

Just an idea though for a potential improvement, this looks good to me overall :)

We should probably not force a specific content type for the return content type, but instead always use the content type the user specified (easily retrievable from request.contentType()). Good issue to create.

@dbwiddis dbwiddis merged commit c7128a0 into opensearch-project:feature/agent_framework Dec 15, 2023
10 checks passed
@dbwiddis dbwiddis deleted the yaml-template branch December 15, 2023 18:00
dbwiddis added a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
Signed-off-by: Daniel Widdis <widdis@gmail.com>
dbwiddis added a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
Signed-off-by: Daniel Widdis <widdis@gmail.com>
@dbwiddis
Copy link
Member Author

@joshpalis Just did a test and if you use the Get Workflow API specifying application/yaml content type, the response is indeed YAML:

---
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:
    user_params: {}

Reviewed our codebase and our only explicit use of JSON is:

  • in our own indices for storing the template, context, state, etc.
  • in the GetWorkflowResponse serialization, we convert to a JSON string for transport but we deserialize from that back into a Java object.

So I don't think we need to do anything code-wise.

We do have a lot of Javadocs that say "raw json" that really should just mean "raw XContent".

dbwiddis added a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
Signed-off-by: Daniel Widdis <widdis@gmail.com>
dbwiddis added a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
Signed-off-by: Daniel Widdis <widdis@gmail.com>
dbwiddis added a commit that referenced this pull request Dec 18, 2023
Signed-off-by: Daniel Widdis <widdis@gmail.com>
dbwiddis added a commit to dbwiddis/flow-framework that referenced this pull request Dec 18, 2023
Signed-off-by: Daniel Widdis <widdis@gmail.com>
dbwiddis added a commit that referenced this pull request Dec 18, 2023
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants