Skip to content

feat(core): Introduce AgentLoopContext.#21198

Merged
joshualitt merged 1 commit intomainfrom
jl/agent-loop-context
Mar 9, 2026
Merged

feat(core): Introduce AgentLoopContext.#21198
joshualitt merged 1 commit intomainfrom
jl/agent-loop-context

Conversation

@joshualitt
Copy link
Contributor

This is the first PR, it introduces the new interface which will be separated out of Config by the end of this series.

Part of a series to address #21197

@gemini-cli
Copy link
Contributor

gemini-cli bot commented Mar 5, 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

github-actions bot commented Mar 5, 2026

Size Change: +533 B (0%)

Total Size: 26 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.5 MB +533 B (0%)
./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

compressed-size-action

@gemini-cli gemini-cli bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Mar 5, 2026
@joshualitt joshualitt force-pushed the jl/agent-loop-context branch 3 times, most recently from ea4a038 to 17afeb1 Compare March 5, 2026 17:19
addItem,
registerBackgroundShell,
consumeUserHint,
config,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is related to a lint warning, which may be in the codebase at HEAD. I might be able to remove this if you prefer we don't land this minor change in this PR, but I haven't tested this.

@joshualitt joshualitt force-pushed the jl/agent-loop-context branch from 17afeb1 to 2872fa7 Compare March 5, 2026 17:23
@joshualitt joshualitt marked this pull request as ready for review March 5, 2026 17:26
@joshualitt joshualitt requested a review from a team as a code owner March 5, 2026 17:26
@joshualitt joshualitt requested a review from gundermanc March 5, 2026 17:26
@gemini-code-assist
Copy link
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 initiates a significant architectural refactoring by introducing the AgentLoopContext interface. The primary goal is to decouple execution-scoped concerns from the global Config object, improving modularity and testability. By having Config initially implement this new interface, the change enables a phased migration, allowing components like the Scheduler and ToolExecutor to begin consuming the more focused context without immediate, sweeping changes across the codebase.

Highlights

  • Introduced AgentLoopContext Interface: A new TypeScript interface, AgentLoopContext, has been defined to represent the execution-scoped view of the world for an agent turn or sub-agent loop. This interface aims to provide better isolation and facilitate incremental migration away from a monolithic Config object.
  • Config Implements AgentLoopContext: The existing Config class now implements the new AgentLoopContext interface, acting as an initial 'Trojan Horse' to allow for a gradual refactoring process. It includes new getters for config (self-reference) and promptId.
  • Scheduler and ToolExecutor Refactoring: The Scheduler and ToolExecutor classes have been updated to depend on the AgentLoopContext interface instead of directly on the Config class for certain functionalities, such as accessing the message bus and tool registry. This change promotes better dependency management and prepares for future isolation.
  • Test Utilities Updated: Mock configuration objects in various test files (testing_utils.ts, coreToolScheduler.test.ts, policy.test.ts, scheduler.test.ts, scheduler_parallel.test.ts) have been updated to include the new config and promptId properties, ensuring compatibility with the AgentLoopContext interface.
Changelog
  • packages/a2a-server/src/utils/testing_utils.ts
    • Added config and promptId properties to the mock Config object to align with the new AgentLoopContext interface.
  • packages/cli/src/ui/hooks/useGeminiStream.ts
    • Removed the config dependency from the useGeminiStream hook, streamlining its dependencies.
  • packages/core/src/config/agent-loop-context.ts
    • Added a new file defining the AgentLoopContext interface, including properties for promptId, getToolRegistry, getMessageBus, getGeminiClient, and a reference to the global config.
  • packages/core/src/config/config.ts
    • Imported the new AgentLoopContext interface.
    • Updated the Config class to implement the AgentLoopContext interface.
    • Added config and promptId getters to the Config class to fulfill the AgentLoopContext contract.
  • packages/core/src/core/coreToolScheduler.test.ts
    • Added a config property to the mock Config object within createMockConfig to satisfy the AgentLoopContext interface.
  • packages/core/src/index.ts
    • Exported the newly introduced AgentLoopContext interface from the core package.
  • packages/core/src/scheduler/policy.test.ts
    • Added a config property to various mock Config objects across multiple test cases to ensure compatibility with the AgentLoopContext interface.
  • packages/core/src/scheduler/scheduler.test.ts
    • Added a config property to the mock Config object in the scheduler tests.
  • packages/core/src/scheduler/scheduler.ts
    • Imported the AgentLoopContext interface.
    • Updated the SchedulerOptions interface to use AgentLoopContext for its config property.
    • Changed the private config property to context of type AgentLoopContext.
    • Modified the constructor to initialize context with options.config and retrieve messageBus from context if not provided.
    • Updated ToolExecutor instantiation to use this.context.
    • Added a config getter to expose the underlying Config from the AgentLoopContext.
  • packages/core/src/scheduler/scheduler_parallel.test.ts
    • Added a config property to the mock Config object in parallel scheduler tests.
  • packages/core/src/scheduler/tool-executor.ts
    • Imported the AgentLoopContext interface.
    • Updated the constructor to accept AgentLoopContext as context instead of Config.
    • Added a config getter to provide access to the underlying Config from the AgentLoopContext.
Activity
  • No human activity detected in the pull request.
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
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 the AgentLoopContext interface as a first step in a larger refactoring effort to decouple components from the main Config object. The Config class now implements this new interface, acting as a "Trojan Horse" to allow for incremental adoption. Key components like Scheduler and ToolExecutor have been updated to depend on the AgentLoopContext abstraction instead of the concrete Config class. Numerous test files have also been updated to align mock configurations with the new interface requirements. The changes are well-structured and represent a positive step towards improving the codebase's modularity and testability. I found no high or critical issues in this pull request.

@joshualitt joshualitt force-pushed the jl/agent-loop-context branch from 2872fa7 to 00559b4 Compare March 5, 2026 17:57
Copy link
Member

@gundermanc gundermanc left a comment

Choose a reason for hiding this comment

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

LGTM. Left a few ideas but nothing blocking.

This is the first PR, it introduces the new interface which will
be separated out of Config by the end of this series.
@joshualitt joshualitt force-pushed the jl/agent-loop-context branch from 7d5f321 to b06e994 Compare March 9, 2026 15:50
@joshualitt joshualitt added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit 96b939f Mar 9, 2026
27 checks passed
@joshualitt joshualitt deleted the jl/agent-loop-context branch March 9, 2026 16:19
gsquared94 added a commit to gsquared94/gemini-cli that referenced this pull request Mar 9, 2026
The AgentLoopContext introduction (google-gemini#21198) caused the Scheduler to
read toolRegistry via a property getter instead of the getToolRegistry()
method. Object.create(config) inherits the getter from the prototype
chain, so the agent-scoped config always returned the main registry.

Add Object.defineProperty to shadow the inherited getter with the
agent-specific registry. Add regression tests.

Fixes google-gemini#21765
gsquared94 added a commit to gsquared94/gemini-cli that referenced this pull request Mar 9, 2026
The AgentLoopContext introduction (google-gemini#21198) caused the Scheduler to
read toolRegistry via a property getter instead of the getToolRegistry()
method. Object.create(config) inherits the getter from the prototype
chain, so the agent-scoped config always returned the main registry.

Add Object.defineProperty to shadow the inherited getter with the
agent-specific registry. Add regression tests.

Fixes google-gemini#21765
gsquared94 added a commit to gsquared94/gemini-cli that referenced this pull request Mar 9, 2026
The AgentLoopContext introduction (google-gemini#21198) caused the Scheduler to
read toolRegistry via a property getter instead of the getToolRegistry()
method. Object.create(config) inherits the getter from the prototype
chain, so the agent-scoped config always returned the main registry.

Add Object.defineProperty to shadow the inherited getter with the
agent-specific registry. Add regression tests.

Fixes google-gemini#21765
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants