mirror of
https://github.com/RightNow-AI/openfang.git
synced 2026-07-30 06:32:17 +00:00
Fix token estimation: include ToolUse arguments in text_length
`MessageContent::text_length()` returned 0 for `ToolUse` blocks, ignoring the tool name and JSON input arguments. This caused the compactor's `estimate_token_count()` (which uses `text_length()`) to massively undercount tokens when conversations contained tool calls with large arguments (e.g. web_search results, page content). The result: compaction never triggered despite the session exceeding the context window, leading to "Token limit exceeded" errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
64631a31e6
commit
55395c80db
@@ -142,8 +142,10 @@ impl MessageContent {
|
||||
ContentBlock::Text { text, .. } => text.len(),
|
||||
ContentBlock::ToolResult { content, .. } => content.len(),
|
||||
ContentBlock::Thinking { thinking } => thinking.len(),
|
||||
ContentBlock::ToolUse { .. }
|
||||
| ContentBlock::Image { .. }
|
||||
ContentBlock::ToolUse { name, input, .. } => {
|
||||
name.len() + input.to_string().len()
|
||||
}
|
||||
ContentBlock::Image { .. }
|
||||
| ContentBlock::Unknown => 0,
|
||||
})
|
||||
.sum(),
|
||||
|
||||
Reference in New Issue
Block a user