feat: Add responses.compact-wired session feature #760
+691
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds seamless support of the newly added compaction typed items in agent convo history: https://platform.openai.com/docs/api-reference/responses/compact
Key changes
The key changes are:
How it works
When the compaction is done, all the items except user messages in history data will be compacted into a single encrypted content as below:
[ { "id": "msg_0857699edcad0c8600693bbe84218481a0abc41dd37854ea76", "type": "message", "status": "completed", "content": [ { "type": "input_text", "text": "Call fetch_image_data with label \"alpha\". Then explain compaction in 1 sentence." } ], "role": "user" }, { "id": "msg_0857699edcad0c8600693bbe8f1a9481a083584278da0af74f", "type": "message", "status": "completed", "content": [ { "type": "input_text", "text": "Call fetch_image_data with label \"beta\". Then add a fun fact about space in 1 sentence." } ], "role": "user" }, { "id": "msg_0857699edcad0c8600693bbe9c271881a0aaa3a993a337f9bf", "type": "message", "status": "completed", "content": [ { "type": "input_text", "text": "Call fetch_image_data with label \"gamma\". Then add a fun fact about oceans in 1 sentence." } ], "role": "user" }, { "id": "msg_0857699edcad0c8600693bbec5a47c81a092b11723771d5139", "type": "message", "status": "completed", "content": [ { "type": "input_text", "text": "Call fetch_image_data with label \"delta\". Then add a fun fact about volcanoes in 1 sentence." } ], "role": "user" }, { "id": "msg_0857699edcad0c8600693bbed5b19481a0961473e7127873b9", "type": "message", "status": "completed", "content": [ { "type": "input_text", "text": "Call fetch_image_data with label \"epsilon\". Then add a fun fact about deserts in 1 sentence." } ], "role": "user" }, { "id": "cmp_0857699edcad0c8601693bbee5e0f081a0a020c6a7f4305161", "type": "compaction", "encrypted_content": "gAAAAABpO77lnRqRPYqAvgFZT7x9m8uhUfyDC4C4Xb9__..." } ]At least, "type": "compaction" must be supported in agent loops.