Skip to content

Commit e1bc0e0

Browse files
committed
add validation check
Signed-off-by: Mingshi Liu <[email protected]>
1 parent 3c28383 commit e1bc0e0

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
@@ -396,16 +396,16 @@ private void executePlanningLoop(
396396
// completedSteps to context management.
397397
// TODO should refactor the completed steps as message array format, similar to chat agent.
398398

399-
Map<String, String> requestParams = new HashMap<>(allParams);
400-
399+
allParams.put("_llm_model_id", llm.getModelId());
401400
if (hookRegistry != null && !completedSteps.isEmpty()) {
402-
requestParams.put("_llm_model_id", llm.getModelId());
403-
requestParams.put(INTERACTIONS, ", " + String.join(", ", completedSteps));
401+
allParams.put(INTERACTIONS, ", " + String.join(", ", completedSteps));
402+
Map<String, String> requestParams = new HashMap<>(allParams);
404403
try {
405404
AgentContextUtil.emitPreLLMHook(requestParams, completedSteps, null, memory, hookRegistry);
405+
406406
if (requestParams.get(INTERACTIONS) != null || requestParams.get(INTERACTIONS) != "") {
407-
requestParams.put(COMPLETED_STEPS_FIELD, StringUtils.toJson(requestParams.get(INTERACTIONS)));
408-
requestParams.put(INTERACTIONS, "");
407+
allParams.put(COMPLETED_STEPS_FIELD, StringUtils.toJson(requestParams.get(INTERACTIONS)));
408+
allParams.put(INTERACTIONS, "");
409409
}
410410
} catch (Exception e) {
411411
log.error("Failed to emit pre-LLM hook", e);
@@ -418,7 +418,7 @@ private void executePlanningLoop(
418418
RemoteInferenceMLInput
419419
.builder()
420420
.algorithm(FunctionName.REMOTE)
421-
.inputDataset(RemoteInferenceInputDataSet.builder().parameters(requestParams).build())
421+
.inputDataset(RemoteInferenceInputDataSet.builder().parameters(allParams).build())
422422
.build(),
423423
null,
424424
allParams.get(TENANT_ID_FIELD)

0 commit comments

Comments
 (0)