fix(model): clear DeepSeek reasoning cache on ChatAgent reset - #4288
Alphaxiaoteng wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if hasattr(self, "model_backend"): | ||
| for model in getattr(self.model_backend, "models", []): | ||
| if hasattr(model, "clear_reasoning_cache"): | ||
| model.clear_reasoning_cache(self.agent_id) |
There was a problem hiding this comment.
I ran this against 4a356ce9 in a clean python:3.11-slim container. reset() clears the entry keyed by self.agent_id, but the cache is written under get_current_agent_id() (deepseek_model.py:167), and the sync streaming path never sets that. step() dispatches to _stream() at chat_agent.py:2932, while set_current_agent_id is called at 2962 inside _step_impl, the non-streaming branch. A streaming step therefore caches under __default__ and this loop misses it.
Driven through agent.step(), with only the HTTP call stubbed: the stub calls the real _get_reasoning_session_id() and the real _cache_reasoning_content(), so the key derivation is untouched.
stream=True session id at cache-write : '__default__'
cache keys AFTER reset : ['__default__']
reasoning still injected : SECRET TASK A REASONING
stream=False session id at cache-write : 'b2d9cf72-e4da-...'
cache keys AFTER reset : []
reasoning still injected : None
astep() already sets the id at line 3231, ahead of both of its branches, so the async side does not have this gap. Moving those same two lines out of _step_impl and into step() above the stream check makes the streaming arm behave like the second block, and test/models/test_deepseek_model.py still passes 16. I did not exercise async streaming.
Unrelated to the fix: camel/toolkits/base.py carries an mcp import shim that #4294 is already handling as a dependency cap.
Summary
Fixes #4283.
DeepSeekModelcachesreasoning_contentby session ID. InChatAgent, the reasoning cache was not cleared upon callingreset(). When an agent is reused or pooled across distinct tasks, previous task reasoning could leak into subsequent tasks when assistant messages shared identical content (e.g. "Done.").Changes
clear_reasoning_cache(session_id)toDeepSeekModelto invalidate reasoning caches per session ID or globally.ChatAgent.reset(), iterate over backend models and invokeclear_reasoning_cachewith the agent's ID when available.test_deepseek_reasoning_cache_cleared_on_agent_resetintest/models/test_deepseek_model.py.Verification
pytest test/models/test_deepseek_model.py(16 passed).