Skip to content

feat: support abort parameter in runner, agent, model, tool and processors#234

Merged
kalenkevich merged 3 commits intomainfrom
feat/abort_support
Apr 17, 2026
Merged

feat: support abort parameter in runner, agent, model, tool and processors#234
kalenkevich merged 3 commits intomainfrom
feat/abort_support

Conversation

@kalenkevich
Copy link
Copy Markdown
Collaborator

@kalenkevich kalenkevich commented Apr 3, 2026

Please ensure you have read the contribution guide before creating a pull request.

Description of Change

This PR implements comprehensive support for AbortSignal across 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: Added abortSignal to parameters for runAsync. Added guards checking abortSignal.aborted at critical lifecycle points (e.g., before session fetching, after plugin executions, and within event streaming loops) to ensure quick termination.

Agents

  • InvocationContext: Added optional abortSignal to InvocationContextParams. Registered an event listener on the signal to automatically set this.endInvocation = true when triggered.
  • LlmAgent: Added checks for context.abortSignal?.aborted within 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: Updated generateContentAsync signature to accept an optional abortSignal.
  • Gemini (Google LLM): Propagated the abortSignal to the underlying Google GenAI SDK by setting llmRequest.config.abortSignal.

Tools

  • AgentTool: Passed the toolContext.abortSignal into the sub-agent runner and added early return checks.
  • MCPTool: Passed the abort signal to the MCP client's callTool method options.

Other

  • Increased timeout in stream_test.ts to account for potential latency during testing.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary of passed npm test results:

  • core/test/runner/streaming_runner_test.ts passed with 13 tests.
  • Tests in llm_agent_test.ts and google_llm_test.ts were also verified to contain the new abort logic

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Comment thread core/src/agents/llm_agent.ts
Comment thread core/src/agents/llm_agent.ts
Comment thread core/src/tools/function_tool.ts Outdated
@kalenkevich kalenkevich force-pushed the feat/abort_support branch 7 times, most recently from e61d57c to c47ac79 Compare April 7, 2026 23:25
Comment thread core/src/agents/base_agent.ts
@kalenkevich kalenkevich merged commit 1614f36 into main Apr 17, 2026
7 checks passed
@kalenkevich kalenkevich deleted the feat/abort_support branch April 17, 2026 19:18
@kalenkevich kalenkevich mentioned this pull request Apr 16, 2026
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.

3 participants