Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import asyncio
import logging

Expand Down Expand Up @@ -346,7 +346,7 @@

if isinstance(result, Task):
self._validate_task_id_match(task_id, result.id)
if params.configuration:
if params.configuration and params.configuration.history_length is not None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

While this change is intended to fix a null-pointer issue, the check for params.configuration.history_length is not None appears to be redundant. The apply_history_length function already includes a check for history_length is not None and safely handles the case where it is None by returning the task unmodified.

To avoid duplicating this logic and to keep the code cleaner, it would be better to rely on apply_history_length to handle this. This centralizes the logic for handling history_length values.

Suggested change
if params.configuration and params.configuration.history_length is not None:
if params.configuration:

result = apply_history_length(
result, params.configuration.history_length
)
Expand Down
38 changes: 38 additions & 0 deletions tests/server/request_handlers/test_default_request_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import asyncio
import contextlib
import logging
Expand Down Expand Up @@ -874,6 +874,44 @@
assert task is not None
assert task.history is not None and len(task.history) > 0

@pytest.mark.asyncio
async def test_on_message_send_limit_history_non_as_no_limit():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

This is a great test case to ensure that a None value for history_length doesn't truncate the history. For better readability, consider renaming the test to be more descriptive of its purpose. For example: test_on_message_send_with_none_history_length_is_not_limited.

Suggested change
async def test_on_message_send_limit_history_non_as_no_limit():
async def test_on_message_send_with_none_history_length_is_not_limited():

task_store = InMemoryTaskStore()
push_store = InMemoryPushNotificationConfigStore()

request_handler = DefaultRequestHandler(
agent_executor=HelloAgentExecutor(),
task_store=task_store,
push_config_store=push_store,
)
params = MessageSendParams(
message=Message(
role=Role.user,
message_id='msg_push',
parts=[Part(root=TextPart(text='Hi'))],
),
configuration=MessageSendConfiguration(
blocking=True,
accepted_output_modes=['text/plain'],
history_length=None
),
)

result = await request_handler.on_message_send(
params, create_server_call_context()
)

# verify that history_length is honored
assert result is not None
assert isinstance(result, Task)
assert result.history is not None and len(result.history) > 0
assert result.status.state == TaskState.completed

# verify that history is still persisted to the store
task = await task_store.get(result.id)
assert task is not None
assert task.history is not None and len(task.history) > 0


@pytest.mark.asyncio
async def test_on_task_get_limit_history():
Expand Down
Loading