Skip to content
Merged
6 changes: 6 additions & 0 deletions sdk/agentserver/azure-ai-agentserver-responses/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 2.1.0b3 (Unreleased)

### Bugs Fixed

- `get_history_item_ids` on `InMemoryResponseProvider` and `FileResponseStore` now keeps the newest item IDs when applying `limit`. (#48514)

## 2.1.0b2 (2026-08-20)

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

VERSION = "2.1.0b2"
VERSION = "2.1.0b3"
Original file line number Diff line number Diff line change
Expand Up @@ -539,19 +539,21 @@ async def get_history_item_ids(
responses in that conversation and contributes their
``history_item_ids + input_item_ids + output_item_ids``.
- Both may be set; results are concatenated in the same order.
- When over ``limit``, keeps the most recent N item IDs from the
resolved chain, preserving chronological order in the returned slice.

Deleted responses are skipped (matches the in-memory provider).

:param previous_response_id: Optional response id to chain history from.
:type previous_response_id: str | None
:param conversation_id: Optional conversation id to scope history lookup.
:type conversation_id: str | None
:param limit: Maximum number of history item ids to return.
:param limit: Maximum number of item IDs to return (most recent N).
:type limit: int
:keyword context: Platform context (accepted but unused —
matches :class:`InMemoryResponseProvider`).
:paramtype context: PlatformContext | None
:returns: List of history item ids (possibly empty).
:returns: List of item IDs from the resolved chain (possibly empty).
:rtype: list[str]
"""
del context
Expand Down Expand Up @@ -579,7 +581,9 @@ async def get_history_item_ids(

if limit <= 0:
return []
return resolved[:limit]
# Keep the most recent N item IDs from the resolved chain,
# preserving chronological order in the returned slice.
return resolved[-limit:]

# ------------------------------------------------------------------
# Internal helpers (must be called with self._lock held)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,22 @@ async def get_history_item_ids(
*,
context: PlatformContext | None = None,
) -> list[str]:
"""Resolve history item IDs from previous response and/or conversation scope.
"""Resolve item IDs from previous response and/or conversation scope.

Collects history item IDs from the previous response chain and/or
all responses within the given conversation, up to *limit*.
Collects history, input, and output item IDs from the previous
response chain and/or all responses within the given conversation.
When over *limit*, keeps the most recent N item IDs from the
resolved chain, preserving chronological order in the returned slice.

:param previous_response_id: Optional response ID to chain history from.
:type previous_response_id: str | None
:param conversation_id: Optional conversation ID to scope history lookup.
:type conversation_id: str | None
:param limit: Maximum number of history item IDs to return.
:param limit: Maximum number of item IDs to return (most recent N).
:type limit: int
:keyword context: Platform context for multi-tenant partitioning.
:paramtype context: ~azure.ai.agentserver.responses.PlatformContext | None
:returns: A list of history item IDs within the given scope.
:returns: A list of item IDs from the resolved chain.
:rtype: list[str]
"""
async with self._locked():
Expand All @@ -325,7 +327,9 @@ async def get_history_item_ids(

if limit <= 0:
return []
return resolved[:limit]
# Keep the most recent N item IDs from the resolved chain,
# preserving chronological order in the returned slice.
return resolved[-limit:]

async def create_execution(self, execution: ResponseExecution, *, ttl_seconds: int | None = None) -> None:
"""Create a new execution and replay container for ``execution.response_id``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ async def test_history_respects_limit(tmp_path: Path) -> None:
history_item_ids=["hist1", "hist2"],
)
ids = await provider.get_history_item_ids("r_prev", None, limit=3)
assert ids == ["hist1", "hist2", "in1"]
# Chronological order is oldest-first; truncation must keep the newest IDs.
assert ids == ["out1", "out2", "out3"]
# Non-positive limit returns empty.
ids_zero = await provider.get_history_item_ids("r_prev", None, limit=0)
assert ids_zero == []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ def test_history__respects_limit() -> None:

ids = asyncio.run(provider.get_history_item_ids("resp_lim", None, 3))
assert len(ids) == 3
# Chronological order is oldest-first; truncation must keep the newest IDs.
assert ids == ["in_lim_7", "in_lim_8", "in_lim_9"]
Comment thread
Hashim1999164 marked this conversation as resolved.


def test_history__zero_limit_returns_empty() -> None:
Expand Down
Loading