Skip to content

Commit 0340ea8

Browse files
committed
Align limiting history with what the spec currently defines
1 parent 265fd33 commit 0340ea8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/a2a/utils/task.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ def apply_history_length(task: Task, history_length: int | None) -> Task:
8383
A new task object with limited history
8484
"""
8585
# Apply historyLength parameter if specified
86-
if history_length is not None and task.history:
86+
if history_length is not None and history_length > 0 and task.history:
8787
# Limit history to the most recent N messages
88-
limited_history = (
89-
task.history[-history_length:] if history_length > 0 else []
90-
)
88+
limited_history = task.history[-history_length:]
9189
# Create a new task instance with limited history
9290
return task.model_copy(update={'history': limited_history})
9391

tests/server/request_handlers/test_default_request_handler.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ async def test_on_message_send_limit_history():
855855
configuration=MessageSendConfiguration(
856856
blocking=True,
857857
accepted_output_modes=['text/plain'],
858-
history_length=0,
858+
history_length=1,
859859
),
860860
)
861861

@@ -866,13 +866,13 @@ async def test_on_message_send_limit_history():
866866
# verify that history_length is honored
867867
assert result is not None
868868
assert isinstance(result, Task)
869-
assert result.history is not None and len(result.history) == 0
869+
assert result.history is not None and len(result.history) == 1
870870
assert result.status.state == TaskState.completed
871871

872872
# verify that history is still persisted to the store
873873
task = await task_store.get(result.id)
874874
assert task is not None
875-
assert task.history is not None and len(task.history) > 0
875+
assert task.history is not None and len(task.history) > 1
876876

877877

878878
@pytest.mark.asyncio
@@ -892,7 +892,8 @@ async def test_on_task_get_limit_history():
892892
parts=[Part(root=TextPart(text='Hi'))],
893893
),
894894
configuration=MessageSendConfiguration(
895-
blocking=True, accepted_output_modes=['text/plain']
895+
blocking=True,
896+
accepted_output_modes=['text/plain'],
896897
),
897898
)
898899

@@ -904,14 +905,14 @@ async def test_on_task_get_limit_history():
904905
assert isinstance(result, Task)
905906

906907
get_task_result = await request_handler.on_get_task(
907-
TaskQueryParams(id=result.id, history_length=0),
908+
TaskQueryParams(id=result.id, history_length=1),
908909
create_server_call_context(),
909910
)
910911
assert get_task_result is not None
911912
assert isinstance(get_task_result, Task)
912913
assert (
913914
get_task_result.history is not None
914-
and len(get_task_result.history) == 0
915+
and len(get_task_result.history) == 1
915916
)
916917

917918

0 commit comments

Comments
 (0)