Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/strands/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from ..tools.registry import ToolRegistry
from ..tools.structured_output._structured_output_context import StructuredOutputContext
from ..tools.watcher import ToolWatcher
from ..types._events import AgentResultEvent, InitEventLoopEvent, ModelStreamChunkEvent, TypedEvent
from ..types._events import AgentResultEvent, InitEventLoopEvent, ModelStreamChunkEvent, ToolInterruptEvent, TypedEvent
from ..types.agent import AgentInput
from ..types.content import ContentBlock, Message, Messages
from ..types.exceptions import ContextWindowOverflowException
Expand Down Expand Up @@ -166,7 +166,8 @@ def caller(

async def acall() -> ToolResult:
async for event in ToolExecutor._stream(self._agent, tool_use, tool_results, invocation_state):
_ = event
if isinstance(event, ToolInterruptEvent):
raise RuntimeError("cannot raise interrupt in direct tool call")

return tool_results[0]

Expand Down
14 changes: 13 additions & 1 deletion tests/strands/agent/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,19 @@ def test_agent_structured_output_interrupt(user):
agent.structured_output(type(user), "invalid")


def test_agent_tool_caller_interrupt(user):
def test_agent_tool_caller_interrupt():
@strands.tool(context=True)
def test_tool(tool_context):
tool_context.interrupt("test-interrupt")

agent = Agent(tools=[test_tool])

exp_message = r"cannot raise interrupt in direct tool call"
with pytest.raises(RuntimeError, match=exp_message):
agent.tool.test_tool(agent=agent)


def test_agent_tool_caller_interrupt_activated():
agent = Agent()
agent._interrupt_state.activated = True

Expand Down
Loading