fix: update context pressure warnings and token estimates after compaction
Reset context pressure warnings and update last_prompt_tokens and last_completion_tokens in the context compressor to prevent stale values from causing excessive warnings and re-triggering compression. This change ensures accurate pressure calculations following the compaction process.
This commit is contained in:
parent
0b993c1e07
commit
481915587e
1 changed files with 10 additions and 1 deletions
11
run_agent.py
11
run_agent.py
|
|
@ -4609,9 +4609,18 @@ class AIAgent:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug("Session DB compression split failed: %s", e)
|
logger.debug("Session DB compression split failed: %s", e)
|
||||||
|
|
||||||
# Reset context pressure warnings — usage drops after compaction
|
# Reset context pressure warnings and token estimate — usage drops
|
||||||
|
# after compaction. Without this, the stale last_prompt_tokens from
|
||||||
|
# the previous API call causes the pressure calculation to stay at
|
||||||
|
# >1000% and spam warnings / re-trigger compression in a loop.
|
||||||
self._context_50_warned = False
|
self._context_50_warned = False
|
||||||
self._context_70_warned = False
|
self._context_70_warned = False
|
||||||
|
_compressed_est = (
|
||||||
|
estimate_tokens_rough(new_system_prompt)
|
||||||
|
+ estimate_messages_tokens_rough(compressed)
|
||||||
|
)
|
||||||
|
self.context_compressor.last_prompt_tokens = _compressed_est
|
||||||
|
self.context_compressor.last_completion_tokens = 0
|
||||||
|
|
||||||
return compressed, new_system_prompt
|
return compressed, new_system_prompt
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue