Goose Simple Compact UX (#4202)

Co-authored-by: David Katz <dkatz@squareup.com>
This commit is contained in:
Alex Hancock
2025-08-26 18:12:02 -04:00
committed by GitHub
parent a3097f5250
commit a4fc5ec4f1
27 changed files with 2608 additions and 1127 deletions
+3
View File
@@ -347,6 +347,9 @@ pub fn message_to_markdown(message: &Message, export_all_content: bool) -> Strin
md.push_str("**Thinking:**\n");
md.push_str("> *Thinking was redacted*\n\n");
}
MessageContent::SummarizationRequested(summarization) => {
md.push_str(&format!("*{}*\n\n", summarization.msg));
}
_ => {
md.push_str(
"`WARNING: Message content type could not be rendered to Markdown`\n\n",
+3
View File
@@ -185,6 +185,9 @@ pub fn render_message(message: &Message, debug: bool) {
println!("\n{}", style("Thinking:").dim().italic());
print_markdown("Thinking was redacted", theme);
}
MessageContent::SummarizationRequested(summarization) => {
println!("\n{}", style(&summarization.msg).yellow());
}
_ => {
println!("WARNING: Message content type could not be rendered");
}
+1 -1
View File
@@ -946,7 +946,7 @@ impl Agent {
// If we compacted, yield the compaction message and history replacement event
if let Some(compaction_msg) = compaction_msg {
return Ok(Box::pin(async_stream::try_stream! {
yield AgentEvent::Message(Message::assistant().with_text(compaction_msg));
yield AgentEvent::Message(Message::assistant().with_summarization_requested(compaction_msg));
yield AgentEvent::HistoryReplaced(messages.messages().clone());
// Continue with normal reply processing using compacted messages
+15 -4
View File
@@ -84,10 +84,21 @@ impl Agent {
// Add an assistant message to the summarized messages to ensure the assistant's response is included in the context.
if new_messages.len() == 1 {
let assistant_message = Message::assistant().with_text(
"I ran into a context length exceeded error so I summarized our conversation.",
);
let assistant_message_tokens: usize = 14;
let compaction_marker = Message::assistant()
.with_summarization_requested("Conversation compacted and summarized");
let compaction_marker_tokens: usize = 8;
// Insert the marker before the summary message
new_messages.insert(0, compaction_marker);
new_token_counts.insert(0, compaction_marker_tokens);
// Add an assistant message to continue the conversation
let assistant_message = Message::assistant().with_text("
The previous message contains a summary that was prepared because a context limit was reached.
Do not mention that you read a summary or that conversation summarization occurred
Just continue the conversation naturally based on the summarized context
");
let assistant_message_tokens: usize = 41;
new_messages.push(assistant_message);
new_token_counts.push(assistant_message_tokens);
}
@@ -595,6 +595,8 @@ mod tests {
create_test_message("First message"),
create_test_message("Second message"),
create_test_message("Third message"),
create_test_message("Fourth message"),
create_test_message("Fifth message"),
];
// Create session metadata with high token count to trigger compaction
@@ -617,6 +619,7 @@ mod tests {
// Verify the compacted messages are returned
assert!(!result.messages.is_empty());
// Should have fewer messages after compaction
assert!(result.messages.len() <= messages.len());
}