Repository navigation
Closed
Labels
Milestone
Description
Please read this first
- Have you read the docs?Agents SDK docs yes
- Have you searched for related issues? Others may have faced similar issues. yes
Describe the bug
After upgrading the version, when using OpenAIResponsesCompactionSession to compress session information, if store = False is set when creating the agent, an error will be reported during the compression process, indicating that the Response ID does not exist
Debug information
- Agents SDK version: (e.g.
v0.6.7) - Python version (e.g. Python 3.12)
Repro steps
async def customer_agent():
redis_client = redis.get_async_client()
try:
redis_session = RedisSession(
session_id="demo-session-1",
redis_client=redis_client,
ttl=60*60*24,
)
session = OpenAIResponsesCompactionSession(
session_id="demo-session-1",
underlying_session=redis_session,
model="gpt-4.1",
# Custom compaction trigger (default is 10 candidates)
should_trigger_compaction=lambda ctx: len(ctx["compaction_candidate_items"]) >= 4,
)
agent = Agent(name="Assistant",
model="gpt-5.2",
tools=[],
model_settings=ModelSettings(store=False),
instructions="""
Reply concisely. Keep answers to 1-2 sentences.
""")
prompts = [
"What is the tallest mountain in the world?",
"How tall is it in feet?",
"When was it first climbed?",
"Who was on that expedition?",
"What country is the mountain in?",
]
print("=== Compaction Session Example ===\n")
for i, prompt in enumerate(prompts, 1):
print(f"Turn {i}:")
print(f"User: {prompt}")
result = await Runner.run(agent, session=session, input=prompt)
print(f"Assistant: {result.final_output}\n")
# Show final session state
items = await session.get_items()
print("=== Final Session State ===")
print(f"Total items: {len(items)}")
for item in items:
# Some inputs are stored as easy messages (only `role` and `content`).
item_type = item.get("type") or ("message" if "role" in item else "unknown")
if item_type == "compaction":
print(" - compaction (encrypted content)")
elif item_type == "message":
role = item.get("role", "unknown")
print(f" - message ({role})")
else:
print(f" - {item_type}")
finally:
# 确保 Redis 连接正确关闭
await redis_client.aclose()
output
=== Compaction Session Example ===
Turn 1:
User: What is the tallest mountain in the world?
Assistant: Mount Everest is the tallest mountain in the world, rising about 8,849 meters (29,032 feet) above sea level.
Turn 2:
User: How tall is it in feet?
Assistant: Mount Everest is about **29,032 feet** tall above sea level.
Turn 3:
User: When was it first climbed?
Assistant: Mount Everest was first successfully climbed on **May 29, 1953**, by **Edmund Hillary** and **Tenzing Norgay**.
Turn 4:
User: Who was on that expedition?
Traceback (most recent call last):
File "/Users/abc/www/new-test-gpt/index.py", line 135, in <module>
asyncio.run(customer_agent())
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 664, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/abc/www/new-test-gpt/index.py", line 57, in customer_agent
result = await Runner.run(agent, session=session, input=prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/abc/www/new-test-gpt/.venv/lib/python3.12/site-packages/agents/run.py", line 372, in run
return await runner.run(
^^^^^^^^^^^^^^^^^
File "/Users/abc/www/new-testgpt/.venv/lib/python3.12/site-packages/agents/run.py", line 753, in run
await self._save_result_to_session(
File "/Users/abc/www/new-test-gpt/.venv/lib/python3.12/site-packages/agents/run.py", line 2124, in _save_result_to_session
await session.run_compaction({"response_id": response_id, "force": force_compaction})
File "/Users/abc/www/new-test-gpt/.venv/lib/python3.12/site-packages/agents/memory/openai_responses_compaction_session.py", line 160, in run_compaction
compacted = await self.client.responses.compact(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/abc/www/new-test-gpt/.venv/lib/python3.12/site-packages/openai/resources/responses/responses.py", line 3279, in compact
return await self._post(
^^^^^^^^^^^^^^^^^
File "/Users/abc/www/new-test-gpt/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1797, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/abc/www/new-test-gpt/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1597, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Previous response with id 'resp_*****c38ac3' not found.", 'type': 'invalid_request_error', 'param': 'previous_response_id', 'code': 'previous_response_not_found'}}
Expected behavior
When using compressed session messages, setting ModelSettings(store=False) will not prompt for a non-existent Response ID, and the session can be compressed,
Activity
[-]Bug regarding session message compression[/-][+]Enable OpenAIResponsesCompactionSession to run in stateless mode[/+]seratch commentedon Jan 19, 2026
Thanks for reporting this issue. Indeed, the current implementation of OpenAIResponsesCompactionSession only supports server managed conversation data, which relies on previous_response_id under the hood. However, responses.compact API supports inputs array without previous_response_id, so the use case you mentioned should be supported as well. We'll adjust the internal behavior to support both use cases.
lijianguo1211 commentedon Jan 19, 2026
Thanks for the quick confirmation and the detailed explanation. I really appreciate you planning to adjust the internal behavior to support both the previous_response_id (server-managed) flow and the inputs-only use case. If helpful, I can provide a minimal repro and I’m happy to help test/verify the fix once there’s a patch.
feat: #2333 support input-based responses compaction with store-aware…
feat: #2333 support input-based responses compaction with store-aware…