Skip to content

Conversation

@pyek-bot
Copy link
Collaborator

@pyek-bot pyek-bot commented Aug 1, 2025

Description

Ensures that chat agent returns a response when max iterations are reached. Currently, it returns an empty response when max_iteration is even and no response (api times out) if max_iteration is odd. This PR resolves that issue.

Related Issues

Resolves #4011

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.

pyek-bot added 2 commits July 31, 2025 20:33
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:38 — with GitHub Actions Failure
@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:38 — with GitHub Actions Failure
@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:38 — with GitHub Actions Error
@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:38 — with GitHub Actions Error
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:46 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:46 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:46 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 03:46 — with GitHub Actions Error
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
@pyek-bot pyek-bot changed the title fix: mlchatagentrunner max iterations bug Ensure chat agent returns response when max iterations are reached Aug 1, 2025
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 07:35 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 07:35 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 07:35 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 07:35 — with GitHub Actions Inactive
@pyek-bot pyek-bot marked this pull request as ready for review August 1, 2025 07:35
@codecov
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.64%. Comparing base (0db22c9) to head (85bc638).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
.../ml/engine/algorithms/agent/MLChatAgentRunner.java 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #4031   +/-   ##
=========================================
  Coverage     80.64%   80.64%           
- Complexity     8016     8025    +9     
=========================================
  Files           695      695           
  Lines         35023    35058   +35     
  Branches       3935     3942    +7     
=========================================
+ Hits          28244    28274   +30     
- Misses         5044     5047    +3     
- Partials       1735     1737    +2     
Flag Coverage Δ
ml-commons 80.64% <95.23%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 17:48 — with GitHub Actions Failure
@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 17:48 — with GitHub Actions Error
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:19 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:19 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:19 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:19 — with GitHub Actions Inactive
public static final String DATETIME_FORMAT_FIELD = "datetime_format";
public static final String SYSTEM_PROMPT_FIELD = "system_prompt";

private static final String DEFAULT_MAX_ITERATIONS = "10";
Copy link
Collaborator

Choose a reason for hiding this comment

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

can customer configure this value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, chat agent has a parameter max_iteration

Copy link
Contributor

@jiapingzeng jiapingzeng left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix!

Copy link
Contributor

@rithin-pullela-aws rithin-pullela-aws left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Pavan Yekbote <pybot@amazon.com>
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:52 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:52 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:52 — with GitHub Actions Inactive
@pyek-bot pyek-bot temporarily deployed to ml-commons-cicd-env-require-approval August 1, 2025 18:52 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os merged commit f6a68bf into opensearch-project:main Aug 1, 2025
9 checks passed
@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 20:51 — with GitHub Actions Error
@pyek-bot pyek-bot had a problem deploying to ml-commons-cicd-env-require-approval August 1, 2025 20:51 — with GitHub Actions Failure
@pyek-bot
Copy link
Collaborator Author

pyek-bot commented Aug 1, 2025

Can a maintainer please add backport label for 3.1? Thanks!
cc: @dhrubo-os @ylwu-amzn

@opensearch-trigger-bot
Copy link
Contributor

The backport to 3.1 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-3.1 3.1
# Navigate to the new working tree
cd .worktrees/backport-3.1
# Create a new branch
git switch --create backport/backport-4031-to-3.1
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f6a68bf2ffca0b68c0c677a0aca9125e42f13a46
# Push it to GitHub
git push --set-upstream origin backport/backport-4031-to-3.1
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-3.1

Then, create a pull request where the base branch is 3.1 and the compare/head branch is backport/backport-4031-to-3.1.

pyek-bot added a commit to pyek-bot/ml-commons that referenced this pull request Aug 1, 2025
…pensearch-project#4031)

* fix: mlchatagentrunner max iterations bug

Signed-off-by: Pavan Yekbote <pybot@amazon.com>

* fix: gradle spotless

Signed-off-by: Pavan Yekbote <pybot@amazon.com>

* feat: refactor some code and add test cases

Signed-off-by: Pavan Yekbote <pybot@amazon.com>

* refactor: move the last iteration check earlier

Signed-off-by: Pavan Yekbote <pybot@amazon.com>

---------

Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Co-authored-by: Dhrubo Saha <dhrubo@amazon.com>
@pyek-bot
Copy link
Collaborator Author

pyek-bot commented Aug 1, 2025

Raised manual backport PR: #4036

dhrubo-os added a commit that referenced this pull request Aug 2, 2025
…4031) (#4036)

* fix: mlchatagentrunner max iterations bug



* fix: gradle spotless



* feat: refactor some code and add test cases



* refactor: move the last iteration check earlier



---------

Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Co-authored-by: Dhrubo Saha <dhrubo@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Chat Agent returns empty response when exceeding max iterations

5 participants