fix(agents): clear Responses API chain state on reset - #4302
businessarshgoyal wants to merge 5 commits into
Conversation
Co-Authored-By: business.arshgoyal@gmail.com <business.arshgoyal@gmail.com>
|
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: Team 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd82f6416f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-Authored-By: business.arshgoyal@gmail.com <business.arshgoyal@gmail.com>
Co-Authored-By: business.arshgoyal@gmail.com <business.arshgoyal@gmail.com>
Co-Authored-By: business.arshgoyal@gmail.com <business.arshgoyal@gmail.com>
|
Found and fixed one additional lazy-stream edge case in |
…clear-response-chain
|
Thanks for re-running it, and for reverting the On the async streaming path you left open: it is covered, and I checked the test is load-bearing the same way you did the sync one. 7 passed with it restored. The reason there is a distinct call site per arm: I also merged current |
Related Issue
Closes #4299
Description
ChatAgent.clone()shares model backend instances, while Responses API continuation state is stored per agent session. Clearing or resetting a pooled clone previously rebuilt its local memory but leftprevious_response_idand message-offset state behind, allowing its next task to continue an unrelated conversation.This adds a model-backend reset hook and invokes it from the common
clear_memory()path, coveringreset(), system-message changes, the memory toolkit, context summarization, and direct callers. OpenAI and OpenAI-compatible backends remove both response-chain maps for only that agent session, preserving state for sibling clones sharing the backend.Agent context is also restored immediately before each sync or async model request. This keeps lazy streaming responses scoped to their owning clone even when multiple streams are created before they are consumed.
Regression coverage verifies full agent reset, direct memory clearing, and lazy synchronous and asynchronous streaming all use fresh per-agent Responses conversations without disturbing a sibling clone’s chain.
Testing:
uv run pytest -q test/agents/test_chat_agent_clone.py test/models/test_openai_model.py test/models/test_openai_compatible_model.py test/models/test_azure_openai_model.py(68 passed)uv run pre-commit run --files camel/models/base_model.py camel/models/openai_model.py camel/models/openai_compatible_model.py camel/agents/chat_agent.py test/agents/test_chat_agent_clone.py test/models/test_openai_compatible_model.pyuv run mypy --namespace-packages camel/models/base_model.py camel/models/openai_model.py camel/models/openai_compatible_model.py camel/agents/chat_agent.pyuv lock --checkWhat is the purpose of this pull request?
Checklist
pyproject.tomland runuv lock