fix: Manual compaction does not update context window. (#6682)
This commit is contained in:
@@ -1008,7 +1008,7 @@ impl Agent {
|
||||
{
|
||||
Ok((compacted_conversation, summarization_usage)) => {
|
||||
session_manager.replace_conversation(&session_config.id, &compacted_conversation).await?;
|
||||
self.update_session_metrics(&session_config, &summarization_usage, true).await?;
|
||||
self.update_session_metrics(&session_config.id, session_config.schedule_id.clone(), &summarization_usage, true).await?;
|
||||
|
||||
yield AgentEvent::HistoryReplaced(compacted_conversation.clone());
|
||||
|
||||
@@ -1157,7 +1157,7 @@ impl Agent {
|
||||
}
|
||||
|
||||
if let Some(ref usage) = usage {
|
||||
self.update_session_metrics(&session_config, usage, false).await?;
|
||||
self.update_session_metrics(&session_config.id, session_config.schedule_id.clone(), usage, false).await?;
|
||||
}
|
||||
|
||||
if let Some(response) = response {
|
||||
@@ -1437,7 +1437,7 @@ impl Agent {
|
||||
{
|
||||
Ok((compacted_conversation, usage)) => {
|
||||
session_manager.replace_conversation(&session_config.id, &compacted_conversation).await?;
|
||||
self.update_session_metrics(&session_config, &usage, true).await?;
|
||||
self.update_session_metrics(&session_config.id, session_config.schedule_id.clone(), &usage, true).await?;
|
||||
conversation = compacted_conversation;
|
||||
did_recovery_compact_this_iteration = true;
|
||||
yield AgentEvent::HistoryReplaced(conversation.clone());
|
||||
|
||||
@@ -86,7 +86,7 @@ impl Agent {
|
||||
.conversation
|
||||
.ok_or_else(|| anyhow!("Session has no conversation"))?;
|
||||
|
||||
let (compacted_conversation, _usage) = compact_messages(
|
||||
let (compacted_conversation, usage) = compact_messages(
|
||||
self.provider().await?.as_ref(),
|
||||
session_id,
|
||||
&conversation,
|
||||
@@ -98,6 +98,9 @@ impl Agent {
|
||||
.replace_conversation(session_id, &compacted_conversation)
|
||||
.await?;
|
||||
|
||||
self.update_session_metrics(session_id, session.schedule_id, &usage, true)
|
||||
.await?;
|
||||
|
||||
Ok(Some(Message::assistant().with_system_notification(
|
||||
SystemNotificationType::InlineMessage,
|
||||
"Compaction complete",
|
||||
|
||||
@@ -353,11 +353,11 @@ impl Agent {
|
||||
|
||||
pub(crate) async fn update_session_metrics(
|
||||
&self,
|
||||
session_config: &crate::agents::types::SessionConfig,
|
||||
session_id: &str,
|
||||
schedule_id: Option<String>,
|
||||
usage: &ProviderUsage,
|
||||
is_compaction_usage: bool,
|
||||
) -> Result<()> {
|
||||
let session_id = session_config.id.as_str();
|
||||
let manager = self.config.session_manager.clone();
|
||||
let session = manager.get_session(session_id, false).await?;
|
||||
|
||||
@@ -389,7 +389,7 @@ impl Agent {
|
||||
|
||||
manager
|
||||
.update(session_id)
|
||||
.schedule_id(session_config.schedule_id.clone())
|
||||
.schedule_id(schedule_id)
|
||||
.total_tokens(current_total)
|
||||
.input_tokens(current_input)
|
||||
.output_tokens(current_output)
|
||||
|
||||
Reference in New Issue
Block a user