Skip to content

fix compaction in tool loops#5392

Closed
jamadeo wants to merge 4 commits intomainfrom
jackamadeo/preserve-tool-request-if-preserving-tool-response
Closed

fix compaction in tool loops#5392
jamadeo wants to merge 4 commits intomainfrom
jackamadeo/preserve-tool-request-if-preserving-tool-response

Conversation

@jamadeo
Copy link
Collaborator

@jamadeo jamadeo commented Oct 27, 2025

No description provided.

@jamadeo jamadeo requested review from DOsinga and katzdave and removed request for katzdave October 27, 2025 18:23
format!(
"{}\nThe last user message was:\n\n{}",
TOOL_LOOP_CONTINUATION_TEXT,
user_message.as_concat_text()
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like a good way to include the last user message 👍

&messages[..messages.len() - 1],
vec![conversation_continuation_message(), message.clone()],
),
Some(message) if is_tool_response_message(message) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check on is_tool_response_message feels a little iffy to me.

For manual compact, I guess it won't happen under normal circumstances, but is that guaranteed for the case where the agent loop is running and runs out of context?

Would consider passing a boolean is_manual_compact passed into compact_messages.

}
let mut new_messages = vec![summary_msg];
new_messages.extend(continuation_messages);
let (new_messages, _issues) = merge_consecutive_messages(new_messages);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice use of merge messages. What should we do with issues? Ideally there are none, but would be nice to know.

@katzdave
Copy link
Collaborator

FYI, noticed one more issue:

Joke request.json

Since I changed manual compaction to actually send a message, we're now picking up that message (as the most recent user message) and moving it after the compaction.

Maybe another argument for just passing in a manual_compaction flag and skipping the whole last user search entirely; I think otherwise we always just want to find the most recent user message and might not need to special case the last one.

@DOsinga
Copy link
Collaborator

DOsinga commented Nov 6, 2025

should we close this one now? or do we need to copy the test?

@katzdave
Copy link
Collaborator

katzdave commented Nov 6, 2025

should we close this one now? or do we need to copy the test?

Yeah closing. Moved the test to #5618

Still porting a little more functionality there

@katzdave katzdave closed this Nov 6, 2025
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.

3 participants