Skip to main content

Gemini CLI Integration

PraisonAI provides integration with Google’s Gemini CLI for AI-powered code analysis, generation, and refactoring tasks.

Installation

Quick Start

Use as Agent Backend

Delegate an Agent’s LLM turns to gemini -p instead of the Gemini API — uses your Google account.
cli_backend= is deprecated (removal in 2.0.0). Prefer runtime="gemini-cli". Run praisonai doctor fix --execute to auto-migrate YAML.

Backend Configuration

The gemini-cli backend ships with this default configuration:

Backend CLI Flags

The backend builds the gemini command with these flags:
Gemini has no --system-prompt flag, so PraisonAI prepends the system prompt to the user prompt with \n\n (f"{system_prompt}\n\n{prompt}").

Configuration Options

Examples

Basic Execution

Model Selection

Multi-Directory Context

With Usage Stats

Streaming Output

As Agent Tool

As a native async agent tool

Preferred when the agent runs on agent.astart(...) (or any async entrypoint) — the tool is awaited directly on the running loop with no thread hop.
as_async_tool() was added in PraisonAI PR #4022; as_tool() still works and is now also safe to call from inside an async agent runtime.

Environment Variables

CLI Flags Used

The integration uses the following Gemini CLI flags:

JSON Output Schema

The JSON output includes:

Error Handling

Robustness (PR #4111)

  • A subprocess TimeoutError is now returned as CliBackendResult(error=...) instead of escaping as an exception.
  • On CalledProcessError, the CLI’s actual stderr diagnostic is surfaced (previously only the exit status was shown).
  • -m (model) and cwd are threaded through, so scheduled runs can pin a model and run in a workspace.
  • CliSessionBinding.is_resume is now set on the second turn of a session, so the resume branch runs instead of re-sending the system prompt every turn.

Best Practices

  1. Use gemini-2.5-flash for quick tasks
  2. Use gemini-2.5-pro for complex analysis
  3. Include relevant directories for better context
  4. Use execute_with_stats() to monitor usage
  5. Set appropriate timeouts for large codebases