mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-12-01 01:05:10 +08:00
feat: enhance context token estimation and compaction logic
- Added `estimate_context_tokens` function to calculate provider-visible context size based on prompt specifications and projected messages. - Updated `CheckpointBuilder` to record estimated context tokens during message processing. - Refactored compaction logic to utilize the new token estimation, ensuring proper context management during model runs. - Introduced tests to validate context estimation and compaction behavior under various scenarios.
This commit is contained in:
1 parent
ee2592c469
commit
29fde7d7c7
9 files changed
+723
-188
No files matched your search
@@ -3,7 +3,7 @@ use prost::Message;
|
||||
|
||||
use crate::{
|
||||
cursor::{checkpoint::PendingSteps, protocol::proto::agent::v1 as pb},
|
||||
model::CanonicalMessage,
|
||||
model::{estimate_context_tokens, project_messages, CanonicalMessage, PromptSpec},
|
||||
store::{BlobEdge, BlobId},
|
||||
Error, Result,
|
||||
};
|
||||
@@ -85,6 +85,12 @@ impl CheckpointBuilder {
|
||||
.push(archive_id.as_bytes().to_vec());
|
||||
}
|
||||
self.base.self_summary_count = self.base.self_summary_count.saturating_add(1);
|
||||
let projected = project_messages(messages)?;
|
||||
let prompt = PromptSpec {
|
||||
instructions: self.instructions.clone(),
|
||||
tools: self.tool_definitions.clone(),
|
||||
};
|
||||
self.record_context_tokens(Some(estimate_context_tokens(&prompt, &projected)));
|
||||
if let Some(details) = self.base.token_details.as_mut() {
|
||||
details.breakdown = Some(crate::cursor::services::usage::breakdown(
|
||||
details.used_tokens,
|
||||
|
||||
Reference in new issue
Block a user