|
31 | 31 | AssistantMessage, |
32 | 32 | LLMChatCandidate, |
33 | 33 | LLMChatResponse, |
34 | | - ToolExecutionRecord, |
35 | | - ToolMessage, |
36 | 34 | ) |
37 | 35 |
|
38 | 36 |
|
@@ -861,32 +859,64 @@ def test_tool_func(x): |
861 | 859 | assert entry.tool_history[0].tool_call_id == "call_123" |
862 | 860 | assert entry.tool_history[0].tool_name == "TestToolFunc" |
863 | 861 |
|
864 | | - def test_update_agent_memory_and_history(self, basic_durable_agent): |
865 | | - """Test _update_agent_memory_and_history helper method.""" |
| 862 | + @pytest.mark.asyncio |
| 863 | + async def test_update_agent_memory_and_history(self, basic_durable_agent): |
| 864 | + """Test that memory and history are updated via run_tool activity.""" |
| 865 | + instance_id = "test-instance-123" |
866 | 866 |
|
867 | | - tool_msg = ToolMessage( |
868 | | - tool_call_id="call_123", name="test_tool", content="Tool result" |
| 867 | + # Set up instance using AgentWorkflowEntry |
| 868 | + entry = AgentWorkflowEntry( |
| 869 | + input_value="Test task", |
| 870 | + source="test_source", |
| 871 | + triggering_workflow_instance_id=None, |
| 872 | + workflow_instance_id=instance_id, |
| 873 | + workflow_name="AgenticWorkflow", |
| 874 | + status="RUNNING", |
| 875 | + messages=[], |
| 876 | + tool_history=[], |
869 | 877 | ) |
870 | | - tool_history_entry = ToolExecutionRecord( |
871 | | - tool_call_id="call_123", |
872 | | - tool_name="test_tool", |
873 | | - execution_result="tool_result", |
| 878 | + basic_durable_agent._state_model.instances[instance_id] = entry |
| 879 | + |
| 880 | + # Create a simple test tool |
| 881 | + from dapr_agents.tool.base import AgentTool |
| 882 | + |
| 883 | + def test_tool_func(x: str) -> str: |
| 884 | + """Test tool for verification.""" |
| 885 | + return "tool_result" |
| 886 | + |
| 887 | + test_tool = AgentTool.from_func(test_tool_func) |
| 888 | + basic_durable_agent.tools.append(test_tool) |
| 889 | + # Recreate tool executor with the new tool |
| 890 | + from dapr_agents.tool.executor import AgentToolExecutor |
| 891 | + |
| 892 | + basic_durable_agent.tool_executor = AgentToolExecutor( |
| 893 | + tools=list(basic_durable_agent.tools) |
874 | 894 | ) |
875 | 895 |
|
876 | | - # Mock the memory add_message method |
877 | | - with patch.object( |
878 | | - type(basic_durable_agent.memory), "add_message" |
879 | | - ) as mock_add_message: |
880 | | - basic_durable_agent._update_agent_memory_and_history( |
881 | | - tool_msg, tool_history_entry |
882 | | - ) |
| 896 | + # Mock save_state to prevent actual persistence |
| 897 | + with patch.object(basic_durable_agent, "save_state"): |
| 898 | + mock_ctx = Mock() |
883 | 899 |
|
884 | | - # Verify memory was updated |
885 | | - mock_add_message.assert_called_once_with(tool_msg) |
| 900 | + # Call run_tool activity which updates memory and history |
| 901 | + await basic_durable_agent.run_tool( |
| 902 | + mock_ctx, |
| 903 | + { |
| 904 | + "instance_id": instance_id, |
| 905 | + "tool_call": { |
| 906 | + "id": "call_123", |
| 907 | + "type": "function", |
| 908 | + "function": { |
| 909 | + "name": "TestToolFunc", |
| 910 | + "arguments": '{"x": "test"}', |
| 911 | + }, |
| 912 | + }, |
| 913 | + }, |
| 914 | + ) |
886 | 915 |
|
887 | 916 | # Verify agent-level tool_history was updated |
888 | 917 | assert len(basic_durable_agent.tool_history) == 1 |
889 | 918 | assert basic_durable_agent.tool_history[0].tool_call_id == "call_123" |
| 919 | + assert basic_durable_agent.tool_history[0].tool_name == "TestToolFunc" |
890 | 920 |
|
891 | 921 | def test_construct_messages_with_instance_history(self, basic_durable_agent): |
892 | 922 | """Test _construct_messages_with_instance_history helper method.""" |
|
0 commit comments