Skip to content

Conversation

pgrayy
Copy link
Member

@pgrayy pgrayy commented Oct 16, 2025

Description

Support interrupts in decorated tool definitions. This is a follow up to #987.

A few notes:

  • Users must pass in tool_context to run interrupts.
  • Consequently, Python module tools are not interruptible. Only decorated tools are interruptible.

Usage

from strands import Agent, tool
from strands.types.tools import ToolContext

@tool(context=True)
def my_tool(tool_context: ToolContext) -> str:
    return tool_context.interrupt("test_interrupt", reason="my reason")

agent = Agent(tools=[my_tool], callback_handler=None)

result = agent("Call my tool")
assert result.stop_reason == "interrupt"
assert len(result.interrupts) == 1
interrupt = result.interrupts[0]
response = {"interruptResponse": {"interruptId": interrupt.id, "response": f"my response to {interrupt.reason}"}}

result = agent([response])
assert result.stop_reason == "end_turn"
print(f"MESSAGE: {result.message}")

"""
Output:
MESSAGE: {'role': 'assistant', 'content': [{'text': 'The tool has been called successfully and returned the response: "my response to my reason".'}]}
"""

Related Issues

#204

Documentation PR

Will release docs for single agent interrupts after this PR is merged.

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare: Wrote new unit tests.
  • Ran hatch test tests_integ/interrupt/*.py: Wrote new integ tests.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pgrayy pgrayy marked this pull request as ready for review October 16, 2025 19:56
@pgrayy pgrayy merged commit 26862e4 into strands-agents:main Oct 17, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants