feat: support abort parameter in runner, agent, model, tool and processors#234
Merged
kalenkevich merged 3 commits intomainfrom Apr 17, 2026
Merged
feat: support abort parameter in runner, agent, model, tool and processors#234kalenkevich merged 3 commits intomainfrom
kalenkevich merged 3 commits intomainfrom
Conversation
e61d57c to
c47ac79
Compare
4c48229 to
c424a83
Compare
ScottMansfield
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Description of Change
This PR implements comprehensive support for
AbortSignalacross the core components of the ADK TS. This allows for the graceful cancellation of long-running agent operations, streaming model responses, and tool executions, resolving issues with unhandled promise rejections or runaway executions when a task is no longer needed.Rationale
Allowing execution to be aborted at any level is critical for resource management and user experience. With these changes, a cancellation triggered by a user or timeout will propagate down to stop active LLM generations and inform running tools, preventing wasted resources and unhandled promise rejections.
Runner
Runner: AddedabortSignalto parameters forrunAsync. Added guards checkingabortSignal.abortedat critical lifecycle points (e.g., before session fetching, after plugin executions, and within event streaming loops) to ensure quick termination.Agents
InvocationContext: Added optionalabortSignaltoInvocationContextParams. Registered an event listener on the signal to automatically setthis.endInvocation = truewhen triggered.LlmAgent: Added checks forcontext.abortSignal?.abortedwithin the main execution loops and before yielding events. Passed the abort signal down to the model call.LoopAgent&ParallelAgent: Added abort checks within their iteration/merging loops to terminate sub-agent execution early if requested.Models
BaseLlm: UpdatedgenerateContentAsyncsignature to accept an optionalabortSignal.Gemini(Google LLM): Propagated theabortSignalto the underlying Google GenAI SDK by settingllmRequest.config.abortSignal.Tools
AgentTool: Passed thetoolContext.abortSignalinto the sub-agent runner and added early return checks.MCPTool: Passed the abort signal to the MCP client'scallToolmethod options.Other
stream_test.tsto account for potential latency during testing.Testing Plan
Unit Tests:
Summary of passed npm test results:
core/test/runner/streaming_runner_test.tspassed with 13 tests.llm_agent_test.tsandgoogle_llm_test.tswere also verified to contain the new abort logicChecklist