Skip to content

Conversation

@onmete
Copy link
Contributor

@onmete onmete commented Jan 26, 2026

Description

Add tool output truncation

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jan 26, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 26, 2026

@onmete: This pull request references OLS-1406 which is a valid jira issue.

Details

In response to this:

Description

Add tool output truncation

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from tisnik and xrajesh January 26, 2026 10:27
@openshift-ci
Copy link

openshift-ci bot commented Jan 27, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign tisnik for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@asamal4 asamal4 left a comment

Choose a reason for hiding this comment

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

Overall tool output truncation logic is fine. But we will have to handle few other scenarios to avoid any error because of context window limit..

  • enforce overall tool token usage limit. Imagine a scenario where we may have multiple small parallel tool outputs. But overall token size may be more.
  • consider tools definition for initial prompt token calculation.
  • need to consider AIMessage in each iteration for input token calculation for next iteration
  • need to re-calculate available tokens for each tool iteration. With every iteration (or with parallel tool calls) AIMessage & tool output will be added to the prompt.
  • token count should be weighted.

if truncation occurred
"""
tokens = self.text_to_tokens(text)
token_count = len(tokens)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider adding the weight, the constant is already there with weight 1.1

max_tokens_per_tool_output: PositiveInt = (
constants.DEFAULT_MAX_TOKENS_PER_TOOL_OUTPUT
)
max_tokens_for_tools: PositiveInt = constants.DEFAULT_MAX_TOKENS_FOR_TOOLS
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just used for initial token reservation, never enforced later. It is possible that after multiple iteration overall limit will exceed

@@ -388,17 +393,29 @@ async def iterate_with_tools( # noqa: C901

# execute tools and add to messages
tool_calls_messages = await execute_tool_calls(
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to recalculate available tokens for every iteration.

@xrajesh
Copy link
Contributor

xrajesh commented Jan 28, 2026

@onmete We want to keep the summarization separate ? how would that impact this calculation ?

@onmete
Copy link
Contributor Author

onmete commented Jan 29, 2026

@xrajesh Partially - the logic for truncating/cut-off of very long tool output will be still be required (output that don't fit into the context window), the rest will be replaced by the summarization logic.
I assume you are talking about summarization of long conversations/contex, rather than truncation.

@onmete
Copy link
Contributor Author

onmete commented Jan 29, 2026

@asamal4 comments addressed.
Changes:

  • token budget is now enforced across iterations, not just reserved upfront
  • later iterations get progressively smaller limits as budget is consumed
  • tool results are not stored in conversation history (confirmed existing behavior is correct)

@onmete
Copy link
Contributor Author

onmete commented Jan 29, 2026

watson timeout
/test e2e-ols-cluster

@openshift-ci
Copy link

openshift-ci bot commented Jan 29, 2026

@onmete: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants