Skip to content

Latest commit

 

History

History

gemini-assistant

README.md

Gemini CLI Assistant

In this guide you will learn how to use the Gemini CLI Assistant via GitHub Actions. It serves as an on-demand collaborator you can quickly delegate work to, invoked directly in GitHub Pull Request and Issue comments to perform a wide range of tasks—from code analysis and modifications to project management. When you invoke the workflow via @gemini-cli, it uses a customizable set of tools to understand the context, execute your request, and respond within the same thread.

Overview

Unlike specialized Gemini CLI workflows for pull request reviews or issue triage, the Gemini CLI Assistant is designed to handle a broad variety of requests, from answering questions about the code to performing complex code modifications, as demonstrated further in this document.

Features

  • Conversational Interface: You can interact with the Gemini AI assistant directly in GitHub Issue and PR comments.
  • Repository Interaction: The Gemini CLI can read files, view diffs in Pull Requests, and inspect Issue details.
  • Code Modification: After maintainer approval of a proposed plan comment, Gemini CLI can create a feature branch, commit file updates, and open a pull request for review.
  • Customizable Toolset: You can define exactly which shell commands and tools the Gemini AI is allowed to use.
  • Flexible Prompting: You can tailor the Gemini CLI's role, instructions, and guidelines to fit your project's needs.

Setup

For detailed setup instructions, including prerequisites and authentication, please refer to the main Getting Started section and Authentication documentation.

Prerequisites

Add the following entries to your .gitignore file to prevent Gemini CLI artifacts from being committed:

# gemini-cli settings
.gemini/

# GitHub App credentials
gha-creds-*.json

Setup Methods

To use this workflow, you can utilize either of the following methods:

  1. Run the /setup-github command in Gemini CLI on your terminal to set up workflows for your repository.
  2. Copy the workflow files into your repository's .github/workflows directory:
mkdir -p .github/workflows
curl -o .github/workflows/gemini-dispatch.yml https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/main/examples/workflows/gemini-dispatch/gemini-dispatch.yml
curl -o .github/workflows/gemini-invoke.yml https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/main/examples/workflows/gemini-assistant/gemini-invoke.yml
curl -o .github/workflows/gemini-plan-execute.yml https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/main/examples/workflows/gemini-assistant/gemini-plan-execute.yml

Note: The gemini-dispatch.yml workflow is designed to call multiple workflows. If you are only setting up gemini-invoke.yml and gemini-plan-execute.yml, you should comment out or remove the other jobs in your copy of gemini-dispatch.yml.

Dependencies

This workflow relies on the gemini-dispatch.yml workflow to route requests to the appropriate workflow.

Usage

Supported Triggers

The Gemini CLI Assistant workflow is triggered by new comments in:

  • GitHub Pull Request reviews
  • GitHub Pull Request review comments
  • GitHub Issues

The Gemini CLI Assistant workflow is intentionally configured not to respond to comments containing /review or /triage to avoid conflicts with other dedicated workflows (such as the Gemini CLI Pull Request workflow or the issue triage workflow).

How to Invoke the Gemini CLI Workflow

To use the general GitHub CLI workflow, just mention @gemini-cli in a comment in a GitHub Pull Request or an Issue, followed by your request. For example:

@gemini-cli Please explain what the `main.go` file does.
@gemini-cli Refactor the `calculateTotal` function in `src/utils.js` to improve readability.

Interaction Flow

The workflow follows a clear, multi-step process to handle requests:

flowchart TD
    subgraph "User Interaction"
        A[User posts comment with '@gemini-cli <request>']
        F{"Maintainer approves plan comment ('@gemini-cli /approve <url-or-id>')?"}
    end

    subgraph "Gemini CLI Workflow"
        B[Acknowledge Request]
        C[Checkout Code]
        D[Run Gemini]
        E{Is a plan required?}
        G[Post Plan for Approval]
        H[Verify Approved Plan & Execute Request]
        I{Request involves code changes?}
        J[Create Branch and Open Pull Request]
        K[Post Final Response]
    end

    A --> B
    B --> C
    C --> D
    D --> E
    E -- Yes --> G
    G --> F
    F -- Yes --> H
    F -- No --> K
    E -- No --> K
    H --> I
    I -- Yes --> J
    J --> K
    I -- No --> K
Loading
  1. Acknowledge: The action first posts a brief comment to let you know it received the request.
  2. Plan (if needed): For requests that involve code changes or multi-step actions, Gemini CLI creates a step-by-step plan and posts it as a comment. Copy the link or comment ID of that plan comment and reply with @gemini-cli /approve <comment-url-or-id>. Bare @gemini-cli /approve without a comment link or ID is rejected so only the exact bot-authored plan you reviewed can run.
  3. Execute: After verifying the approved plan comment's bot authorship (EXPECTED_PLAN_AUTHOR, which defaults to <app-slug>[bot] or github-actions[bot]), immutability, and pre-approval timestamp, the workflow runs Gemini CLI against that verified plan artifact.
  4. Open pull request (if needed): When the verified plan modifies files, Gemini CLI creates a feature branch, commits the file updates, and opens a pull request for review. We recommend enabling branch protection rules on your default branch (main).
  5. Respond: Gemini CLI posts a final summary comment on the issue or pull request.

Configuration

The Gemini CLI assistant prompts are defined in the gemini-invoke.toml and gemini-plan-execute.toml files. The action automatically copies these files from .github/commands/ to .gemini/commands/ during execution.

To customize the assistant prompt:

  1. Copy the TOML file to your repository:

    mkdir -p .gemini/commands
    curl -o .gemini/commands/gemini-invoke.toml https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/main/examples/workflows/gemini-assistant/gemini-invoke.toml
    curl -o .gemini/commands/gemini-plan-execute.toml https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/main/examples/workflows/gemini-assistant/gemini-plan-execute.toml
  2. Edit .gemini/commands/gemini-invoke.toml and .gemini/commands/gemini-plan-execute.toml to customize:

    • Change its persona or primary function
    • Add project-specific guidelines or context
    • Instruct it to format its output in a specific way
    • Modify security constraints or workflow steps
  3. Commit the file to your repository:

    git add .gemini/commands/gemini-invoke.toml
    git commit -m "feat: customize Gemini assistant prompt"

The workflow will use your custom TOML file instead of the default one from the action.

For more details on workflow configuration, see the Configuration Guide.

Examples

More Gemini CLI Assistant workflow examples:

Asking a Question

@gemini-cli What is the purpose of the `telemetry.js` script?

Requesting a Code Change

@gemini-cli In `package.json`, please add a new script called "test:ci" that runs `npm test`.

Summarizing an Issue

@gemini-cli Can you summarize the main points of this issue thread for me?