Skip to content

Commit 360d726

Browse files
fix(sessions): accept namespaced compaction model names (#5225)
Recognize gateway namespaces before validating OpenAI model names, including fine-tuned models, while forwarding the original identifier unchanged. Add focused constructor and compaction request regression coverage. Fixes #5214.
1 parent 770721b commit 360d726

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎src/agents/memory/openai_responses_compaction_session.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def default_should_trigger_compaction(context: dict[str, Any]) -> bool:
7171

7272
def is_openai_model_name(model: str) -> bool:
7373
"""Validate model name follows OpenAI conventions."""
74-
trimmed = model.strip()
74+
trimmed = model.strip().rsplit("/", 1)[-1]
7575
if not trimmed:
7676
return False
7777

‎tests/memory/test_openai_responses_compaction_session.py‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,15 @@ def create_mock_session(self) -> MagicMock:
376376
mock.clear_session = AsyncMock()
377377
return mock
378378

379-
def test_init_validates_model(self) -> None:
379+
@pytest.mark.parametrize("model", ["claude-3", "anthropic/claude-3"])
380+
def test_init_validates_model(self, model: str) -> None:
380381
mock_session = self.create_mock_session()
381382

382383
with pytest.raises(ValueError, match="Unsupported model"):
383384
OpenAIResponsesCompactionSession(
384385
session_id="test",
385386
underlying_session=mock_session,
386-
model="claude-3",
387+
model=model,
387388
)
388389

389390
def test_init_accepts_valid_model(self) -> None:
@@ -759,7 +760,18 @@ def __call__(self, context: dict[str, Any]) -> bool:
759760
mock_client.responses.compact.assert_not_awaited()
760761

761762
@pytest.mark.asyncio
762-
async def test_run_compaction_input_mode_without_response_id(self) -> None:
763+
@pytest.mark.parametrize(
764+
"model",
765+
[
766+
"gpt-4.1",
767+
"ft:gpt-4.1:my-org::id",
768+
"openai/gpt-4.1",
769+
"openai/openai/gpt-5.6-terra",
770+
"openai/o3",
771+
"openai/ft:gpt-4.1:org:proj:id",
772+
],
773+
)
774+
async def test_run_compaction_input_mode_without_response_id(self, model: str) -> None:
763775
mock_session = self.create_mock_session()
764776
items: list[TResponseInputItem] = [
765777
cast(TResponseInputItem, {"type": "message", "role": "user", "content": "hello"}),
@@ -786,14 +798,15 @@ async def test_run_compaction_input_mode_without_response_id(self) -> None:
786798
session_id="test",
787799
underlying_session=mock_session,
788800
client=mock_client,
801+
model=model,
789802
compaction_mode="input",
790803
)
791804

792805
await session.run_compaction({"force": True})
793806

794807
mock_client.responses.compact.assert_called_once()
795808
call_kwargs = mock_client.responses.compact.call_args.kwargs
796-
assert call_kwargs.get("model") == "gpt-4.1"
809+
assert call_kwargs.get("model") == model
797810
assert "previous_response_id" not in call_kwargs
798811
assert call_kwargs.get("input") == items
799812

0 commit comments

Comments
 (0)