Skip to content

feat(core): add LocalSessionInvocation and SubagentProtocols#26665

Open
adamfweidman wants to merge 4 commits intomainfrom
agent-session/local-invocation
Open

feat(core): add LocalSessionInvocation and SubagentProtocols#26665
adamfweidman wants to merge 4 commits intomainfrom
agent-session/local-invocation

Conversation

@adamfweidman
Copy link
Copy Markdown
Contributor

Summary

This PR adds LocalSessionInvocation for session-based local subagent invocation, and introduces RemoteSubagentProtocol and LocalSubagentProtocol to wrap A2A client and LocalAgentExecutor behind AgentProtocol.

Details

  • LocalSessionInvocation: Implements session-based invocation for local agents.
  • RemoteSubagentProtocol: Wraps A2A client.
  • LocalSubagentProtocol: Wraps LocalAgentExecutor.
  • Part of the ADK integration effort.

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

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

adamfweidman and others added 4 commits April 13, 2026 13:01
…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
@adamfweidman adamfweidman requested a review from a team as a code owner May 7, 2026 19:21
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • LocalSessionInvocation: Added a new class to handle session-based local subagent execution, providing a bridge for streaming activity and result formatting.
  • Subagent Protocols: Introduced RemoteSubagentProtocol and LocalSubagentProtocol to standardize communication patterns across different agent types.
  • ADK Integration: Refactored agent communication patterns to support the ongoing ADK migration effort.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented May 7, 2026

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!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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']);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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).

Suggested change
const text = String(activity.data['text']);
const text = (activity.data['text']?.trim() ?? '');
References
  1. 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 ??).
  2. 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
lastItem.content = sanitizeThoughtContent(text);
lastItem.content += text;
References
  1. Prompt injection sanitization should be handled at the tool or subagent level, not on a per-tool basis within the agent executor.

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label May 7, 2026
@adamfweidman adamfweidman force-pushed the agent-session/local-protocol branch from 33ed68f to 5cb3bd5 Compare May 8, 2026 18:27
Base automatically changed from agent-session/local-protocol to main May 8, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant