Commit 8334cad
committed
fix: Add None check in _trim_messages to prevent TypeError
Prevent TypeError when comparing int with NoneType in message trimming.
Problem:
When agent execution starts, _trim_messages() is called to manage context.
The method calculates max_tokens = context_window - reserve_tokens, then
compares current_tokens <= max_tokens. If context_window or reserve_tokens
is None (edge case with model initialization), this causes:
TypeError: '<' not supported between instances of 'int' and 'NoneType'
Solution:
Add safety check after getting context_window and reserve_tokens.
If either value is None, log warning and return early without trimming.
This prevents the crash while maintaining backward compatibility - the
trimming simply won't happen in edge cases where context values cannot
be determined, which is safe (agent will continue without context management).
Error location: agentmesh/protocol/agent_stream.py line 387
Error message from user:
[ERROR][2026-02-03 21:13:07][agent_stream.py:162] - Agent execution error:
'<' not supported between instances of 'int' and 'NoneType'1 parent ea3d635 commit 8334cad
1 file changed
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
| |||
0 commit comments