Skip to content

feat(core): Thread AgentLoopContext through core.#21944

Merged
joshualitt merged 1 commit intomainfrom
jl/alc-2
Mar 11, 2026
Merged

feat(core): Thread AgentLoopContext through core.#21944
joshualitt merged 1 commit intomainfrom
jl/alc-2

Conversation

@joshualitt
Copy link
Copy Markdown
Contributor

@joshualitt joshualitt commented Mar 10, 2026

One PR of a few to tackle #21197

@gemini-cli
Copy link
Copy Markdown
Contributor

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

@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 10, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 10, 2026

Size Change: +386 B (0%)

Total Size: 26.5 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 26 MB +386 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

@joshualitt joshualitt marked this pull request as ready for review March 10, 2026 23:17
@joshualitt joshualitt requested a review from a team as a code owner March 10, 2026 23:17
@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 significant architectural improvement by centralizing the execution context for agent operations into a new AgentLoopContext interface. This change streamlines how configuration and runtime-specific information are accessed by various agent components, enhancing clarity and maintainability. The refactoring ensures that all relevant data for an agent's execution, such as the global configuration, message bus, and prompt ID, are consistently available through a single context object.

Highlights

  • Refactoring Context Passing: The primary change involves refactoring how configuration and execution context are passed throughout the core agent components. Instead of directly passing the Config object, an AgentLoopContext interface is now used, providing a more explicit and unified context for agent loops and sub-agent executions.
  • AgentLoopContext Introduction: A new AgentLoopContext interface has been introduced in packages/core/src/config/agent-loop-context.ts, which now includes a config: Config property. This ensures that the global Config object remains accessible within the new context.
  • Config Class Conformance: The Config class in packages/core/src/config/config.ts has been updated to implement the AgentLoopContext interface, including a config getter that returns itself. This allows the Config object to be used as an AgentLoopContext where appropriate.
  • Component Updates: Numerous constructors and methods across Scheduler, LocalAgentExecutor, BrowserAgentInvocation, SubagentToolWrapper, SubagentTool, and GeminiClient have been updated to accept AgentLoopContext instead of Config. This standardizes the context available to these components.
  • Test Adjustments: Corresponding test files have been modified to reflect these changes, including updates to mock objects and property access patterns to align with the new AgentLoopContext structure.
Changelog
  • packages/a2a-server/src/agent/task.ts
    • Updated Scheduler instantiation to use context instead of config.
  • packages/cli/src/nonInteractiveCli.ts
    • Modified Scheduler instantiation to pass context instead of config.
  • packages/cli/src/ui/hooks/useToolScheduler.ts
    • Changed Scheduler instantiation to use context instead of config.
  • packages/core/src/agents/agent-scheduler.test.ts
    • Added mockConfig declaration.
    • Initialized mockConfig with getMessageBus and toolRegistry.
    • Updated comment and variable name to reflect context usage.
    • Removed getToolRegistry() call, directly accessing toolRegistry.
  • packages/core/src/agents/agent-scheduler.ts
    • Modified Scheduler instantiation to pass agentConfig as context.
  • packages/core/src/agents/browser/browserAgentInvocation.ts
    • Imported AgentLoopContext type.
    • Updated constructor to accept context instead of config.
    • Added a private config getter that returns this.context.config.
    • Modified LocalAgentExecutor.create call to pass this.context.
  • packages/core/src/agents/local-executor.test.ts
    • Added mock promptId property to mockConfig.
    • Changed vi.spyOn(mockConfig, 'getToolRegistry') to vi.spyOn(mockConfig, 'toolRegistry', 'get').
    • Updated mockedPromptIdContext.getStore to set promptId on mockConfig.
    • Changed vi.spyOn(configWithHints, 'getToolRegistry') to vi.spyOn(configWithHints, 'toolRegistry', 'get').
  • packages/core/src/agents/local-executor.ts
    • Imported AgentLoopContext type.
    • Renamed runtimeContext property to context.
    • Added a private config getter that returns this.context.config.
    • Updated create static method to accept context instead of runtimeContext.
    • Modified parentMessageBus assignment to use context.messageBus.
    • Updated agentToolRegistry instantiation to use context.config.
    • Modified parentToolRegistry assignment to use context.toolRegistry.
    • Updated allAgentNames assignment to use context.config.getAgentRegistry().
    • Modified parentPromptId assignment to use context.promptId.
    • Updated LocalAgentExecutor constructor call to pass context.
    • Updated constructor to accept context instead of runtimeContext.
    • Modified logRecoveryAttempt call to use this.config.
    • Modified logAgentStart call to use this.config.
    • Modified activeModel assignment to use this.config.getActiveModel().
    • Updated startIndex assignment to use this.config.userHintService.
    • Modified initialHints assignment to use this.config.userHintService.
    • Updated offUserHint call to use this.config.userHintService.
    • Modified logAgentFinish call to use this.config.
    • Updated GeminiChat instantiation to use this.config.
    • Modified modelConfigService calls to use this.config.modelConfigService.
    • Updated getModelRouterService call to use this.config.getModelRouterService().
    • Modified GeminiChat instantiation to use this.config.
    • Updated scheduleAgentTools call to use this.config.
    • Modified getDirectoryContextString call to use this.config.
  • packages/core/src/agents/local-invocation.test.ts
    • Added mock promptId property to mockConfig.
  • packages/core/src/agents/local-invocation.ts
    • Imported AgentLoopContext type.
    • Updated constructor to accept context instead of config.
    • Modified LocalAgentExecutor.create call to pass this.context.
  • packages/core/src/agents/subagent-tool-wrapper.test.ts
    • Added mock promptId property to mockConfig.
  • packages/core/src/agents/subagent-tool-wrapper.ts
    • Imported AgentLoopContext type.
    • Updated constructor to accept context instead of config.
    • Added a private config getter that returns this.context.config.
    • Modified LocalSubagentInvocation instantiation to pass this.context.
  • packages/core/src/agents/subagent-tool.test.ts
    • Added mock promptId property to mockConfig.
    • Changed vi.spyOn(mockConfig, 'getToolRegistry') to vi.spyOn(mockConfig, 'toolRegistry', 'get') in multiple places.
  • packages/core/src/agents/subagent-tool.ts
    • Imported AgentLoopContext type.
    • Updated constructor to accept context instead of config.
    • Modified checkIsReadOnly call to pass this.context.
    • Updated checkIsReadOnly static method to accept context instead of config.
    • Modified registry assignment to use context.toolRegistry.
    • Updated SubAgentInvocation instantiation to pass this.context.
    • Updated SubAgentInvocation constructor to accept context instead of config.
    • Modified startIndex assignment to use context.config.userHintService.
    • Added a private config getter that returns this.context.config.
    • Updated SubagentToolWrapper instantiation to pass this.context.
  • packages/core/src/config/agent-loop-context.ts
    • Imported Config type.
    • Added config: Config property to the AgentLoopContext interface.
  • packages/core/src/config/config.ts
    • Added a config getter that returns this to conform to AgentLoopContext.
  • packages/core/src/core/client.test.ts
    • Imported AgentLoopContext type.
    • Added mock properties (toolRegistry, messageBus, config, promptId) to mockConfig to conform to AgentLoopContext.
    • Updated GeminiClient instantiation to cast mockConfig to AgentLoopContext.
  • packages/core/src/core/client.ts
    • Imported AgentLoopContext type.
    • Updated constructor to accept context instead of config.
    • Added a private config getter that returns this.context.config.
    • Modified LoopDetectionService instantiation to use this.config.
    • Updated toolRegistry assignment to use this.context.toolRegistry in multiple places.
  • packages/core/src/core/coreToolScheduler.ts
    • Updated ToolExecutor instantiation to pass only this.config.
  • packages/core/src/scheduler/policy.test.ts
    • Imported AgentLoopContext type.
    • Added messageBus property to mockConfig in multiple test cases.
    • Updated updatePolicy calls to pass mockConfig directly as AgentLoopContext and toolInvocation as a separate argument.
  • packages/core/src/scheduler/policy.ts
    • Imported AgentLoopContext type.
    • Updated updatePolicy function signature to accept context: AgentLoopContext directly and toolInvocation as a separate argument.
    • Created deps object from context and toolInvocation.
  • packages/core/src/scheduler/scheduler.test.ts
    • Added toolRegistry and messageBus properties to mockConfig.
    • Updated Scheduler instantiation to use context instead of config.
    • Modified messageBus expectation to expect.anything().
    • Updated updatePolicy call to pass mockConfig directly and expect.anything() for toolInvocation.
  • packages/core/src/scheduler/scheduler.ts
    • Updated SchedulerOptions interface to use context: AgentLoopContext.
    • Modified constructor to assign this.context from options.context and derive this.config from this.context.config.
    • Updated ToolExecutor instantiation to pass only this.context.
    • Modified updatePolicy call to pass this.context directly and toolCall.invocation as a separate argument.
  • packages/core/src/scheduler/scheduler_parallel.test.ts
    • Updated Scheduler instantiation to use context instead of config.
  • packages/core/src/scheduler/scheduler_waiting_callback.test.ts
    • Updated Scheduler instantiation to use context instead of config.
  • packages/core/src/scheduler/tool-executor.test.ts
    • Updated ToolExecutor instantiation to pass only config.
  • packages/core/src/scheduler/tool-executor.ts
    • Updated constructor to accept only context: AgentLoopContext.
    • Added a private config getter that returns this.context.config.
  • packages/core/src/telemetry/loggers.test.ts
    • Added mock properties (config, promptId) to cfg2 to conform to AgentLoopContext.
    • Updated GeminiClient instantiation to pass cfg2.
  • packages/core/src/tools/web-search.test.ts
    • Added mock properties (config, promptId) to mockConfigInstance to conform to AgentLoopContext.
    • Updated GeminiClient instantiation to pass mockConfigInstance.
  • packages/core/src/utils/summarizer.test.ts
    • Added mock promptId property to mockConfigInstance.
Activity
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.

@joshualitt joshualitt requested a review from gundermanc March 10, 2026 23:18
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 well-executed refactoring that introduces AgentLoopContext and threads it through core components like schedulers and agent executors. This change effectively separates global configuration from execution-scoped context, which is a solid architectural improvement. The modifications are applied consistently across the codebase, including necessary updates to tests. I've reviewed the changes and found no issues.

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

@joshualitt joshualitt added this pull request to the merge queue Mar 11, 2026
Merged via the queue into main with commit 20a226a Mar 11, 2026
28 checks passed
@joshualitt joshualitt deleted the jl/alc-2 branch March 11, 2026 01:30
JaisalJain pushed a commit to JaisalJain/gemini-cli that referenced this pull request Mar 11, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
SUNDRAM07 pushed a commit to SUNDRAM07/gemini-cli that referenced this pull request Mar 30, 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