Skip to content

Commit 076c7d6

Browse files
committed
fix: rewrite update_agent_memory_and_history test
Signed-off-by: Roberto Rodriguez <[email protected]>
1 parent ecae6d0 commit 076c7d6

File tree

1 file changed

+49
-19
lines changed

1 file changed

+49
-19
lines changed

tests/agents/durableagent/test_durable_agent.py

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
AssistantMessage,
3232
LLMChatCandidate,
3333
LLMChatResponse,
34-
ToolExecutionRecord,
35-
ToolMessage,
3634
)
3735

3836

@@ -861,32 +859,64 @@ def test_tool_func(x):
861859
assert entry.tool_history[0].tool_call_id == "call_123"
862860
assert entry.tool_history[0].tool_name == "TestToolFunc"
863861

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"
866866

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=[],
869877
)
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)
874894
)
875895

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()
883899

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+
)
886915

887916
# Verify agent-level tool_history was updated
888917
assert len(basic_durable_agent.tool_history) == 1
889918
assert basic_durable_agent.tool_history[0].tool_call_id == "call_123"
919+
assert basic_durable_agent.tool_history[0].tool_name == "TestToolFunc"
890920

891921
def test_construct_messages_with_instance_history(self, basic_durable_agent):
892922
"""Test _construct_messages_with_instance_history helper method."""

0 commit comments

Comments
 (0)