Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/agents/memory/openai_responses_compaction_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def default_should_trigger_compaction(context: dict[str, Any]) -> bool:

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

Expand Down
21 changes: 17 additions & 4 deletions tests/memory/test_openai_responses_compaction_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,15 @@ def create_mock_session(self) -> MagicMock:
mock.clear_session = AsyncMock()
return mock

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

with pytest.raises(ValueError, match="Unsupported model"):
OpenAIResponsesCompactionSession(
session_id="test",
underlying_session=mock_session,
model="claude-3",
model=model,
)

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

@pytest.mark.asyncio
async def test_run_compaction_input_mode_without_response_id(self) -> None:
@pytest.mark.parametrize(
"model",
[
"gpt-4.1",
"ft:gpt-4.1:my-org::id",
"openai/gpt-4.1",
"openai/openai/gpt-5.6-terra",
"openai/o3",
"openai/ft:gpt-4.1:org:proj:id",
],
)
async def test_run_compaction_input_mode_without_response_id(self, model: str) -> None:
mock_session = self.create_mock_session()
items: list[TResponseInputItem] = [
cast(TResponseInputItem, {"type": "message", "role": "user", "content": "hello"}),
Expand All @@ -786,14 +798,15 @@ async def test_run_compaction_input_mode_without_response_id(self) -> None:
session_id="test",
underlying_session=mock_session,
client=mock_client,
model=model,
compaction_mode="input",
)

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

mock_client.responses.compact.assert_called_once()
call_kwargs = mock_client.responses.compact.call_args.kwargs
assert call_kwargs.get("model") == "gpt-4.1"
assert call_kwargs.get("model") == model
assert "previous_response_id" not in call_kwargs
assert call_kwargs.get("input") == items

Expand Down
Loading