feat(core): virtual tools support (#1806)#3174
feat(core): virtual tools support (#1806)#3174matiasmolinas wants to merge 11 commits intogoogle-gemini:mainfrom EvolvingAgentsLabs:issue-1806
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Summary of Changes
Hello @matiasmolinas, 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 significantly expands the Gemini CLI's capabilities by enabling users to define custom, sandboxed tools directly within their project's GEMINI.md files. This feature, designed for security and ease of use, allows for more powerful and project-specific AI workflows. Beyond the core virtual tool functionality, I've also implemented security enhancements for user authentication, refined chat history management, and made several minor UI/UX improvements.
Highlights
- Virtual Tool System Introduction: I've introduced a new 'Manifest-Driven Virtual Tool System' to the Gemini CLI. This allows users to define and execute custom, sandboxed tools directly from their project's
GEMINI.mdfile, significantly enhancing CLI extensibility for advanced AI workflows. - Manifest Parsing: A new
ManifestParserhas been implemented to detect and extract tool definitions from a special### Toolssection withinGEMINI.mdfiles. Each tool definition includes a shell script and a JSON schema. - Virtual Tool Execution: The
VirtualShellToolclass is now responsible for executing these user-defined shell scripts within the CLI's existing secure sandbox. Arguments are passed via theGEMINI_TOOL_ARGSenvironment variable, andstdoutis returned as the tool's result. - Tool Discovery Integration: The
ToolRegistryhas been updated to automatically discover and register these new virtual tools upon startup, integrating them seamlessly with existing built-in and discovered tools. - Enhanced Security for Google Account ID Retrieval: I've refactored the Google Account ID retrieval process to use
id_tokenverification, which is a more secure and privacy-preserving method compared to the previoususerinfoendpoint. - Chat History Compression Logic: The
GeminiClientnow includes logic to dynamically manage chat history size. It can trigger summarization based on token limits, ensuring the model operates efficiently within its context window. - Documentation and Testing: Comprehensive documentation for virtual tools has been added, and a new integration test specifically validates the core mechanics of the virtual tool system.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces manifest-driven virtual tools, a powerful extension to the CLI. A critical change to the telemetry system involves sending Personally Identifiable Information (PII). This change was not documented in the pull request description and requires immediate attention to ensure user privacy and compliance.
|
Thanks so much for you efforts in this space, we really appreciate your contributions and encourage you to keep them coming ! This is a very good idea and will be valuable for many users. In order to help users build and implement use cases such as this, we encourage users to implement these using either extensions or MCP Servers. Have you considered one of thes approaches? You can learn more about Extensions here, https://github.com/google-gemini/gemini-cli/blob/main/docs/extension.md Please don't hesitate to reach out if you had any further thoughts / comments about this. While we are closing this PR for now, we do look forward to seeing how you take this forward as an extension or MCP server ! |
This PR introduces a "Manifest-Driven Virtual Tool System" to the Gemini CLI, enabling users to define and execute custom, sandboxed tools directly from their project's
GEMINI.mdfile. This is a generic, opt-in feature that enhances CLI extensibility without altering its core behavior for existing users.The implementation consists of two main parts:
ManifestParserthat detects a special### Toolssection inGEMINI.mdand extracts tool definitions (a shell script and a JSON schema).VirtualShellToolclass that executes these parsed scripts within the CLI's existing, secure sandbox, delegating the execution to the nativeShellTool.This change democratizes tool creation, allowing any user who can write a simple shell script to create powerful, project-specific AI workflows and advanced agentic systems like LLMunix.
Dive Deeper
The primary motivation for this change is to unlock advanced agentic behavior by providing a simple, secure, and accessible way to extend the CLI's capabilities. Instead of building a complex, framework-specific runner, this PR enhances the existing
GEMINI.mdcontext-loading mechanism to support executable manifests.Architectural Approach:
VirtualShellToolthat delegates its execution to the battle-tested nativeShellTool, we ensure all user-defined code runs within the existing sandboxing infrastructure (Docker, Podman, or Seatbelt). This is a critical security consideration.How it Works:
MemoryDiscoveryServiceloadsGEMINI.mdfiles as usual.ManifestParser, which looks for a### Toolssection.#### tool_nameheader and correspondingshandjsoncode blocks, the parser creates aVirtualToolDefinitionobject.VirtualShellToolinstance is created and registered with theToolRegistry.VirtualShellToolinstance stringifies the arguments, passes them to the tool's script via aGEMINI_TOOL_ARGSenvironment variable, and executes the script within the sandbox.stdoutfrom the script is returned to the LLM as the tool's result.This approach is powerful because it allows the entire "firmware" of an agentic system—its core logic (the system prompt) and its system calls (the virtual tools)—to live and be version-controlled directly within the user's project repository.
Reviewer Test Plan
To validate these changes, pull down this branch and run the following tests.
1. Unit & Basic Integration Test:
npm test2. End-to-End Acceptance Test with LLMunix:
This is the most important test, as it validates the feature's ability to power a complex, real-world agentic system.
Step 1: Clone the test repository.
git clone https://github.com/EvolvingAgentsLabs/llmunix cd llmunixStep 2: Initialize the workspace.
Step 3: Run the local build of Gemini CLI.
From the
gemini-cliproject root:The CLI should start, and you will see logs indicating that the virtual tools from
llmunix/GEMINI.mdhave been registered (e.g.,[MemoryDiscovery] Registered virtual tool 'run_agent' from ...).Step 4: Provide a high-level goal.
At the Gemini CLI prompt, enter the following goal:
Step 5: Observe and Validate Agent Behavior.
You should observe the following sequence of events, which confirms the system is working as intended:
list_filesvirtual tool to check its capabilities.WritingAgent.mdis missing.WritingAgent.mdfile using thewrite_filevirtual tool.run_agentvirtual tool multiple times.workspace/reports/directory.Testing Matrix
Linked issues / bugs
Resolves #1806