Skip to content

Commit d90572d

Browse files
committed
add validation check
Signed-off-by: Mingshi Liu <mingshl@amazon.com>
1 parent 35c8ffd commit d90572d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLChatAgentRunner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private void runReAct(
543543
return;
544544
}
545545
// Emit PRE_LLM hook event
546-
if (hookRegistry != null) {
546+
if (hookRegistry != null && !interactions.isEmpty()) {
547547
List<MLToolSpec> currentToolSpecs = new ArrayList<>(toolSpecMap.values());
548548
ContextManagerContext contextAfterEvent = AgentContextUtil
549549
.emitPreLLMHook(tmpParameters, interactions, currentToolSpecs, memory, hookRegistry);
@@ -568,9 +568,10 @@ private void runReAct(
568568
// Emit PRE_LLM hook event for initial LLM call
569569
List<MLToolSpec> initialToolSpecs = new ArrayList<>(toolSpecMap.values());
570570
tmpParameters.put("_llm_model_id", llm.getModelId());
571-
if (hookRegistry != null) {
571+
if (hookRegistry != null && !interactions.isEmpty()) {
572572
ContextManagerContext contextAfterEvent = AgentContextUtil
573573
.emitPreLLMHook(tmpParameters, interactions, initialToolSpecs, memory, hookRegistry);
574+
574575
if (tmpParameters.get(INTERACTIONS) != null || tmpParameters.get(INTERACTIONS) != "") {
575576
tmpParameters.put(INTERACTIONS, StringUtils.toJson(contextAfterEvent.getParameters().get(INTERACTIONS)));
576577
}

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/agent/MLPlanExecuteAndReflectAgentRunner.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,16 @@ private void executePlanningLoop(
397397
// completedSteps to context management.
398398
// TODO should refactor the completed steps as message array format, similar to chat agent.
399399

400-
Map<String, String> requestParams = new HashMap<>(allParams);
401-
400+
allParams.put("_llm_model_id", llm.getModelId());
402401
if (hookRegistry != null && !completedSteps.isEmpty()) {
403-
requestParams.put("_llm_model_id", llm.getModelId());
404-
requestParams.put(INTERACTIONS, ", " + String.join(", ", completedSteps));
402+
allParams.put(INTERACTIONS, ", " + String.join(", ", completedSteps));
403+
Map<String, String> requestParams = new HashMap<>(allParams);
405404
try {
406405
AgentContextUtil.emitPreLLMHook(requestParams, completedSteps, null, memory, hookRegistry);
406+
407407
if (requestParams.get(INTERACTIONS) != null || requestParams.get(INTERACTIONS) != "") {
408-
requestParams.put(COMPLETED_STEPS_FIELD, StringUtils.toJson(requestParams.get(INTERACTIONS)));
409-
requestParams.put(INTERACTIONS, "");
408+
allParams.put(COMPLETED_STEPS_FIELD, StringUtils.toJson(requestParams.get(INTERACTIONS)));
409+
allParams.put(INTERACTIONS, "");
410410
}
411411
} catch (Exception e) {
412412
log.error("Failed to emit pre-LLM hook", e);
@@ -419,7 +419,7 @@ private void executePlanningLoop(
419419
RemoteInferenceMLInput
420420
.builder()
421421
.algorithm(FunctionName.REMOTE)
422-
.inputDataset(RemoteInferenceInputDataSet.builder().parameters(requestParams).build())
422+
.inputDataset(RemoteInferenceInputDataSet.builder().parameters(allParams).build())
423423
.build(),
424424
null,
425425
allParams.get(TENANT_ID_FIELD)

0 commit comments

Comments
 (0)