Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 6 additions & 3 deletions src/strands/hooks/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
via hook provider objects.
"""

import logging
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Generator, Generic, Protocol, Type, TypeVar

Expand All @@ -15,6 +16,8 @@
if TYPE_CHECKING:
from ..agent import Agent

logger = logging.getLogger(__name__)


@dataclass
class BaseHookEvent:
Expand Down Expand Up @@ -219,9 +222,9 @@ def invoke_callbacks(self, event: TInvokeEvent) -> tuple[TInvokeEvent, list[Inte
except InterruptException as exception:
interrupt = exception.interrupt
if interrupt.name in interrupts:
raise ValueError(
f"interrupt_name=<{interrupt.name}> | interrupt name used more than once"
) from exception
message = f"interrupt_name=<{interrupt.name}> | interrupt name used more than once"
logger.error(message)
raise ValueError(message) from exception

# Each callback is allowed to raise their own interrupt.
interrupts[interrupt.name] = interrupt
Expand Down
8 changes: 8 additions & 0 deletions src/strands/multiagent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ async def _execute_node(self, node: GraphNode, invocation_state: dict[str, Any])
else:
agent_response = await node.executor.invoke_async(node_input, invocation_state=invocation_state)

if agent_response.stop_reason == "interrupt":
node.executor.messages.pop() # remove interrupted tool use message
node.executor._interrupt_state.deactivate()

raise RuntimeError(
"user raised interrupt from agent | interrupts are not yet supported in graphs"
)

# Extract metrics from agent response
usage = Usage(inputTokens=0, outputTokens=0, totalTokens=0)
metrics = Metrics(latencyMs=0)
Expand Down
6 changes: 6 additions & 0 deletions src/strands/multiagent/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ async def _execute_node(
node.reset_executor_state()
result = await node.executor.invoke_async(node_input, invocation_state=invocation_state)

if result.stop_reason == "interrupt":
node.executor.messages.pop() # remove interrupted tool use message
node.executor._interrupt_state.deactivate()

raise RuntimeError("user raised interrupt from agent | interrupts are not yet supported in swarms")

execution_time = round((time.time() - start_time) * 1000)

# Create NodeResult
Expand Down