ai is a powerful, extensible command-line interface for interacting with OpenAI-compatible APIs. Beyond simple prompting, it features a full Agentic Mode with support for the Model Context Protocol (MCP), Local RAG (Retrieval-Augmented Generation), Voice Interaction, and more.
- Agentic Capabilities: Enable the AI to perform multi-step tasks using tools (
-aflag). - MCP Support: Connect to any Model Context Protocol server to give the AI access to local resources (databases, APIs, etc.).
- Local RAG: Chat with your local documents (
.pdf,.docx,.xlsx,.epub,.md, etc.) using local embedding models for privacy and speed (--rag). - Voice Mode (not implemented yet, WIP): Talk to the AI and hear its responses using OpenAI Whisper and TTS (
--voice). - Context Inclusion: Easily inject local files as context via glob patterns (
--glob). - Session Management: Save and load your chat history to/from Markdown files (
--save-session,--session). - Interactive Chat: Continuous conversational workflows with memory (
-i,-m). - Flexible Input: Standard input (stdin) piping, command-line arguments, and external editor integration (
-e).
- Go 1.21+
- An OpenAI API Key (or compatible provider).
- (Optional) MCP:
npxor other runtimes if you plan to use specific MCP servers. - (Optional) Voice Mode: Requires the
portaudioC library (e.g.,brew install portaudioon macOS,sudo apt-get install portaudio19-devon Debian/Ubuntu). Linux users may also need an audio player likempg123orffmpeginstalled for playback.
go install github.com/yuriiter/ai@latestThe tool uses environment variables for default configuration.
| Environment Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
Required. Your API key. | None |
OPENAI_BASE_URL |
Optional. Base URL for the API (useful for Ollama, Azure, etc.). | https://api.openai.com/v1 |
OPENAI_MODEL |
Optional. The specific model to use. | gpt-4o |
OPENAI_SYSTEM_INSTRUCTIONS |
Optional. Default system prompt/persona. | Built-in helper persona |
OPENAI_TEMPERATURE |
Optional. Default temperature (creativity). | 1.0 |
EDITOR |
Optional. Editor for the -e flag. |
vim, nano, or vi |
Just like echo, you can pass arguments directly:
ai Explain the concept of recursionStart a chat session with memory:
ai -imEasily dump files directly into the AI's context window.
ai --glob "*.go" "Find any bugs in these files"Use --rag to index and search through large documents locally. The tool automatically extracts text, generates local embeddings (sentence-transformers), and caches them for fast repeated use.
ai --rag "docs/**/*.md" --rag "*.pdf" -iTalk to your agent! Press SPACE to start recording and SPACE again to send. The AI will speak its response back to you.
ai -im --voiceSave your conversation to a Markdown file to resume later or keep a record.
# Save a session
ai -im --save-session chat.md
# Resume a session
ai -im --session chat.mdThe real power of ai comes from connecting it to MCP servers. This allows the AI to "do" things rather than just talk.
To use tools, you must enable agent mode (-a) and provide an MCP server command (--mcp).
Example: Giving the AI access to your filesystem
(Requires npx installed)
ai -a --mcp "npx -y @modelcontextprotocol/server-filesystem ." \
"Read the file 'main.go' and tell me what the package name is"You can chain multiple MCP servers:
ai -a \
--mcp "npx -y @modelcontextprotocol/server-filesystem ." \
--mcp "python3 my_custom_server.py" \
"Analyze my files and upload the summary to my custom server"Use -e to open your default text editor (Vim/Nano) to compose complex prompts. If you pipe data in, it will appear in the editor for you to annotate.
git diff | ai -e
# Opens editor with the diff, letting you add: "Write a commit message for these changes"| Flag | Short | Description |
|---|---|---|
--agent |
-a |
Enable agentic capabilities (required for MCP tools). |
--editor |
-e |
Open editor to compose prompt. |
--glob |
Glob patterns to include files as full text context. | |
--interactive |
-i |
Start interactive chat mode. |
--mcp |
Command to start an MCP server (can be used multiple times). | |
--memory |
-m |
Retain conversation history between turns (useful in scripts). |
--rag |
Glob patterns for RAG documents (can be used multiple times). | |
--rag-top |
Number of RAG context chunks to retrieve (default: 3). | |
--save-session |
Save chat history to a Markdown file. | |
--session |
Load chat history from a Markdown file. | |
--steps |
Maximum number of agentic steps allowed (default: 10). | |
--temperature |
-t |
Set model temperature (0.0 - 2.0). |
--voice |
Enable voice interaction (requires --interactive). |
- Clone the repository.
- Ensure you have
portaudioinstalled on your system. - Build the binary:
go build -o ai main.go