A command-line AI assistant that combines Google Gemini with Tavily Search to provide intelligent, source-backed answers directly from your terminal.
๐ Versiรณn en espaรฑol
- ๐ค AI-Powered Answers โ Uses Google Gemini 2.5 Flash for natural language understanding and generation
- ๐ Real-Time Web Search โ Leverages Tavily API with advanced search depth to ground responses with up-to-date web data
- ๐ฌ Interactive Chat Mode โ Conversational interface with session-based chat history maintained in memory
- ๐ ๏ธ Genkit Tool System โ Search is exposed as a Genkit tool, allowing the AI to autonomously decide when to search the web
- ๐ Source Citations โ Responses include numbered source citations and a dedicated Sources section with URLs
- ๐จ Beautiful Terminal UI โ Colored output, spinners, and formatted responses using Chalk and Ora
- ๐ง Genkit Dev Tools โ Built on Firebase Genkit for observability, tracing, and debugging
- Node.js v18 or higher
- A Tavily API Key (for web search)
- A Google AI API Key (for Gemini model)
git clone https://github.com/juanan09/percli.git
cd perclinpm installCopy the example file and add your API keys:
cp .env.example .envEdit .env with your keys:
# Tavily API Key - Get it from https://tavily.com
TAVILY_API_KEY=your_tavily_api_key_here
# Google AI API Key - Get it from https://aistudio.google.com/app/apikey
GOOGLE_API_KEY=your_google_api_key_here# Production mode
npm start
# Development mode (with Genkit Dev UI for tracing and debugging)
npm run devOnce running, you'll see an interactive prompt:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Welcome to Percli CLI - Interactive Mode โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Type your questions and get AI-powered answers with sources!
Chat history is maintained during this session.
Commands: exit, quit, or press Ctrl+C to leave
๐ฌ Ask a question (or type "exit" to quit):
Simply type your question and press Enter. The AI will:
- Analyze your query
- Automatically search the web if current information is needed
- Synthesize information from multiple sources
- Provide a comprehensive, well-structured answer with source citations
Commands:
| Command | Description |
|---|---|
exit / quit |
Exit the application |
Ctrl+C |
Force quit |
๐ก Tip: Chat history is maintained during your session, so the AI remembers previous questions and can build on prior context.
PerCLI is built on a tool-augmented agent architecture using Firebase Genkit:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ index.js (CLI Loop) โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ readline โ โ chalk โ โ ora โ โ
โ โ (user I/O) โ โ (colors) โ โ (spinners) โ โ
โ โโโโโโโโฌโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ agent.js (Chat Agent) โ โ
โ โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Genkit Prompt โ โ searchWeb Tool โ โ โ
โ โ โ (system prompt โ โ (AI decides when to โ โ โ
โ โ โ + model cfg) โ โ invoke search) โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ โ
โ โ search.js (Tavily Integration) โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Advanced search ยท Max N results ยท Answer โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
index.jsโ Entry point. Sets up the Genkit AI instance, Tavily client, and readline-based interactive loop. Validates environment variables and manages the CLI lifecycle.src/agent.jsโ Defines the AI chat agent. Creates a Genkit prompt with a system instruction that tells the AI how to respond, and registers asearchWebtool that the AI can call autonomously. Uses Zod schemas for input/output validation.src/search.jsโ Wraps the Tavily API client. Performs advanced web searches with configurable result limits and returns structured results (title, URL, content).
percli/
โโโ index.js # Entry point โ interactive CLI loop & initialization
โโโ src/
โ โโโ agent.js # Chat agent config โ prompt, model, and tool registration
โ โโโ search.js # Tavily web search wrapper with advanced search depth
โโโ .env.example # Environment variables template
โโโ .gitignore # Git ignore rules
โโโ package.json # Dependencies, scripts, and project metadata
โโโ README.md # This file (English)
โโโ README_ES.md # Documentation in Spanish
| Package | Version | Description |
|---|---|---|
| genkit | ^1.29.0 | Firebase Genkit framework for building AI-powered applications |
| @genkit-ai/google-genai | ^1.29.0 | Google Gemini plugin for Genkit |
| @genkit-ai/googleai | ^1.28.0 | Google AI integration for Genkit |
| @tavily/core | 0.7.2 | Tavily search API client for real-time web search |
| chalk | ^5.6.2 | Terminal string styling with colors and formatting |
| ora | ^9.3.0 | Elegant terminal spinners for loading states |
| dotenv | ^17.3.1 | Loads environment variables from .env files |
| Package | Version | Description |
|---|---|---|
| genkit-cli | ^1.29.0 | Genkit CLI for dev UI, tracing, and debugging |
| Script | Command | Description |
|---|---|---|
start |
npm start |
Runs the CLI in production mode (node index.js) |
dev |
npm run dev |
Runs with Genkit Dev UI for tracing and debugging (npx genkit start -- node index.js) |
test |
npm test |
Placeholder for tests (not yet implemented) |
All configuration is done through environment variables in the .env file:
| Variable | Required | Description |
|---|---|---|
TAVILY_API_KEY |
โ | API key for Tavily web search โ get it at tavily.com |
GOOGLE_API_KEY |
โ | API key for Google Gemini โ get it at AI Studio |
PerCLI uses Google Gemini 2.5 Flash as its underlying language model, configured through Genkit. The model is instructed to:
- Provide comprehensive, factual answers based on web search results
- Synthesize information from multiple sources
- Use numbered citations
[1],[2], etc. to reference sources - Include a "Sources" section at the end of each response with reference URLs
- Use markdown formatting for better readability
- Autonomously decide when to use the web search tool
PerCLI includes robust error handling:
- Missing API keys โ Clear error messages with actionable tips if
TAVILY_API_KEYorGOOGLE_API_KEYare not set - Search failures โ Tavily search errors are caught and surfaced with descriptive messages
- Runtime errors โ Per-query errors are caught without crashing the session, allowing continued interaction
- Graceful shutdown โ Clean exit with farewell message on
exit,quit, orCtrl+C
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
Made with โค๏ธ using Genkit, Google Gemini, and Tavily