Skip to content

Conversation

@seratch
Copy link
Member

@seratch seratch commented Dec 12, 2025

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:

  1. Support compaction type items in history
  2. Add OpenAIResponsesCompactionSession, which is a decorator of any Session implementation (except OpenAIConversationsSession) and runs the compaction API call when the compaction should be done for the context efficiency

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.

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

🦋 Changeset detected

Latest commit: 62e6c76

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-openai Patch
@openai/agents-core Patch
@openai/agents Patch
@openai/agents-extensions Patch
@openai/agents-realtime Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rka-oai
Copy link

rka-oai commented Dec 12, 2025

Thank you for doing this! LGTM. LMK if I can help support responses.compact support in the SDK any further. (Let's still wait for someone who's more familiar than me with Agents SDK to stamp, but looks good from a responses POV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants