Skip to content

Conversation

@PauiC
Copy link

@PauiC PauiC commented Nov 12, 2025

Description

This feature provides intelligent summarization when ML Commons Chat Agents and PER (planner) agent reach their maximum iteration limit without completing tasks.

Related Issues

#4150

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.

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.

dhrubo-os and others added 30 commits October 24, 2025 16:03
)

Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
…Agents (opensearch-project#4397)

* add hooks in ml-commons (opensearch-project#4326)

Signed-off-by: Xun Zhang <xunzh@amazon.com>

* initiate context management api with hook implementation (opensearch-project#4345)

* initiate context management api with hook implementation

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* apply spotless

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

---------

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* Add Context Manager to PER (opensearch-project#4379)

* add pre_llm hook to per agent

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

change context management passing from query parameters to payload

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

pass hook registery into PER

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

apply spotless

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

initiate context management api with hook implementation

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* add comment

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* format

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* add validation

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

---------

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* add inner create context management to agent register api

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* add code coverage

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* allow context management hook register in during agent execute

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* add code coverage

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* add more code coverage

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* add validation check

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* adapt to inplace update for context

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* fix test

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

---------

Signed-off-by: Xun Zhang <xunzh@amazon.com>
Signed-off-by: Mingshi Liu <mingshl@amazon.com>
Co-authored-by: Xun Zhang <xunzh@amazon.com>
…ut atm)

Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
…ing in index (opensearch-project#4403)

* allow inline create context management without storing in agent register

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* make ML_COMMONS_MULTI_TENANCY_ENABLED default is false

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

---------

Signed-off-by: Mingshi Liu <mingshl@amazon.com>
Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
…roject#4408)

* Fix POST_TOOL hook interaction updates and add tenant ID support
Signed-off-by: Mingshi Liu <mingshl@amazon.com>

- Fix POST_TOOL hook to return full ContextManagerContext like PRE_LLM hook
- Update MLChatAgentRunner to properly handle interaction updates from POST_TOOL hook
- Ensure interactions list and tmpParameters.INTERACTIONS stay synchronized
- Add tenant ID support to MLPredictionTaskRequest in ModelGuardrail and SummarizationManager

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* fix error message escaping

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

* consolicate post_hook logic

Signed-off-by: Mingshi Liu <mingshl@amazon.com>

---------

Signed-off-by: Mingshi Liu <mingshl@amazon.com>
@PauiC PauiC had a problem deploying to ml-commons-cicd-env-require-approval November 12, 2025 10:27 — with GitHub Actions Error
@PauiC PauiC had a problem deploying to ml-commons-cicd-env-require-approval November 12, 2025 10:27 — with GitHub Actions Error
@PauiC PauiC had a problem deploying to ml-commons-cicd-env-require-approval November 12, 2025 10:27 — with GitHub Actions Failure
@PauiC PauiC had a problem deploying to ml-commons-cicd-env-require-approval November 12, 2025 10:27 — with GitHub Actions Failure
Copy link
Contributor

@Hailong-am Hailong-am left a comment

Choose a reason for hiding this comment

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

cherry picked from original PR

Signed-off-by: Jiaru Jiang <jiaruj@amazon.com>
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 02:33 — with GitHub Actions Waiting
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 02:33 — with GitHub Actions Waiting
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 02:33 — with GitHub Actions Waiting
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 02:33 — with GitHub Actions Waiting
Signed-off-by: Jiaru Jiang <jiaruj@amazon.com>
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 03:17 — with GitHub Actions Waiting
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 03:17 — with GitHub Actions Waiting
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 03:17 — with GitHub Actions Waiting
@PauiC PauiC requested a deployment to ml-commons-cicd-env-require-approval November 13, 2025 03:17 — with GitHub Actions Waiting
}
}

public String extractSummaryFromResponse(MLTaskResponse response) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

try to avoid returning nulls inside methods, ideally this method would also handle the errors and return a fallback response.

If you return nulls in a method, it requires the caller to handle the null which can potentially lead to NPEs.

Not urgent, can address in future PRs

}, finalListener::onFailure);

generateSummary(llm, completedSteps, allParams.get(TENANT_ID_FIELD), ActionListener.wrap(summary -> {
log.info("Summary generated successfully");
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's remove this log, seems redundant

Comment on lines +779 to +789
String fallbackResult = completedSteps.isEmpty() || completedSteps.size() < 2
? String.format("Max Steps Limit (%d) Reached. Use memory_id with same task to restart.", maxSteps)
: String
.format(
"Max Steps Limit (%d) Reached. Use memory_id with same task to restart. \n "
+ "Last executed step: %s, \n "
+ "Last executed step result: %s",
maxSteps,
completedSteps.get(completedSteps.size() - 2),
completedSteps.getLast()
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can pass the fallback from the previous method which is generated, this can make the current method more reusable

it's fine for now!

}
}

private String extractSummaryFromResponse(MLTaskResponse response) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can move this to agent utils in a later PR

Copy link
Collaborator

@pyek-bot pyek-bot left a comment

Choose a reason for hiding this comment

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

LGTM, let's merge and address the comments in the main branch PR (or in a follow up PR)

Thanks for taking this up!

@pyek-bot pyek-bot force-pushed the feature/agentic_memory_integration branch from ce7f3f5 to cd738fa Compare November 14, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants