Python: coalesce code interpreter history chunks#5801
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses streamed code-interpreter history bloat in the Python core by coalescing code_interpreter_tool_call / code_interpreter_tool_result content items with the same call_id (or item_id) during response finalization, ensuring history providers receive a single aggregated item per logical tool call.
Changes:
- Add response-finalization logic to coalesce code-interpreter tool call/result content by
(type, call_id). - Implement merge behavior that prefers a later “done” event carrying the full code over keeping both deltas and the complete script.
- Add a regression test ensuring history providers store the coalesced code-interpreter content shape.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
python/packages/core/agent_framework/_types.py |
Adds code-interpreter coalescing/merge helpers and applies them during _finalize_response. |
python/packages/core/tests/core/test_sessions.py |
Adds a history-provider regression test verifying coalesced code-interpreter chunks are stored as a single content item. |
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
|
@he-yufeng please have a look at the failing code quality failures. Thank you. |
|
Thanks for the heads up. I pushed a small follow-up that narrows the nested content list types before iteration/deepcopy, which addresses the pyright failures from the package check. Validated locally:
|
|
Thanks, I pushed a follow-up for the mypy redundant-cast failure in Validated locally:
|
118ecb5 to
a4a0a73
Compare
|
I also rebased the branch onto current Revalidated after the rebase:
|
Fixes #5793.
Summary
To verify