feat(core): add LocalSessionInvocation and SubagentProtocols#26665
feat(core): add LocalSessionInvocation and SubagentProtocols#26665adamfweidman wants to merge 4 commits intomainfrom
Conversation
…ind AgentProtocol Introduces LocalSubagentProtocol (implements AgentProtocol) and LocalSubagentSession (extends AgentSession) to wrap the existing LocalAgentExecutor behind the unified agent session interface. - Translates SubagentActivityEvent callbacks into typed AgentEvent emissions - Maps AgentTerminateMode to StreamEndReason for proper stream lifecycle - Exposes getResult() for executor output retrieval - Supports external AbortSignal propagation - Accepts optional rawActivityCallback for rich UI display - Includes comprehensive test suite (776 lines) Part of the AgentSession unification effort to expose all agents (interactive, non-interactive, subagents) through the same contract. Bug: b/22700
… invocation New invocation class that delegates to LocalSubagentSession instead of directly using LocalAgentExecutor. Existing LocalSubagentInvocation is untouched — this will be wired in behind a feature flag in a later PR.
…ntProtocol Introduces RemoteSubagentProtocol (implements AgentProtocol) and RemoteSubagentSession (extends AgentSession) to wrap the A2A remote agent streaming client behind the unified agent session interface. - Manages persistent session state (contextId, taskId) across sends - Handles auth setup via A2AAuthProviderFactory per agent definition - Uses A2AResultReassembler for response chunk processing - Maps A2A streaming events to typed AgentEvent emissions - Exposes getResult() and getLatestProgress() for result retrieval - Guards against concurrent send() with clear error messaging - Includes comprehensive test suite (776 lines) Part of the AgentSession unification effort to expose all agents (interactive, non-interactive, subagents) through the same contract. Bug: b/22700
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new infrastructure for managing subagent sessions, specifically adding LocalSessionInvocation for local agents and defining standardized protocols to encapsulate agent execution logic. These changes are part of the broader ADK integration effort to unify how different agent types interact with the core system, ensuring consistent handling of streaming activity and execution results. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Hi @adamfweidman, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
There was a problem hiding this comment.
Code Review
This pull request introduces LocalSessionInvocation and RemoteSubagentProtocol to manage local and remote subagent executions via session-based protocols, including progress streaming and abort handling. Comprehensive unit tests for these new components are also added. Feedback identifies that LocalSessionInvocation lacks nullish checks when accessing activity data, which could display 'undefined' in the UI, and notes that THOUGHT_CHUNK updates should append content instead of overwriting it to maintain the full thought history.
|
|
||
| switch (activity.type) { | ||
| case 'THOUGHT_CHUNK': { | ||
| const text = String(activity.data['text']); |
There was a problem hiding this comment.
Accessing properties of activity.data using String() without a nullish check will result in the literal string 'undefined' or 'null' being displayed in the UI. Per repository rules, you should handle the undefined case with a default and trim the string to ensure whitespace-only values do not result in uninformative messages. This pattern should also be corrected for other fields like 'name' (lines 155, 181), 'displayName' (line 157), and 'error' (line 201).
| const text = String(activity.data['text']); | |
| const text = (activity.data['text']?.trim() ?? ''); |
References
- When consuming an object, if a property is optional in its type definition, callers must handle the undefined case (e.g., by providing a default with ??).
- When using an optional string with a fallback value, trim the optional string and use the fallback if the result is empty to avoid uninformative messages from whitespace-only strings.
| lastItem.type === 'thought' && | ||
| lastItem.status === 'running' | ||
| ) { | ||
| lastItem.content = sanitizeThoughtContent(text); |
There was a problem hiding this comment.
The THOUGHT_CHUNK handler currently overwrites the existing content of the last thought item. It should append the new chunk to maintain the full history. Additionally, ensure that prompt injection sanitization is handled at the subagent level rather than within the agent executor logic, as per repository guidelines.
| lastItem.content = sanitizeThoughtContent(text); | |
| lastItem.content += text; |
References
- Prompt injection sanitization should be handled at the tool or subagent level, not on a per-tool basis within the agent executor.
33ed68f to
5cb3bd5
Compare
Summary
This PR adds
LocalSessionInvocationfor session-based local subagent invocation, and introducesRemoteSubagentProtocolandLocalSubagentProtocolto wrap A2A client and LocalAgentExecutor behindAgentProtocol.Details
LocalSessionInvocation: Implements session-based invocation for local agents.RemoteSubagentProtocol: Wraps A2A client.LocalSubagentProtocol: Wraps LocalAgentExecutor.Related Issues
Related to ADK migration.
How to Validate
Run preflight checks (build, lint, test). Tests added in
packages/core/src/agents/local-session-invocation.test.ts.Pre-Merge Checklist