fix: handle LangGraph interrupts in human tool

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-11 11:06:49 +00:00
parent 409892d65f
commit 364a31ca8b
5 changed files with 114 additions and 0 deletions

View File

@@ -85,6 +85,38 @@ def test_random_number_tool_schema():
)
def test_tool_usage_interrupt_handling():
"""Test that tool usage properly propagates LangGraph interrupts."""
from unittest.mock import patch, MagicMock
class InterruptingTool(BaseTool):
name: str = "interrupt_test"
description: str = "A tool that raises LangGraph interrupts"
def _run(self, query: str) -> str:
raise type('Interrupt', (Exception,), {})("test interrupt")
tool = InterruptingTool()
tool_usage = ToolUsage(
tools_handler=MagicMock(),
tools=[tool],
original_tools=[tool],
tools_description="Sample tool for testing",
tools_names="interrupt_test",
task=MagicMock(),
function_calling_llm=MagicMock(),
agent=MagicMock(),
action=MagicMock(),
)
# Test that interrupt is propagated
with pytest.raises(Exception) as exc_info:
tool_usage.use(
ToolCalling(tool_name="interrupt_test", arguments={"query": "test"}, log="test"),
"test"
)
assert "test interrupt" in str(exc_info.value)
def test_tool_usage_render():
tool = RandomNumberTool()