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 togemini -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
Thegemini-cli backend ships with this default configuration:
Backend CLI Flags
The backend builds thegemini 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 onagent.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
TimeoutErroris now returned asCliBackendResult(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_resumeis 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
- Use gemini-2.5-flash for quick tasks
- Use gemini-2.5-pro for complex analysis
- Include relevant directories for better context
- Use execute_with_stats() to monitor usage
- Set appropriate timeouts for large codebases

