Skip to content

Commit

Permalink
feat: parse connector id from tool parameters map
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws committed Aug 26, 2024
1 parent 3a88199 commit 11c9e0f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/opensearch/flowframework/workflow/ToolStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.opensearch.flowframework.common.CommonValue.TOOLS_FIELD;
import static org.opensearch.flowframework.common.CommonValue.TYPE;
import static org.opensearch.flowframework.common.WorkflowResources.AGENT_ID;
import static org.opensearch.flowframework.common.WorkflowResources.CONNECTOR_ID;
import static org.opensearch.flowframework.common.WorkflowResources.MODEL_ID;

/**
Expand Down Expand Up @@ -114,6 +115,13 @@ private Map<String, String> getToolsParametersMap(
) {
@SuppressWarnings("unchecked")
Map<String, String> parametersMap = (Map<String, String>) parameters;

Optional<String> previousNodeConnector = previousNodeInputs.entrySet()
.stream()
.filter(e -> CONNECTOR_ID.equals(e.getValue()))
.map(Map.Entry::getKey)
.findFirst();

Optional<String> previousNodeModel = previousNodeInputs.entrySet()
.stream()
.filter(e -> MODEL_ID.equals(e.getValue()))
Expand All @@ -126,6 +134,14 @@ private Map<String, String> getToolsParametersMap(
.map(Map.Entry::getKey)
.findFirst();

// Case when connectorId is passed through previousSteps and not present already in parameters
if (previousNodeConnector.isPresent() && !parametersMap.containsKey(CONNECTOR_ID)) {
WorkflowData previousNodeOutput = outputs.get(previousNodeConnector.get());

Check warning on line 139 in src/main/java/org/opensearch/flowframework/workflow/ToolStep.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/workflow/ToolStep.java#L139

Added line #L139 was not covered by tests
if (previousNodeOutput != null && previousNodeOutput.getContent().containsKey(CONNECTOR_ID)) {
parametersMap.put(CONNECTOR_ID, previousNodeOutput.getContent().get(CONNECTOR_ID).toString());

Check warning on line 141 in src/main/java/org/opensearch/flowframework/workflow/ToolStep.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/workflow/ToolStep.java#L141

Added line #L141 was not covered by tests
}
}

// Case when modelId is passed through previousSteps and not present already in parameters
if (previousNodeModel.isPresent() && !parametersMap.containsKey(MODEL_ID)) {
WorkflowData previousNodeOutput = outputs.get(previousNodeModel.get());
Expand Down

0 comments on commit 11c9e0f

Please sign in to comment.