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

feat: parse connector id from tool parameters map #846

Merged

Conversation

yuye-aws
Copy link
Member

@yuye-aws yuye-aws commented Aug 26, 2024

Description

Parse connector id from previous_node_inputs into the parameters map

{
  "id": "create_connector_tool",
  "type": "create_tool",
  "previous_node_inputs": {
    "create_connector": "connector_id"
  },
  "user_inputs": {
    "parameters": {},
    "name": "ConnectorTool",
    "type": "ConnectorTool"
  }
}

Related Issues

Resolves #845

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • [ ] API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • [ ] Public documentation issue/PR created. Already documented

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.

@yuye-aws
Copy link
Member Author

Not sure what are the expected UTs and ITs in the PR.

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 77.55%. Comparing base (60458a6) to head (52d68df).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rg/opensearch/flowframework/workflow/ToolStep.java 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #846      +/-   ##
============================================
+ Coverage     77.38%   77.55%   +0.17%     
- Complexity      963      966       +3     
============================================
  Files            97       97              
  Lines          4536     4531       -5     
  Branches        423      422       -1     
============================================
+ Hits           3510     3514       +4     
+ Misses          845      835      -10     
- Partials        181      182       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbwiddis
Copy link
Member

Thanks for the PR! I see you copied what we already did for model ID which works great. I wonder if there's a more efficient way to do it but we can refactor later. :)

Not sure what are the expected UTs and ITs in the PR.

For UT: Looks like our existing unit tests just confirm that we generate a tool step. We could update those to include things in the map and verify that they exist in the MLToolSpec object in the output... which we probably should have already done. ☹️

But this is one of those things probably better tested in an integ test (or API Spec test). Can you add a new test method to FlowFrameworkRestApiIT that tests a Tool (or tools) with inputs from both a connector and a model? You'd basically:

  • create a template in src/test/resources/template with appropriate JSON (probably need to create an agent with those tool(s))
  • copy testSearchWorkflows() and change it to execute your template
  • provision the template
  • call an API to verify the output (in this case you'd probably get the workflow ID after provisioning, use that to query the workflow state to get the resource ID of the agent, then use the agent API to query the agent and make sure it has the connector ID in the JSON

From the standpoint of this PR, doing a manual test and showing the output here is probably sufficient as we have a plan to eventually test all our templates via api spec and that will eventually cover this... but any help you can provide improving out UT/IT would be appreciated.

@yuye-aws
Copy link
Member Author

For UT: Looks like our existing unit tests just confirm that we generate a tool step. We could update those to include things in the map and verify that they exist in the MLToolSpec object in the output... which we probably should have already done. ☹️

Updated

@yuye-aws
Copy link
Member Author

Thanks for the PR! I see you copied what we already did for model ID which works great. I wonder if there's a more efficient way to do it but we can refactor later. :)

It should be a good idea to iterate over a set of [CONNECTOR_ID, MODEL_ID, AGENT_ID]. Hoping that the code can get merged before 2.17, we can refactor the code later in 2.18.

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.

LGTM for now, please make the one tweak on workflow data param I requested!

@dbwiddis dbwiddis added the v2.17.0 Issues targeting release v2.17.0 label Aug 26, 2024
@yuye-aws
Copy link
Member Author

  • call an API to verify the output (in this case you'd probably get the workflow ID after provisioning, use that to query the workflow state to get the resource ID of the agent, then use the agent API to query the agent and make sure it has the connector ID in the JSON

Not sure how to accomplish this step. It takes me some while to get the agent id.

@dbwiddis
Copy link
Member

Not sure how to accomplish this step. It takes me some while to get the agent id.

This one's probably better handled by an api spec test
CC @JunweiD

@yuye-aws
Copy link
Member Author

Not sure how to accomplish this step. It takes me some while to get the agent id.

This one's probably better handled by an api spec test CC @JunweiD

Just figured out. Pushing the code now.

@yuye-aws
Copy link
Member Author

@dbwiddis Can you help review the IT code? Thanks!

@yuye-aws yuye-aws requested a review from dbwiddis August 26, 2024 07:13
@yuye-aws yuye-aws force-pushed the feat/ParseConnectorIDFromToolParams branch from 88b1ecf to 44cf0be Compare August 26, 2024 07:24
@yuye-aws
Copy link
Member Author

Not sure whether the current CI error is attributed to this PR. Can someone take a look?

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.

Still LGTM with a few suggestions.

Copy link
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

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

Can you also write a secured integ test for this in FlowFrameworkSecureRestApiIT?

@yuye-aws
Copy link
Member Author

Can you also write a secured integ test for this in FlowFrameworkSecureRestApiIT?

I can add an IT. Before that, can you tell me its difference between FlowFrameworkRestApiIT? I do not wish to implement duplicated ITs.

@owaiskazi19
Copy link
Member

Can you also write a secured integ test for this in FlowFrameworkSecureRestApiIT?

I can add an IT. Before that, can you tell me its difference between FlowFrameworkRestApiIT? I do not wish to implement duplicated

FlowFrameworkSecureRestApiIT is for security enabled integ tests and FlowFrameworkRestApiIT is for security disabled integ tests.

@yuye-aws
Copy link
Member Author

Can you also write a secured integ test for this in FlowFrameworkSecureRestApiIT?

I can add an IT. Before that, can you tell me its difference between FlowFrameworkRestApiIT? I do not wish to implement duplicated

FlowFrameworkSecureRestApiIT is for security enabled integ tests and FlowFrameworkRestApiIT is for security disabled integ tests.

FlowFrameworkSecureRestApiIT is mainly about access control. Not sure if you expect to see a similar method like testCreateAndProvisionConnectorToolAgentFrameworkWorkflow.

@owaiskazi19
Copy link
Member

owaiskazi19 commented Aug 27, 2024

FlowFrameworkSecureRestApiIT is mainly about access control. Not sure if you expect to see a similar method like testCreateAndProvisionConnectorToolAgentFrameworkWorkflow.

So since you are adding a new template file createconnector-createconnectortool-createflowagent.json. We can add a new secured integ tests for create and provision with access control.

@dbwiddis
Copy link
Member

FlowFrameworkSecureRestApiIT is mainly about access control. Not sure if you expect to see a similar method like testCreateAndProvisionConnectorToolAgentFrameworkWorkflow.

Does the ML Commons client connector API behave differently with/without the security plugin installed? If so, it's appropriate.

@yuye-aws
Copy link
Member Author

Does the ML Commons client connector API behave differently with/without the security plugin installed? If so, it's appropriate.

No. I don't think so. Connector is accessing remote services. Security plugin does not matter.

@dbwiddis
Copy link
Member

No. I don't think so. Connector is accessing remote services. Security plugin does not matter.

Then I don't think a security integ test is needed. @owaiskazi19 do you feel differently?

@owaiskazi19
Copy link
Member

No. I don't think so. Connector is accessing remote services. Security plugin does not matter.

Then I don't think a security integ test is needed. @owaiskazi19 do you feel differently?

Agreed. @yuye-aws can you resolve the other comments then and we can get this in?

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
@yuye-aws yuye-aws force-pushed the feat/ParseConnectorIDFromToolParams branch from e7994a6 to a8872d6 Compare August 28, 2024 02:39
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
@yuye-aws
Copy link
Member Author

@dbwiddis @owaiskazi19 This PR has been updated according to your comments. Can you help review again?

@yuye-aws
Copy link
Member Author

There seems to be a flakey test. Need to rerun this workflow.

@dbwiddis
Copy link
Member

dbwiddis commented Aug 28, 2024

There seems to be a flakey test. Need to rerun this workflow.

Yeah, macos multinode runs into memory issues sometimes (3 nodes in docker + deploying a local model), will rerun, but sometimes we just merge if that's the only failure.

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
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.

LGTM and I've checked all requested changes and resolved the conversations.

@dbwiddis dbwiddis merged commit b3f9d65 into opensearch-project:main Aug 28, 2024
20 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 28, 2024
* feat: parse connector id from tool parameters map

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* update changelog

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* implement unit test for connector, model and agent id

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* tool step id: make node id unique

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* integration test: create agent with connector tool

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* integration test: update with get agent and get workflow

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* optimize: iterate through connector_id model_id and agent_id

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* update changelog

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
(cherry picked from commit b3f9d65)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
dbwiddis added a commit that referenced this pull request Aug 28, 2024
* feat: parse connector id from tool parameters map (#846)

* feat: parse connector id from tool parameters map

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* update changelog

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* implement unit test for connector, model and agent id

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* tool step id: make node id unique

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* integration test: create agent with connector tool

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* integration test: update with get agent and get workflow

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* optimize: iterate through connector_id model_id and agent_id

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* update changelog

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
(cherry picked from commit b3f9d65)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* JDK21 minimum is only for 3.x

Signed-off-by: Daniel Widdis <widdis@gmail.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Daniel Widdis <widdis@gmail.com>
@yuye-aws yuye-aws deleted the feat/ParseConnectorIDFromToolParams branch September 14, 2024 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport PRs to 2.x branch v2.17.0 Issues targeting release v2.17.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Function getToolsParametersMap in ToolStep should parse connector id
3 participants