Skip to content

feat(core): Fully migrate packages/core to AgentLoopContext.#22115

Merged
joshualitt merged 1 commit intomainfrom
jl/alc-cli
Mar 13, 2026
Merged

feat(core): Fully migrate packages/core to AgentLoopContext.#22115
joshualitt merged 1 commit intomainfrom
jl/alc-cli

Conversation

@joshualitt
Copy link
Copy Markdown
Contributor

PR series to address #21197

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 12, 2026

Hi @joshualitt, 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 Mar 12, 2026

Size Change: +1.09 kB (0%)

Total Size: 26.1 MB

Filename Size Change
./bundle/chunk-HD26CB2N.js 0 B -13.4 MB (removed) 🏆
./bundle/chunk-Z6SWWESI.js 0 B -3.62 MB (removed) 🏆
./bundle/core-ZHRT2KF2.js 0 B -40.1 kB (removed) 🏆
./bundle/devtoolsService-TZVSZVZU.js 0 B -27.7 kB (removed) 🏆
./bundle/interactiveCli-2NOF4NCU.js 0 B -1.59 MB (removed) 🏆
./bundle/oauth2-provider-YDXJJYEV.js 0 B -9.19 kB (removed) 🏆
./bundle/chunk-4UNDOEUQ.js 3.62 MB +3.62 MB (new file) 🆕
./bundle/chunk-FMOUDU2H.js 13.4 MB +13.4 MB (new file) 🆕
./bundle/core-JI6ETHZI.js 40.1 kB +40.1 kB (new file) 🆕
./bundle/devtoolsService-JKYZ72ZZ.js 27.7 kB +27.7 kB (new file) 🆕
./bundle/interactiveCli-P3M2FXTU.js 1.59 MB +1.59 MB (new file) 🆕
./bundle/oauth2-provider-SHWISXXC.js 9.19 kB +9.19 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-37ZTTFQF.js 966 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-FXR7IA3Q.js 1.95 MB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/gemini.js 689 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/keychain-token-storage-LF5BRABV.js 0 B -518 B (removed) 🏆
./bundle/memoryDiscovery-URXPIMBI.js 922 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 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/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/undici-4X2YZID5.js 360 B 0 B
./bundle/keychain-token-storage-NZDQQU5M.js 518 B +518 B (new file) 🆕

compressed-size-action

@gemini-cli gemini-cli bot added area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 12, 2026
@joshualitt joshualitt force-pushed the jl/alc-cli branch 2 times, most recently from 63f36a8 to 1b626ed Compare March 12, 2026 05:14
@joshualitt joshualitt marked this pull request as ready for review March 12, 2026 05:16
@joshualitt joshualitt requested a review from a team as a code owner March 12, 2026 05:16
@joshualitt joshualitt requested a review from gundermanc March 12, 2026 05:16
@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 undertakes a significant architectural refactoring to standardize how core services and configuration are accessed throughout the agent loop. By migrating various components to explicitly use the AgentLoopContext interface, the change aims to create a more consistent, maintainable, and testable codebase. This involves replacing numerous direct method calls on the Config object with property-based access via the AgentLoopContext, thereby streamlining dependency management and promoting clearer separation of concerns.

Highlights

  • Core Refactoring: AgentLoopContext Migration: The pull request fully migrates various core components across packages/a2a-server, packages/core, and packages/sdk to utilize the AgentLoopContext interface. This standardizes how essential services like the message bus, tool registry, and Gemini client are accessed.
  • API Modernization: Direct method calls such as config.getMessageBus(), config.getToolRegistry(), and config.getGeminiClient() have been replaced with direct property access on the AgentLoopContext (e.g., context.messageBus, context.toolRegistry, context.geminiClient).
  • Improved Testability and Maintainability: This migration enhances the modularity and testability of the codebase by promoting dependency injection through the AgentLoopContext, making it easier to mock and manage dependencies in tests and improving overall code clarity.
  • Deprecation of Direct Config Accessors: The direct accessor methods on the Config class for toolRegistry, messageBus, and geminiClient have been marked as @deprecated, guiding developers towards using the AgentLoopContext for these services.
Changelog
  • packages/a2a-server/src/agent/task-event-driven.test.ts
    • Updated message bus access from a method call to a property.
  • packages/a2a-server/src/agent/task.ts
    • Imported the AgentLoopContext type.
    • Updated access to geminiClient, toolRegistry, and messageBus to use AgentLoopContext properties.
  • packages/a2a-server/src/commands/memory.ts
    • Imported the AgentLoopContext type.
    • Updated toolRegistry access to use an AgentLoopContext property.
  • packages/a2a-server/src/utils/testing_utils.ts
    • Updated toolRegistry access in mock configuration.
  • packages/core/src/agents/agent-scheduler.test.ts
    • Updated mock messageBus and toolRegistry access to properties instead of method calls.
  • packages/core/src/agents/agent-scheduler.ts
    • Updated getMessageBus and Scheduler constructor to use the toolRegistry.messageBus property.
  • packages/core/src/agents/cli-help-agent.ts
    • Replaced Config with AgentLoopContext in the agent definition.
    • Updated messageBus access to use the context.messageBus property.
  • packages/core/src/agents/generalist-agent.test.ts
    • Updated mock config to expose toolRegistry and config as properties for AgentLoopContext compatibility.
  • packages/core/src/agents/generalist-agent.ts
    • Replaced Config with AgentLoopContext in the agent definition.
    • Updated toolRegistry and config access to use AgentLoopContext properties.
  • packages/core/src/agents/local-executor.test.ts
    • Updated ToolRegistry and LSTool instantiation to use mockConfig.messageBus property.
  • packages/core/src/config/config.test.ts
    • Imported the AgentLoopContext type.
    • Updated geminiClient and toolRegistry access to use AgentLoopContext properties in tests.
    • Changed ConsecaSafetyChecker.setConfig to setContext.
  • packages/core/src/config/config.ts
    • Changed ConsecaSafetyChecker.setConfig to setContext.
    • Updated toolRegistry.unregisterTool and registerTool to use the this.toolRegistry property.
    • Added @deprecated JSDoc to toolRegistry, messageBus, and geminiClient getters.
    • Updated geminiClient access to use the property directly.
  • packages/core/src/config/trackerFeatureFlag.test.ts
    • Imported the AgentLoopContext type.
    • Updated toolRegistry access to use an AgentLoopContext property.
  • packages/core/src/core/client.test.ts
    • Imported the MessageBus type.
    • Updated mock messageBus and geminiClient properties.
  • packages/core/src/core/client.ts
    • Updated messageBus access to this.context.messageBus.
  • packages/core/src/core/coreToolScheduler.test.ts
    • Added toolRegistry, messageBus, and geminiClient properties to mock config.
    • Changed CoreToolScheduler constructor parameter from config to context.
    • Updated toolRegistry access in mock.
  • packages/core/src/core/coreToolScheduler.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed CoreToolSchedulerOptions and class property config to context: AgentLoopContext.
    • Updated toolExecutor instantiation and various config accesses to use this.context.config or this.context.toolRegistry/messageBus.
  • packages/core/src/core/geminiChat.test.ts
    • Added config and promptId properties to mock config.
  • packages/core/src/core/geminiChat.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.toolRegistry.
  • packages/core/src/core/geminiChat_network_retry.test.ts
    • Added config, toolRegistry, messageBus, and promptId properties to mock config.
  • packages/core/src/core/prompts-substitution.test.ts
    • Imported the ToolRegistry type.
    • Added config and toolRegistry properties to mock config.
    • Updated toolRegistry access in tests.
  • packages/core/src/core/prompts.test.ts
    • Added config and toolRegistry properties to mock config.
    • Updated toolRegistry access in tests.
  • packages/core/src/hooks/hookEventHandler.test.ts
    • Added config and geminiClient properties to mock config.
  • packages/core/src/hooks/hookEventHandler.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.geminiClient.
  • packages/core/src/prompts/promptProvider.test.ts
    • Imported the ToolRegistry type.
    • Added config and toolRegistry properties to mock config.
  • packages/core/src/prompts/promptProvider.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed getCoreSystemPrompt and getCompressionPrompt parameters from config: Config to context: AgentLoopContext.
    • Updated various config accesses to use context.config or context.toolRegistry.
  • packages/core/src/prompts/utils.test.ts
    • Imported the ToolRegistry type.
    • Added config and toolRegistry properties to mock config.
    • Updated toolRegistry access in tests.
  • packages/core/src/prompts/utils.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed applySubstitutions parameter from config: Config to context: AgentLoopContext.
    • Updated various config accesses to use context.config or context.toolRegistry.
  • packages/core/src/safety/conseca/conseca.test.ts
    • Added config property to mock config.
    • Changed checker.setConfig to setContext.
  • packages/core/src/safety/conseca/conseca.ts
    • Changed config: Config | null to context: AgentLoopContext | null.
    • Changed setConfig to setContext.
    • Updated various config accesses to use this.context.config or this.context.toolRegistry.
  • packages/core/src/safety/context-builder.test.ts
    • Imported the GeminiClient type.
    • Added config and geminiClient properties to mock config.
  • packages/core/src/safety/context-builder.ts
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.geminiClient.
  • packages/core/src/scheduler/policy.test.ts
    • Updated Scheduler and CoreToolScheduler constructors to pass an AgentLoopContext object.
  • packages/core/src/services/chatCompressionService.test.ts
    • Added config property to mock config.
  • packages/core/src/services/chatRecordingService.test.ts
    • Added config, toolRegistry, and promptId properties to mock config.
  • packages/core/src/services/chatRecordingService.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.promptId/toolRegistry.
  • packages/core/src/services/loopDetectionService.test.ts
    • Added config and geminiClient properties to mock config.
  • packages/core/src/services/loopDetectionService.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.geminiClient.
  • packages/core/src/tools/confirmation-policy.test.ts
    • Added config property to mock config.
  • packages/core/src/tools/mcp-client.ts
    • Updated toolRegistry.getMessageBus() to toolRegistry.messageBus.
  • packages/core/src/tools/shell.test.ts
    • Added config and geminiClient properties to mock config.
    • Updated geminiClient access to use the property directly.
  • packages/core/src/tools/shell.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.geminiClient.
  • packages/core/src/tools/tool-registry.ts
    • Changed the messageBus property from private to readonly.
  • packages/core/src/tools/web-fetch.test.ts
    • Added config and geminiClient properties to mock config.
  • packages/core/src/tools/web-fetch.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.geminiClient.
  • packages/core/src/tools/web-search.test.ts
    • Added geminiClient property to mock config.
  • packages/core/src/tools/web-search.ts
    • Removed Config import and added AgentLoopContext import.
    • Changed constructor parameter config to context: AgentLoopContext.
    • Updated various config accesses to use this.context.config or this.context.geminiClient.
  • packages/core/src/utils/extensionLoader.test.ts
    • Added geminiClient property to mock config.
  • packages/core/src/utils/extensionLoader.ts
    • Updated config.getGeminiClient() to config.geminiClient.
  • packages/core/src/utils/nextSpeakerChecker.test.ts
    • Added config and promptId properties to mock config.
  • packages/sdk/src/session.ts
    • Imported the AgentLoopContext type.
    • Updated toolRegistry, messageBus, and geminiClient access to use AgentLoopContext properties.
  • packages/sdk/src/shell.ts
    • Imported the AgentLoopContext type.
    • Updated ShellTool instantiation to use AgentLoopContext properties.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

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 is a significant and valuable refactoring that migrates packages/core to use the new AgentLoopContext. This change improves decoupling, clarifies dependencies, and enhances testability by moving away from direct Config property access. The changes are extensive and appear to be correctly implemented for the most part. My review focuses on a repeated pattern of creating unnecessary local variables for the context, which can be simplified to make the code more concise and maintainable.

Note: Security Review did not run due to the size of the PR.

@joshualitt joshualitt added this pull request to the merge queue Mar 13, 2026
Merged via the queue into main with commit de656f0 Mar 13, 2026
27 checks passed
@joshualitt joshualitt deleted the jl/alc-cli branch March 13, 2026 02:08
SUNDRAM07 pushed a commit to SUNDRAM07/gemini-cli that referenced this pull request Mar 30, 2026
warrenzhu25 pushed a commit to warrenzhu25/gemini-cli that referenced this pull request Apr 9, 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 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants