@@ -799,43 +799,67 @@ async def test_create_tool_message_objects(self, basic_durable_agent):
799799 assert entry .tool_history [0 ].tool_name == "test_tool"
800800 assert entry .tool_history [0 ].execution_result == "tool_result"
801801
802- def test_append_tool_message_to_instance (self , basic_durable_agent ):
803- """Test _append_tool_message_to_instance helper method."""
802+ @pytest .mark .asyncio
803+ async def test_append_tool_message_to_instance (self , basic_durable_agent ):
804+ """Test that tool messages are appended to instance via run_tool activity."""
804805 instance_id = "test-instance-123"
805806
806- # Set up instance
807- basic_durable_agent .state ["instances" ][instance_id ] = {
808- "input" : "Test task" ,
809- "source" : "test_source" ,
810- "triggering_workflow_instance_id" : None ,
811- "workflow_instance_id" : instance_id ,
812- "workflow_name" : "AgenticWorkflow" ,
813- "status" : "RUNNING" ,
814- "messages" : [],
815- "tool_history" : [],
816- "end_time" : None ,
817- "trace_context" : None ,
818- }
807+ # Set up instance using AgentWorkflowEntry
808+ entry = AgentWorkflowEntry (
809+ input_value = "Test task" ,
810+ source = "test_source" ,
811+ triggering_workflow_instance_id = None ,
812+ workflow_instance_id = instance_id ,
813+ workflow_name = "AgenticWorkflow" ,
814+ status = "RUNNING" ,
815+ messages = [],
816+ tool_history = [],
817+ )
818+ basic_durable_agent ._state_model .instances [instance_id ] = entry
819819
820- # Create mock objects
820+ # Create a simple test tool
821+ from dapr_agents .tool .base import AgentTool
821822
822- agent_msg = AgentWorkflowMessage (role = "assistant" , content = "Tool result" )
823- tool_history_entry = ToolExecutionRecord (
824- tool_call_id = "call_123" ,
825- tool_name = "test_tool" ,
826- execution_result = "tool_result" ,
827- )
823+ def test_tool_func (x ):
824+ """Test tool for verification."""
825+ return "tool_result"
826+
827+ test_tool = AgentTool .from_func (test_tool_func )
828+ basic_durable_agent .tools .append (test_tool )
829+ # Recreate tool executor with the new tool
830+ from dapr_agents .tool .executor import AgentToolExecutor
828831
829- basic_durable_agent ._append_tool_message_to_instance (
830- instance_id , agent_msg , tool_history_entry
832+ basic_durable_agent .tool_executor = AgentToolExecutor (
833+ tools = list ( basic_durable_agent . tools )
831834 )
832835
833- # Verify instance was updated
834- instance_data = basic_durable_agent .state ["instances" ][instance_id ]
835- assert len (instance_data ["messages" ]) == 1
836- assert instance_data ["messages" ][0 ]["role" ] == "assistant"
837- assert len (instance_data ["tool_history" ]) == 1
838- assert instance_data ["tool_history" ][0 ]["tool_call_id" ] == "call_123"
836+ # Mock save_state to prevent actual persistence
837+ with patch .object (basic_durable_agent , "save_state" ):
838+ mock_ctx = Mock ()
839+
840+ # Call run_tool activity which appends messages and tool_history
841+ await basic_durable_agent .run_tool (
842+ mock_ctx ,
843+ {
844+ "instance_id" : instance_id ,
845+ "tool_call" : {
846+ "id" : "call_123" ,
847+ "type" : "function" ,
848+ "function" : {
849+ "name" : "TestToolFunc" , # Tool name is CamelCase version of function name
850+ "arguments" : '{"x": "test"}' , # Pass string to match type hint default
851+ },
852+ },
853+ },
854+ )
855+
856+ # Verify entry was updated with message and tool_history
857+ assert len (entry .messages ) == 1
858+ assert entry .messages [0 ].role == "tool"
859+ assert entry .messages [0 ].id == "call_123" # AgentWorkflowMessage uses 'id'
860+ assert len (entry .tool_history ) == 1
861+ assert entry .tool_history [0 ].tool_call_id == "call_123"
862+ assert entry .tool_history [0 ].tool_name == "TestToolFunc"
839863
840864 def test_update_agent_memory_and_history (self , basic_durable_agent ):
841865 """Test _update_agent_memory_and_history helper method."""
0 commit comments