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

[Feature/agent_framework] Adds a Search Workflow State API #284

Merged

Conversation

joshpalis
Copy link
Member

@joshpalis joshpalis commented Dec 13, 2023

Description

This PR modifies the workflow state system index mapping so that the resources_created array has a static mapping rather than just using type object. This allows us to use a search query against this index for specific terms within the resources_created object array.

Additionally, this PR exposes a search API (path : /_plugins/_flow_framework/workflow/state/_search ) against this system index which can accept OpenSearch DSL. Open to suggestions on the path if there are any concerns

Testing locally, creating a workflow that creates a connector, registers a remote model and deploys :

curl -i -XPOST "localhost:9200/_plugins/_flow_framework/workflow" -H "Content-Type:application/json" --data '{"name":"create-connector-register-deploy-model","description":"test case","use_case":"TEST_CASE","version":{"template":"1.0.0","compatibility":["2.12.0","3.0.0"]},"workflows":{"provision":{"nodes":[{"id":"workflow_step_1","type":"create_connector","user_inputs":{"name":"OpenAI Chat Connector","description":"The connector to public OpenAI model service for GPT 3.5","version":"1","protocol":"http","parameters":{"endpoint":"api.openai.com","model":"gpt-3.5-turbo"},"credential":{"openAI_key":"12345"},"actions":[{"action_type":"predict","method":"POST","url":"https://${parameters.endpoint}/v1/chat/completions"}]}},{"id":"workflow_step_2","type":"register_remote_model","previous_node_inputs":{"workflow_step_1":"connector_id"},"user_inputs":{"name":"openAI-gpt-3.5-turbo","function_name":"remote","description":"test model"}},{"id":"workflow_step_3","type":"deploy_model","previous_node_inputs":{"workflow_step_2":"model_id"}}],"edges":[{"source":"workflow_step_1","dest":"workflow_step_2"},{"source":"workflow_step_2","dest":"workflow_step_3"}]}}}'

HTTP/1.1 201 Created
content-type: application/json; charset=UTF-8
content-length: 38

{"workflow_id":"7CQYYYwBLLLWmLbUe31f"}

Provisioning this workflow

curl -i -XPOST "localhost:9200/_plugins/_flow_framework/workflow/7CQYYYwBLLLWmLbUe31f/_provision"
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 38

{"workflow_id":"7CQYYYwBLLLWmLbUe31f"}

OpenSearch logs show us that the steps have completed successfully and that the resources created have been updated :

[2023-12-13T02:54:27,130][INFO ][o.o.m.m.MLModelManager   ] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] Completed setting connector 7SQYYYwBLLLWmLbU1H2B in the model 8CQYYYwBLLLWmLbU1n2L
[2023-12-13T02:54:32,083][INFO ][o.o.f.w.AbstractRetryableWorkflowStep] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] Deploy model successful for 7CQYYYwBLLLWmLbUe31f and modelId 8CQYYYwBLLLWmLbU1n2L
[2023-12-13T02:54:32,102][INFO ][o.o.f.i.FlowFrameworkIndicesHandler] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] updated resources created of 7CQYYYwBLLLWmLbUe31f
[2023-12-13T02:54:32,103][INFO ][o.o.f.w.AbstractRetryableWorkflowStep] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] successfully updated resources created in state index: .plugins-workflow-state
[2023-12-13T02:54:32,103][INFO ][o.o.f.t.ProvisionWorkflowTransportAction] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] Provisioning completed successfully for workflow 7CQYYYwBLLLWmLbUe31f
[2023-12-13T02:54:32,103][INFO ][o.o.f.w.ProcessNode      ] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] Finished workflow_step_3.
[2023-12-13T02:54:32,126][INFO ][o.o.f.t.ProvisionWorkflowTransportAction] [dev-dsk-jpalis-2c-27c8aa11.us-west-2.amazon.com] updated workflow 7CQYYYwBLLLWmLbUe31f state to COMPLETED

Now we hit the new search API using a bool query on the resources_created path to find documents that have a connector_id resource type :

curl -i -XGET "localhost:9200/_plugins/_flow_framework/workflow/state/_search?pretty" -H "Content-Type:application/json" -d '{"
query":{"nested":{"path":"resources_created","query":{"bool":{"must":[{"match":{"resources_created.resource_type":"connector_id"}}]}}}}}'
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 1496

{
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.7985077,
    "hits" : [
      {
        "_index" : ".plugins-workflow-state",
        "_id" : "7CQYYYwBLLLWmLbUe31f",
        "_version" : 6,
        "_seq_no" : 5,
        "_primary_term" : 1,
        "_score" : 0.7985077,
        "_source" : {
          "workflow_id" : "7CQYYYwBLLLWmLbUe31f",
          "state" : "COMPLETED",
          "provisioning_progress" : "DONE",
          "provision_start_time" : 1702436066147,
          "resources_created" : [
            {
              "workflow_step_name" : "create_connector",
              "workflow_step_id" : "workflow_step_1",
              "resource_type" : "connector_id",
              "resource_id" : "7SQYYYwBLLLWmLbU1H2B"
            },
            {
              "workflow_step_name" : "register_remote_model",
              "workflow_step_id" : "workflow_step_2",
              "resource_type" : "model_id",
              "resource_id" : "8CQYYYwBLLLWmLbU1n2L"
            },
            {
              "workflow_step_name" : "deploy_model",
              "workflow_step_id" : "workflow_step_3",
              "resource_type" : "model_id",
              "resource_id" : "8CQYYYwBLLLWmLbU1n2L"
            }
          ],
          "provision_end_time" : 1702436072103
        }
      }
    ]
  }
}

Issues Resolved

#279

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.

Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
@joshpalis joshpalis marked this pull request as ready for review December 13, 2023 03:03
@dbwiddis
Copy link
Member

find documents that have a connector_id resource type :

We can also search by workflow step, correct? So I could find matching resources for this?

{
  "query": {
    "nested": {
      "path": "resources_created",
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "resources_created.workflow_step_id": "workflow_step_3"
              }
            }
          ]
        }
      }
    }
  }
}

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Great work!

@joshpalis
Copy link
Member Author

@dbwiddis Yes, I've tested the query you provided :

curl -i -XGET "localhost:9200/.plugins-workflow-state/_search?pretty" -H "Content-Type:application/json" -d '{"query":{"nested":{"path":"resources_created","query":{"bool":{"must":[{"match":{"resources_created.workflow_step_id":"workflow_step_3"}}]}}}}}'
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 1420

{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.3862942,
    "hits" : [
      {
        "_index" : ".plugins-workflow-state",
        "_id" : "xxF6ZIwB4h2LBO_7QtZi",
        "_score" : 1.3862942,
        "_source" : {
          "workflow_id" : "xxF6ZIwB4h2LBO_7QtZi",
          "state" : "COMPLETED",
          "provisioning_progress" : "DONE",
          "provision_start_time" : 1702492797079,
          "resources_created" : [
            {
              "workflow_step_name" : "create_connector",
              "workflow_step_id" : "workflow_step_1",
              "resource_type" : "connector_id",
              "resource_id" : "yBF6ZIwB4h2LBO_7edaz"
            },
            {
              "workflow_step_name" : "register_remote_model",
              "workflow_step_id" : "workflow_step_2",
              "resource_type" : "model_id",
              "resource_id" : "yxF6ZIwB4h2LBO_7e9bZ"
            },
            {
              "workflow_step_name" : "deploy_model",
              "workflow_step_id" : "workflow_step_3",
              "resource_type" : "model_id",
              "resource_id" : "yxF6ZIwB4h2LBO_7e9bZ"
            }
          ],
          "provision_end_time" : 1702492803084
        }
      }
    ]
  }
}

Signed-off-by: Joshua Palis <jpalis@amazon.com>
Signed-off-by: Joshua Palis <jpalis@amazon.com>
Copy link
Member

@amitgalitz amitgalitz left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for making this change

@joshpalis joshpalis merged commit affe129 into opensearch-project:feature/agent_framework Dec 13, 2023
10 checks passed
dbwiddis pushed a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
…h-project#284)

* Modifying workflow state index mapping and resources created

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding Search workflow state API

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding rest unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Transport unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Moving resourceType determination outside of the resources created class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

---------

Signed-off-by: Joshua Palis <jpalis@amazon.com>
dbwiddis pushed a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
…h-project#284)

* Modifying workflow state index mapping and resources created

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding Search workflow state API

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding rest unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Transport unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Moving resourceType determination outside of the resources created class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

---------

Signed-off-by: Joshua Palis <jpalis@amazon.com>
dbwiddis pushed a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
…h-project#284)

* Modifying workflow state index mapping and resources created

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding Search workflow state API

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding rest unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Transport unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Moving resourceType determination outside of the resources created class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

---------

Signed-off-by: Joshua Palis <jpalis@amazon.com>
dbwiddis pushed a commit to dbwiddis/flow-framework that referenced this pull request Dec 15, 2023
…h-project#284)

* Modifying workflow state index mapping and resources created

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding Search workflow state API

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding rest unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Transport unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Moving resourceType determination outside of the resources created class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

---------

Signed-off-by: Joshua Palis <jpalis@amazon.com>
dbwiddis pushed a commit that referenced this pull request Dec 18, 2023
* Modifying workflow state index mapping and resources created

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding Search workflow state API

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding rest unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Transport unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Moving resourceType determination outside of the resources created class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

---------

Signed-off-by: Joshua Palis <jpalis@amazon.com>
dbwiddis pushed a commit to dbwiddis/flow-framework that referenced this pull request Dec 18, 2023
…h-project#284)

* Modifying workflow state index mapping and resources created

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding Search workflow state API

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding rest unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Transport unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Moving resourceType determination outside of the resources created class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

---------

Signed-off-by: Joshua Palis <jpalis@amazon.com>
dbwiddis pushed a commit that referenced this pull request Dec 18, 2023
* Modifying workflow state index mapping and resources created

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding Search workflow state API

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Adding rest unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Transport unit tests

Signed-off-by: Joshua Palis <jpalis@amazon.com>

* Moving resourceType determination outside of the resources created class

Signed-off-by: Joshua Palis <jpalis@amazon.com>

---------

Signed-off-by: Joshua Palis <jpalis@amazon.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