Skip to content

Commit e5fa202

Browse files
committed
fixed context window calc, now properly takes into account max output tokens
1 parent f15013a commit e5fa202

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

crates/pattern_cli/src/agent_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ pub async fn create_agent_from_record_with_tracker(
478478
.context
479479
.as_ref()
480480
.and_then(|c| c.max_messages)
481-
.unwrap_or(50),
481+
.unwrap_or(100),
482482
compression_strategy
483483
.as_ref()
484484
.map(|s| format!("{:?}", s))

crates/pattern_core/src/agent/impls/db_agent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,15 +909,15 @@ where
909909
.find(|m| m.id == *model_id || m.name == *model_id)
910910
.map(|m| {
911911
// Use 90% of context window to leave room for output
912-
(m.context_window as f64 * 0.9) as usize
912+
(m.context_window - m.max_output_tokens.unwrap_or_else(|| 8192)) as usize
913913
})
914914
} else {
915915
None
916916
};
917917

918918
// Build the context config from the record with token limit
919919
let mut context_config = record.to_context_config();
920-
context_config.max_context_tokens = max_context_tokens.or(Some(180_000)); // Fallback to 180k
920+
context_config.max_context_tokens = max_context_tokens.or(Some(136_000)); // Fallback to 136k
921921

922922
// Load tool rules from database record (with config fallback)
923923
let tool_rules = if !record.tool_rules.is_empty() {

0 commit comments

Comments
 (0)