Skip to content

Forward Responses context management in OpenAI agents - #741

Closed
rakshit-hud wants to merge 2 commits into
fix/anthropic-message-unionfrom
fix/openai-response-compaction
Closed

rakshit-hud wants to merge 2 commits into
fix/anthropic-message-unionfrom
fix/openai-response-compaction

Conversation

@rakshit-hud

@rakshit-hud rakshit-hud commented Oct 23, 2026 •

Copy link
Copy Markdown

Long tool-using Responses rollouts can exhaust their context window because OpenAIConfig currently drops the provider’s context_management option. Agents therefore cannot request native server-side compaction through their normal configuration.

Add the canonical Responses context-management type to OpenAIConfig and forward it on every provider call. The setting survives agent.dump() and configuration round trips for hosted execution. When unset, provider requests retain their existing behavior. The normal previous_response_id chain continues to carry state, including opaque compaction output items.

The official compaction guide describes the API contract. A small synthetic gateway check emitted compaction items and retained an exact required ID across a continued response. Adopting this setting in hosted rollouts requires the runner to use the updated SDK; this PR does not publish a release or update a deployed runner.

Depends on #742 for the pre-existing Anthropic message-schema compatibility fix. The base branch keeps that prerequisite separate from this Responses change.

Validation:

  • 44 OpenAI/base agent tests pass, including normal Run lifecycle coverage of opt-in forwarding on both turns, opaque compaction output, continuation IDs, configuration serialization and the unchanged default.
  • 119 targeted agent/hosted-runtime tests pass with the unrelated Claude timeout case excluded.
  • All 306 agent and hosted-runtime tests pass on top of the compatibility prerequisite with current Anthropic 2.1.0; the earlier 306-test run also passed with Anthropic 1.7.0.
  • Full Ruff lint/format checks and targeted type checking pass.
  • Full local type checking with all supported extras passes after the prerequisite. Hosted-runner adoption and SDK release remain outstanding before the option can be enabled in deployed hosted evaluations.

Note

Low Risk
Opt-in config passthrough to the Responses API with unchanged defaults; no auth, data, or pruning logic changes.

Overview
Adds optional OpenAIConfig.context_management so OpenAI Responses agents can opt into provider server-side compaction (and other context-management policies) instead of dropping that knob.

OpenAIAgent reads the setting from config and passes it on every responses.create call; when unset, requests still omit the parameter (unchanged behavior). The value round-trips through agent.dump() / hosted config for OpenAIConfig.model_validate.

Docs describe enabling compaction with a compact_threshold below the model window; the agent still chains turns via previous_response_id and does not client-side prune. New tests cover per-turn forwarding, default omit, and config serialization across a multi-turn run (including opaque compaction output items).

Reviewed by Cursor Bugbot for commit 0329b80. Bugbot is set up for automated code reviews on this repo. Configure here.

@rakshit-hud
rakshit-hud changed the base branch from main to fix/anthropic-message-union October 23, 2026 02:26
@rakshit-hud
rakshit-hud marked this pull request as ready for review October 23, 2026 02:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T02:42:20.274697Z 0329b80 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jdchawla29

Copy link
Copy Markdown
Collaborator

Closing for now: there's no current consumer, and truncation="auto" already covers context overflow. Happy to revisit with a concrete use case.

@jdchawla29 jdchawla29 closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants