Skip to content

Commit e9a39aa

Browse files
[agentserver-responses] Keep newest history item IDs when applying limit (#48560)
* Keep newest history item IDs when applying limit get_history_item_ids in the in-memory and file response stores used resolved[:limit], which dropped recent turns. Slice from the end so conversation history keeps the newest N items. Fixes #48514. * Keep newest history ids under the limit and fix changelog * Restore an unreleased changelog section for the history id limit fix. Keep 2.1.0b1 as previously released and name FileResponseStore in the 2.1.0b2 notes. * Bump azure-ai-agentserver-responses to 2.1.0b2 so Analyze validates the unreleased changelog. * Clarify that limit keeps newest item IDs from the resolved chain. --------- Co-authored-by: Shiva S <shivakishore14@gmail.com>
1 parent bc99dcd commit e9a39aa

6 files changed

Lines changed: 28 additions & 11 deletions

File tree

‎sdk/agentserver/azure-ai-agentserver-responses/CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 2.1.0b3 (Unreleased)
4+
5+
### Bugs Fixed
6+
7+
- `get_history_item_ids` on `InMemoryResponseProvider` and `FileResponseStore` now keeps the newest item IDs when applying `limit`. (#48514)
8+
39
## 2.1.0b2 (2026-08-20)
410

511
### Bugs Fixed

‎sdk/agentserver/azure-ai-agentserver-responses/azure/ai/agentserver/responses/_version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# Copyright (c) Microsoft Corporation. All rights reserved.
55
# ---------------------------------------------------------
66

7-
VERSION = "2.1.0b2"
7+
VERSION = "2.1.0b3"

‎sdk/agentserver/azure-ai-agentserver-responses/azure/ai/agentserver/responses/store/_file.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,21 @@ async def get_history_item_ids(
539539
responses in that conversation and contributes their
540540
``history_item_ids + input_item_ids + output_item_ids``.
541541
- Both may be set; results are concatenated in the same order.
542+
- When over ``limit``, keeps the most recent N item IDs from the
543+
resolved chain, preserving chronological order in the returned slice.
542544
543545
Deleted responses are skipped (matches the in-memory provider).
544546
545547
:param previous_response_id: Optional response id to chain history from.
546548
:type previous_response_id: str | None
547549
:param conversation_id: Optional conversation id to scope history lookup.
548550
:type conversation_id: str | None
549-
:param limit: Maximum number of history item ids to return.
551+
:param limit: Maximum number of item IDs to return (most recent N).
550552
:type limit: int
551553
:keyword context: Platform context (accepted but unused —
552554
matches :class:`InMemoryResponseProvider`).
553555
:paramtype context: PlatformContext | None
554-
:returns: List of history item ids (possibly empty).
556+
:returns: List of item IDs from the resolved chain (possibly empty).
555557
:rtype: list[str]
556558
"""
557559
del context
@@ -579,7 +581,9 @@ async def get_history_item_ids(
579581

580582
if limit <= 0:
581583
return []
582-
return resolved[:limit]
584+
# Keep the most recent N item IDs from the resolved chain,
585+
# preserving chronological order in the returned slice.
586+
return resolved[-limit:]
583587

584588
# ------------------------------------------------------------------
585589
# Internal helpers (must be called with self._lock held)

‎sdk/agentserver/azure-ai-agentserver-responses/azure/ai/agentserver/responses/store/_memory.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,22 @@ async def get_history_item_ids(
286286
*,
287287
context: PlatformContext | None = None,
288288
) -> list[str]:
289-
"""Resolve history item IDs from previous response and/or conversation scope.
289+
"""Resolve item IDs from previous response and/or conversation scope.
290290
291-
Collects history item IDs from the previous response chain and/or
292-
all responses within the given conversation, up to *limit*.
291+
Collects history, input, and output item IDs from the previous
292+
response chain and/or all responses within the given conversation.
293+
When over *limit*, keeps the most recent N item IDs from the
294+
resolved chain, preserving chronological order in the returned slice.
293295
294296
:param previous_response_id: Optional response ID to chain history from.
295297
:type previous_response_id: str | None
296298
:param conversation_id: Optional conversation ID to scope history lookup.
297299
:type conversation_id: str | None
298-
:param limit: Maximum number of history item IDs to return.
300+
:param limit: Maximum number of item IDs to return (most recent N).
299301
:type limit: int
300302
:keyword context: Platform context for multi-tenant partitioning.
301303
:paramtype context: ~azure.ai.agentserver.responses.PlatformContext | None
302-
:returns: A list of history item IDs within the given scope.
304+
:returns: A list of item IDs from the resolved chain.
303305
:rtype: list[str]
304306
"""
305307
async with self._locked():
@@ -325,7 +327,9 @@ async def get_history_item_ids(
325327

326328
if limit <= 0:
327329
return []
328-
return resolved[:limit]
330+
# Keep the most recent N item IDs from the resolved chain,
331+
# preserving chronological order in the returned slice.
332+
return resolved[-limit:]
329333

330334
async def create_execution(self, execution: ResponseExecution, *, ttl_seconds: int | None = None) -> None:
331335
"""Create a new execution and replay container for ``execution.response_id``.

‎sdk/agentserver/azure-ai-agentserver-responses/tests/unit/test_file_response_store_parity.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ async def test_history_respects_limit(tmp_path: Path) -> None:
327327
history_item_ids=["hist1", "hist2"],
328328
)
329329
ids = await provider.get_history_item_ids("r_prev", None, limit=3)
330-
assert ids == ["hist1", "hist2", "in1"]
330+
# Chronological order is oldest-first; truncation must keep the newest IDs.
331+
assert ids == ["out1", "out2", "out3"]
331332
# Non-positive limit returns empty.
332333
ids_zero = await provider.get_history_item_ids("r_prev", None, limit=0)
333334
assert ids_zero == []

‎sdk/agentserver/azure-ai-agentserver-responses/tests/unit/test_in_memory_provider_crud.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ def test_history__respects_limit() -> None:
374374

375375
ids = asyncio.run(provider.get_history_item_ids("resp_lim", None, 3))
376376
assert len(ids) == 3
377+
# Chronological order is oldest-first; truncation must keep the newest IDs.
378+
assert ids == ["in_lim_7", "in_lim_8", "in_lim_9"]
377379

378380

379381
def test_history__zero_limit_returns_empty() -> None:

0 commit comments

Comments
 (0)