Repository navigation
feat(bidi): support cancellation from custom tools - #4664
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Assessment: Approve (with minor suggestions) Clean, well-scoped change that replaces the deprecated dual stop mechanism ( Review Categories
Nicely simplified—removing the deprecation branching makes the stop path much easier to follow. |
Documentation Preview ReadyYour documentation preview has been successfully deployed! Changed pages:
Updated at: 2026-09-29T15:44:03.675Z |
|
Assessment: Comment (mostly Approve — one process item to confirm) This is a solid rework of the earlier revision: replacing the name-based / Review Categories
Nice simplification — the single |
Keep upstream's reconnect-result delivery behavior and retain the cancellation and shared-state tests.
|
Assessment: Comment (mostly Approve — one process item remains) Re-reviewed after the latest push. This revision improves on the prior one and resolves my concurrency feedback. The stop mechanism is now a clean, single group-level checkpoint, the deprecated Review Categories
The single group-level |
Description
Bidi tools need a supported way to end conversations without a packaged tool or special handling of its name.
BidiAgent.cancel()provides the same API asAgent.cancel(), and exposing it on Python'sLocalAgentmakes it available to shared tools and hooks.A documented
end_conversationexample replaces the packagedstop_conversationtool. This avoids coupling Bidi to the experimental generic stop tool or the deprecatedstrands_toolspackage.request_stateremains initialized for compatibility with shared tools; using it for shutdown is discouraged.Public API Changes
BidiAgent.cancel()is synchronous, thread-safe, and idempotent. Cancellation currently takes effect only after a tool group completes. Requests from other contexts remain pending until then.run()handles cleanup, and the agent can be reused.Breaking Changes
Remove
strands.experimental.bidi.tools.stop_conversation. Define a custom tool that callsagent.cancel()instead. Settingrequest_state["stop_event_loop"]no longer stops Bidi.Related Issues
None.
Documentation PR
Included in this PR under
site/.Type of Change
Breaking change
Testing
hatch run prepareVerified cancellation through a custom tool on a live OpenAI Realtime connection using a generic system prompt. The tool result was recorded and
run()returned cleanly. Reused the same agent and repeated tool-triggered cancellation successfully.Ran the Bidi agent and loop unit suites on Python 3.10 and 3.14 after the final test refinements. Local checks cover cancellation, retry suppression, pending requests, cleanup, reuse, and the shared typing contract.
After syncing with upstream/main, all 829 Bidi and tool-executor unit tests passed. All 20 Bidi integration tests passed on Python 3.12 with Nova in
us-west-2, alongside Google and OpenAI. Lint, formatting, and type checks passed.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.