Skip to content

feat(agent): formalize first-class tool lifecycle states and status mapping#26529

Open
mbleigh wants to merge 31 commits into
mainfrom
mb/atui/02-tool-state
Open

feat(agent): formalize first-class tool lifecycle states and status mapping#26529
mbleigh wants to merge 31 commits into
mainfrom
mb/atui/02-tool-state

Conversation

@mbleigh

@mbleigh mbleigh commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR formalizes first-class tool lifecycle states in the AgentProtocol event types and refactors the terminal UI rendering pipeline to consume these top-level status properties, fully decoupling it from legacy metadata objects.

Details

1. Protocol Ingestion & Type Formalization

  • Defined ToolEventStatus union type ('pending' | 'pending_input' | 'executing' | 'succeeded' | 'errored' | 'aborted') in types.ts.
  • Added first-class status: ToolEventStatus field to ToolRequest, ToolUpdate, and ToolResponse event types.

2. Granular State Transition Listening

  • Updated translateEvent in event-translator.ts to inject correct status flags.
  • Refactored LegacyAgentProtocol in legacy-agent-session.ts to subscribe to TOOL_CALLS_UPDATE from the scheduler message bus, emitting a typed tool_update event on every single state transition.

3. Dumb Terminal UI Decoupling

  • Refactored useAgentStream.ts to switch state tracking purely from event.status instead of digging into _meta.legacyState.status.

Related Issues

Closes #24993

How to Validate

  1. Start the experimental agent shell flow.
  2. Run tool-heavy turns (e.g., multi-file grep or background processes).
  3. Verify the UI tracks execution stages flawlessly via pure protocol events.

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

mbleigh and others added 20 commits April 10, 2026 11:00
…tadata overwrite

This addresses PR feedback by:
- Creating a `renderDisplayDiff` utility to render `DisplayDiff` objects.
- Creating a `displayContentToString` utility to safely extract text from any `DisplayContent`.
- Updating non-interactive CLI to use `displayContentToString` to avoid data loss on non-text output.
- Updating `useAgentStream` to use `displayContentToString` to avoid stale UI state for non-text output.
- Shallow merging the `display` object in `useAgentStream` rather than replacing it, preventing loss of display metadata.
This change completes the transition of the interactive agent session (`useAgentStream`)
to a declarative-first tool rendering system.

Key changes:
- Reverted experimental `ToolDisplay` logic from legacy UI components (`DenseToolMessage`, etc.)
  to establish a clean baseline.
- Introduced `HistoryItemToolDisplayGroup` and `ToolGroupDisplay` component in CLI.
- Added `display` property to `ToolCallRequestInfo` to carry declarative UI info natively.
- Populated tool request display information at the source (`Turn.ts` and `Scheduler.ts`)
  using dynamic descriptions from tool invocations.
- Updated `useAgentStream` to emit the new history item type, providing a standalone
  rendering path for interactive sessions.
- Ensured tool descriptions are updated when arguments are modified during confirmation.
Key enhancements:
- Updated `UpdateTopicTool` to provide declarative 'notice' display info, using dynamic
  descriptions for high-fidelity output.
- Refined `ToolGroupDisplay` to 'hoist' notice-format tools to the top of the group.
- Implemented conditional boxing in `ToolGroupDisplay`: borders are now suppressed in
  compact mode, matching the standard CLI view.
- Added support for `resultSummary` rendering at the bottom of text results in boxed mode.
- Improved `useAgentStream` to wait for turn completion before pushing tools to history,
  ensuring all notices for a turn are correctly grouped and hoisted together.
- Fixed margin and border logic to handle seamless transitions between notices and tool boxes.
@mbleigh mbleigh requested a review from a team as a code owner May 5, 2026 18:45
@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 formalizes the tool lifecycle states within the AgentProtocol. By introducing a standard set of status types and propagating them through the event translation layer and UI hooks, the system is now decoupled from legacy state management. This change ensures more reliable tracking of tool execution progress and simplifies the handling of tool-related events across the codebase.

Highlights

  • Tool Lifecycle Formalization: Introduced a formal 'ToolEventStatus' type to standardize tool lifecycle states across the AgentProtocol, replacing legacy status mappings.
  • Event Translation Refactoring: Updated 'translateEvent' to include explicit status fields in tool request and response events, ensuring consistent state tracking.
  • UI Decoupling: Refactored 'useAgentStream' to rely directly on standard event statuses rather than legacy metadata, improving maintainability.
  • Legacy Protocol Integration: Implemented a tool call update handler in 'LegacyAgentProtocol' to monitor and emit status changes via the message bus.
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 gemini-cli Bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label May 5, 2026

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

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.

Code Review

This pull request improves tool call status management by introducing a ToolEventStatus type and updating event interfaces to include execution status. Key changes include enhanced status mapping in the UI, a new message bus subscription in LegacyAgentProtocol for real-time updates, and a fix to the build script for cleaner documentation deployment. Reviewer feedback focused on improving type safety by replacing magic strings with the CoreToolCallStatus enum and addressing a potential bug where tool updates could leak across different agent sessions.

Comment thread packages/core/src/agent/legacy-agent-session.ts
Comment thread packages/core/src/agent/legacy-agent-session.ts
Comment thread packages/core/src/agent/legacy-agent-session.ts
Base automatically changed from mb/atui/01-ui-rendering to main May 6, 2026 21:36
@mbleigh mbleigh requested a review from a team as a code owner May 6, 2026 21:36
@jacob314 jacob314 self-requested a review May 6, 2026 21:43
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

Size Change: +3.22 kB (+0.01%)

Total Size: 33.8 MB

Filename Size Change
./bundle/chunk-4M4ROHNP.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-53KM2QET.js 0 B -16.5 MB (removed) 🏆
./bundle/chunk-5SXQEWXY.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-EGNJHBRW.js 0 B -12.5 kB (removed) 🏆
./bundle/chunk-JIMQKCNQ.js 0 B -658 kB (removed) 🏆
./bundle/chunk-KJ3MEIKE.js 0 B -19.5 kB (removed) 🏆
./bundle/chunk-LHS2Y2CK.js 0 B -2.78 MB (removed) 🏆
./bundle/chunk-WO4FLERD.js 0 B -3.77 kB (removed) 🏆
./bundle/core-A3LYXDWA.js 0 B -49.1 kB (removed) 🏆
./bundle/devtoolsService-IN7BHUX7.js 0 B -28 kB (removed) 🏆
./bundle/gemini-SQL2KYMJ.js 0 B -585 kB (removed) 🏆
./bundle/interactiveCli-EVH65IOT.js 0 B -1.3 MB (removed) 🏆
./bundle/liteRtServerManager-64J5LTFA.js 0 B -2.08 kB (removed) 🏆
./bundle/oauth2-provider-7GLAZ4MT.js 0 B -9.12 kB (removed) 🏆
./bundle/chunk-46PFNPPY.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-AYBKAD3W.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/chunk-EYUJA3MB.js 658 kB +658 kB (new file) 🆕
./bundle/chunk-FIMVGBL3.js 3.77 kB +3.77 kB (new file) 🆕
./bundle/chunk-GXF45W6R.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/chunk-OYJIRUCP.js 2.78 MB +2.78 MB (new file) 🆕
./bundle/chunk-UPDU7X3X.js 16.5 MB +16.5 MB (new file) 🆕
./bundle/chunk-VY3ABUVV.js 12.5 kB +12.5 kB (new file) 🆕
./bundle/core-MNP73YY4.js 49.1 kB +49.1 kB (new file) 🆕
./bundle/devtoolsService-DAJJKJOP.js 28 kB +28 kB (new file) 🆕
./bundle/gemini-ZRR5QVJ4.js 585 kB +585 kB (new file) 🆕
./bundle/interactiveCli-2OONP3BT.js 1.3 MB +1.3 MB (new file) 🆕
./bundle/liteRtServerManager-JHHJXBN2.js 2.08 kB +2.08 kB (new file) 🆕
./bundle/oauth2-provider-2WNTWGOS.js 9.12 kB +9.12 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-CTHYVDCX.js 39.8 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/cleanup-MEX4K5WZ.js 0 B -902 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-JYLQM7LS.js 373 B 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.07 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/start-GR6MMZWR.js 0 B -622 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-RONRZ7YN.js 902 B +902 B (new file) 🆕
./bundle/start-PDQZFHKC.js 622 B +622 B (new file) 🆕

compressed-size-action

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

69 tests passed successfully on gemini-3-flash-preview.

🧠 Model Steering Guidance

This PR modifies files that affect the model's behavior (prompts, tools, or instructions).

  • ⚠️ Consider adding Evals: No behavioral evaluations (evals/*.eval.ts) were added or updated in this PR. Consider adding a test case to verify the new behavior and prevent regressions.
  • 🚀 Maintainer Reminder: Please ensure that these changes do not regress results on benchmark evals before merging.

This is an automated guidance message triggered by steering logic signatures.

@gemini-cli gemini-cli Bot added the priority/p1 Important and should be addressed in the near term. label May 8, 2026
Comment thread scripts/build_package.js Outdated
Comment thread packages/core/src/agent/legacy-agent-session.ts

@jacob314 jacob314 left a comment

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.

Approved with a couple comments that should be addressed before commit.lgtm

@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown

⚠️ Invocation Drift Warning

The following file pairs should generally be kept in sync during the AgentSession migration:

  • non-interactive CLI: packages/cli/src/nonInteractiveCliAgentSession.ts was modified but packages/cli/src/nonInteractiveCli.ts was not.

If this is intentional (e.g., a bug fix specific to one implementation), you can ignore this comment.

This check will be removed once the legacy implementations are deleted.

@mbleigh mbleigh added this pull request to the merge queue May 12, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026

@jacob314 jacob314 left a comment

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.

lgtm

@mbleigh mbleigh added this pull request to the merge queue May 15, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 15, 2026
@mbleigh mbleigh enabled auto-merge May 15, 2026 18:14
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p1 Important and should be addressed in the near term. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AgentProtocol] Enrich AgentEvent for granular tool lifecycle states

4 participants