Skip to content

Truncate total tool calls text - #5979

Merged
aibrahim-oai merged 8 commits into
mainfrom
truncate-mcp
Oct 31, 2025
Merged

aibrahim-oai merged 8 commits into
mainfrom
truncate-mcp

Conversation

@aibrahim-oai

Copy link
Copy Markdown
Contributor

Put a cap on the aggregate output of text content on tool calls.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@aibrahim-oai
aibrahim-oai requested a review from gpeal October 30, 2025 17:56
for it in items {
if let FunctionCallOutputContentItem::InputImage { image_url } = it {
out.push(FunctionCallOutputContentItem::InputImage {
image_url: image_url.clone(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be a base64 encoded image which could also be huge

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Next step is resizing images

// Append images.
for it in items {
if let FunctionCallOutputContentItem::InputImage { image_url } = it {
out.push(FunctionCallOutputContentItem::InputImage {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't this reorder items?

I would expect something like:
Map over the items:

  1. Count the length of the item
  2. Add it / 4 or some scalar to a running sum
  3. If >= some max amount, truncate with truncated text. If it's a base64 image, drop it entirely
  4. Add a text item that says n items ommitted if there are more

Wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

does the order matter here? If not, we can just have it like that.
I also think that image should be treated differently and resized. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It can matter!

@aibrahim-oai
aibrahim-oai requested a review from gpeal October 30, 2025 19:11
@pakrym-oai

Copy link
Copy Markdown
Contributor

Needs integration tests

@aibrahim-oai
aibrahim-oai requested review from gpeal and pakrym-oai and removed request for gpeal October 31, 2025 01:03
}
FunctionCallOutputContentItem::InputImage { image_url } => {
out.push(FunctionCallOutputContentItem::InputImage {
image_url: image_url.clone(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can count the url towards remaining even i fyou don't truncate. Maybe add a TODO to truncate images so it doesn't look like they were either intentionally or mistakenly not included

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you want to at least subtract len from remaining? That seems low lift and net positive

}
FunctionCallOutputContentItem::InputImage { image_url } => {
out.push(FunctionCallOutputContentItem::InputImage {
image_url: image_url.clone(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you want to at least subtract len from remaining? That seems low lift and net positive

@aibrahim-oai
aibrahim-oai merged commit 1c8507b into main Oct 31, 2025
@aibrahim-oai
aibrahim-oai deleted the truncate-mcp branch October 31, 2025 17:30
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants