-
Notifications
You must be signed in to change notification settings - Fork 186
Add verbose_filter feature and expose verbose parameter to PER #4358
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,9 @@ public class MLPlanExecuteAndReflectAgentRunner implements MLAgentRunner { | |
| public static final String INJECT_DATETIME_FIELD = "inject_datetime"; | ||
| public static final String DATETIME_FORMAT_FIELD = "datetime_format"; | ||
|
|
||
| public static final String EXECUTOR_VERBOSE = "executor_verbose"; | ||
| public static final String EXECUTOR_VERBOSE_FILTER = "executor_verbose_filter"; | ||
|
Comment on lines
+157
to
+158
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the example, this field name is "verbose" and "verbose_filter", which seems matching to the name in chatAgent. I think "verbose" and "verbose filter" is simpler. |
||
|
|
||
| public MLPlanExecuteAndReflectAgentRunner( | ||
| Client client, | ||
| Settings settings, | ||
|
|
@@ -435,6 +438,15 @@ private void executePlanningLoop( | |
| allParams.getOrDefault(EXECUTOR_MESSAGE_HISTORY_LIMIT, DEFAULT_EXECUTOR_MESSAGE_HISTORY_LIMIT) | ||
| ); | ||
|
|
||
| // Pass through verbose and verbose_filter if provided | ||
| if (allParams.containsKey(EXECUTOR_VERBOSE)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider validation too. |
||
| reactParams.put(AgentUtils.VERBOSE, allParams.get(EXECUTOR_VERBOSE)); | ||
| } | ||
|
|
||
| if (allParams.containsKey(EXECUTOR_VERBOSE_FILTER)) { | ||
| reactParams.put(MLChatAgentRunner.VERBOSE_FILTER, allParams.get(EXECUTOR_VERBOSE_FILTER)); | ||
| } | ||
|
|
||
| AgentMLInput agentInput = AgentMLInput | ||
| .AgentMLInputBuilder() | ||
| .agentId(reActAgentId) | ||
|
|
@@ -449,8 +461,9 @@ private void executePlanningLoop( | |
|
|
||
| // Navigate through the structure to get the response | ||
| Map<String, String> results = new HashMap<>(); | ||
| List<String> allResponses = new ArrayList<>(); | ||
|
|
||
| // Process tensors in a single stream | ||
| // Process tensors to collect all responses | ||
| reactResult.getMlModelOutputs().stream().flatMap(output -> output.getMlModelTensors().stream()).forEach(tensor -> { | ||
| switch (tensor.getName()) { | ||
| case MEMORY_ID_FIELD: | ||
|
|
@@ -459,14 +472,35 @@ private void executePlanningLoop( | |
| case PARENT_INTERACTION_ID_FIELD: | ||
| results.put(PARENT_INTERACTION_ID_FIELD, tensor.getResult()); | ||
| break; | ||
| default: | ||
| Map<String, ?> dataMap = tensor.getDataAsMap(); | ||
| if (dataMap != null && dataMap.containsKey(RESPONSE_FIELD)) { | ||
| results.put(STEP_RESULT_FIELD, (String) dataMap.get(RESPONSE_FIELD)); | ||
| case RESPONSE_FIELD: | ||
| if (tensor.getResult() != null) { | ||
| allResponses.add(tensor.getResult()); | ||
| } else { | ||
| Map<String, ?> dataMap = tensor.getDataAsMap(); | ||
| if (dataMap != null && dataMap.containsKey(RESPONSE_FIELD)) { | ||
| allResponses.add((String) dataMap.get(RESPONSE_FIELD)); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| if (!allResponses.isEmpty()) { | ||
| StringBuilder stepResult = new StringBuilder(); | ||
| stepResult.append(allResponses.getLast()); | ||
| if (allResponses.size() > 1) { | ||
| stepResult.append("\n\n<step-traces>"); | ||
| } | ||
|
|
||
| for (int i = 0; i < allResponses.size() - 1; i++) { | ||
| stepResult.append("\n\n").append(allResponses.get(i)); | ||
| if (i == allResponses.size() - 2) { | ||
| stepResult.append("\n</step-traces>"); | ||
| } | ||
| } | ||
|
|
||
| results.put(STEP_RESULT_FIELD, stepResult.toString()); | ||
| } | ||
|
|
||
|
Comment on lines
+487
to
+503
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a better version to avoid for loop. |
||
| if (!results.containsKey(STEP_RESULT_FIELD)) { | ||
| throw new IllegalStateException("No valid response found in ReAct agent output"); | ||
| } | ||
|
|
@@ -502,8 +536,17 @@ private void executePlanningLoop( | |
| }, e -> log.error("Failed to update task {} with executor memory ID", taskId, e))); | ||
| } | ||
|
|
||
| completedSteps.add(String.format("\nStep %d: %s\n", stepsExecuted + 1, stepToExecute)); | ||
| completedSteps.add(String.format("\nStep %d Result: %s\n", stepsExecuted + 1, results.get(STEP_RESULT_FIELD))); | ||
| completedSteps.add(String.format("\n<step-%d>\n%s\n</step-%d>\n", stepsExecuted + 1, stepToExecute, stepsExecuted + 1)); | ||
| completedSteps | ||
| .add( | ||
| String | ||
| .format( | ||
| "\n<step-%d-result>\n%s\n</step-%d-result>\n", | ||
| stepsExecuted + 1, | ||
| results.get(STEP_RESULT_FIELD), | ||
| stepsExecuted + 1 | ||
| ) | ||
| ); | ||
|
|
||
| saveTraceData( | ||
| (ConversationIndexMemory) memory, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has any validation applied to this verbose filter value? like verboseFilter.matches("^[a-zA-Z]+(,[a-zA-Z]+)*$"). I think it's worth a check before using the filters.