Skip to content

Commit a97c5b3

Browse files
authored
Merge branch 'main' into Extension-support-for-Client
2 parents 7f4ba58 + acdc0de commit a97c5b3

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,11 @@ async def test_on_message_send_non_blocking():
834834

835835
assert task is not None
836836
assert task.status.state == TaskState.completed
837+
assert (
838+
result.history
839+
and task.history
840+
and len(result.history) == len(task.history)
841+
)
837842

838843

839844
@pytest.mark.asyncio
@@ -855,7 +860,7 @@ async def test_on_message_send_limit_history():
855860
configuration=MessageSendConfiguration(
856861
blocking=True,
857862
accepted_output_modes=['text/plain'],
858-
history_length=0,
863+
history_length=1,
859864
),
860865
)
861866

@@ -866,17 +871,17 @@ async def test_on_message_send_limit_history():
866871
# verify that history_length is honored
867872
assert result is not None
868873
assert isinstance(result, Task)
869-
assert result.history is not None and len(result.history) == 0
874+
assert result.history is not None and len(result.history) == 1
870875
assert result.status.state == TaskState.completed
871876

872877
# verify that history is still persisted to the store
873878
task = await task_store.get(result.id)
874879
assert task is not None
875-
assert task.history is not None and len(task.history) > 0
880+
assert task.history is not None and len(task.history) > 1
876881

877882

878883
@pytest.mark.asyncio
879-
async def test_on_task_get_limit_history():
884+
async def test_on_get_task_limit_history():
880885
task_store = InMemoryTaskStore()
881886
push_store = InMemoryPushNotificationConfigStore()
882887

@@ -892,7 +897,8 @@ async def test_on_task_get_limit_history():
892897
parts=[Part(root=TextPart(text='Hi'))],
893898
),
894899
configuration=MessageSendConfiguration(
895-
blocking=True, accepted_output_modes=['text/plain']
900+
blocking=True,
901+
accepted_output_modes=['text/plain'],
896902
),
897903
)
898904

@@ -904,14 +910,14 @@ async def test_on_task_get_limit_history():
904910
assert isinstance(result, Task)
905911

906912
get_task_result = await request_handler.on_get_task(
907-
TaskQueryParams(id=result.id, history_length=0),
913+
TaskQueryParams(id=result.id, history_length=1),
908914
create_server_call_context(),
909915
)
910916
assert get_task_result is not None
911917
assert isinstance(get_task_result, Task)
912918
assert (
913919
get_task_result.history is not None
914-
and len(get_task_result.history) == 0
920+
and len(get_task_result.history) == 1
915921
)
916922

917923

0 commit comments

Comments
 (0)