Skip to content

feat: add AbortSignal support to Agent and BedrockModel#618

Open
jsamuel1 wants to merge 2 commits intostrands-agents:mainfrom
jsamuel1:feat/abort-signal
Open

feat: add AbortSignal support to Agent and BedrockModel#618
jsamuel1 wants to merge 2 commits intostrands-agents:mainfrom
jsamuel1:feat/abort-signal

Conversation

@jsamuel1
Copy link
Contributor

@jsamuel1 jsamuel1 commented Mar 9, 2026

Summary

Plumb AbortSignal through the invocation stack so callers can cancel in-flight requests:

  • InvokeOptions.signal passed to Agent.invokeModel
  • StreamOptions.signal passed to Model.stream
  • BedrockModel forwards signal as abortSignal to AWS SDK client

Usage

const controller = new AbortController()
const result = await agent.invoke('Hello', { signal: controller.signal })

// Cancel from another context:
controller.abort()

Follow-up needed after multi-agent PRs merge

Once the swarm (#587) and graph (#594) multi-agent PRs land, abort signal propagation should be added to both:

  • Swarm: Currently accepts signal?: AbortSignal in SwarmInvokeOptions and checks signal.aborted at the top of the loop, but does NOT forward the signal to node.agent.stream(input). It should pass { signal: options.signal } to each agent invocation so in-flight model calls are actually cancelled.
  • Graph: Has no abort signal support at all. Should accept a signal option, check it between node executions, and forward it to each agent invocation.

@jsamuel1
Copy link
Contributor Author

jsamuel1 commented Mar 9, 2026

Note: AbortSignal threading through Graph (passing signal down to node.stream()) depends on this PR's changes to Node.stream() accepting a signal parameter. The Graph PR (#594) already adds signal? to the public invoke()/stream() signatures per MultiAgentBase, but defers the internal threading until this PR merges.

Plumb AbortSignal through the invocation stack so callers can
cancel in-flight requests:

- InvokeOptions.signal passed to Agent.invokeModel
- StreamOptions.signal passed to Model.stream
- BedrockModel forwards signal as abortSignal to AWS SDK client

---
Prompt: put abort signal changes into a new PR based off upstream
main
Thread AbortSignal through the multiagent orchestration layer:

- Add MultiAgentOptions with signal to MultiAgent interface
- Swarm checks signal.aborted before each handoff step
- Graph checks signal.aborted before launching new nodes
- Signal forwarded through Node.stream() → handle() →
  agent.stream() so running agents are cancelled
- Return CANCELLED status when signal is aborted
- Guard Swarm._resolveContent for empty results

---
Prompt: work out how AbortSignal should work with multiagent
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.

1 participant