@@ -836,6 +836,85 @@ async def test_on_message_send_non_blocking():
836836 assert task .status .state == TaskState .completed
837837
838838
839+ @pytest .mark .asyncio
840+ async def test_on_message_send_limit_history ():
841+ task_store = InMemoryTaskStore ()
842+ push_store = InMemoryPushNotificationConfigStore ()
843+
844+ request_handler = DefaultRequestHandler (
845+ agent_executor = HelloAgentExecutor (),
846+ task_store = task_store ,
847+ push_config_store = push_store ,
848+ )
849+ params = MessageSendParams (
850+ message = Message (
851+ role = Role .user ,
852+ message_id = 'msg_push' ,
853+ parts = [Part (root = TextPart (text = 'Hi' ))],
854+ ),
855+ configuration = MessageSendConfiguration (
856+ blocking = True ,
857+ accepted_output_modes = ['text/plain' ],
858+ history_length = 0 ,
859+ ),
860+ )
861+
862+ result = await request_handler .on_message_send (
863+ params , create_server_call_context ()
864+ )
865+
866+ # verify that history_length is honored
867+ assert result is not None
868+ assert isinstance (result , Task )
869+ assert result .history is not None and len (result .history ) == 0
870+ assert result .status .state == TaskState .completed
871+
872+ # verify that history is still persisted to the store
873+ task = await task_store .get (result .id )
874+ assert task is not None
875+ assert task .history is not None and len (task .history ) > 0
876+
877+
878+ @pytest .mark .asyncio
879+ async def test_on_task_get_limit_history ():
880+ task_store = InMemoryTaskStore ()
881+ push_store = InMemoryPushNotificationConfigStore ()
882+
883+ request_handler = DefaultRequestHandler (
884+ agent_executor = HelloAgentExecutor (),
885+ task_store = task_store ,
886+ push_config_store = push_store ,
887+ )
888+ params = MessageSendParams (
889+ message = Message (
890+ role = Role .user ,
891+ message_id = 'msg_push' ,
892+ parts = [Part (root = TextPart (text = 'Hi' ))],
893+ ),
894+ configuration = MessageSendConfiguration (
895+ blocking = True , accepted_output_modes = ['text/plain' ]
896+ ),
897+ )
898+
899+ result = await request_handler .on_message_send (
900+ params , create_server_call_context ()
901+ )
902+
903+ assert result is not None
904+ assert isinstance (result , Task )
905+
906+ get_task_result = await request_handler .on_get_task (
907+ TaskQueryParams (id = result .id , history_length = 0 ),
908+ create_server_call_context (),
909+ )
910+ assert get_task_result is not None
911+ assert isinstance (get_task_result , Task )
912+ assert (
913+ get_task_result .history is not None
914+ and len (get_task_result .history ) == 0
915+ )
916+
917+
839918@pytest .mark .asyncio
840919async def test_on_message_send_interrupted_flow ():
841920 """Test on_message_send when flow is interrupted (e.g., auth_required)."""
0 commit comments