A headless agentic loop, supporting scripting, tools, template-based prompts, LSP, and MCP integrations.
- Multi-provider support - Anthropic (Claude), OpenAI
- Agent tools - Built-in tools for git, file reading/listing/creation, and file editing
- Template system - Custom prompt templates with Go templates or Pongo2 (Django-style)
- LSP integration - Language Server Protocol support for code understanding (e.g., gopls)
- MCP integration - Model Context Protocol for connecting external tools
- Streaming output - Token-by-token response streaming with usage/cost reporting
- **ACP mode ** - Can be used as an ACP backend
go install github.com/elek/rai@latestOr build from source:
git clone https://github.com/elek/rai.git
cd rai
go buildCreate ~/.config/rai/config.yaml:
providers:
- name: anthropic
type: anthropic
key: sk-ant-xxxxx
- name: google
type: google
key: AIzaSyxxxxx
- name: openrouter
type: openrouter
key: sk-or-xxxxx
models:
- name: claude
provider: anthropic
model: claude-3-5-sonnet-20241022
max_token: 2000
temperature: 0.7
default: true
- name: gemini
provider: google
model: gemini-2.0-flash
max_token: 4000rai ask "What is the capital of France?"
rai ask --model gemini "Explain Go interfaces"
rai ask --with-tools "List all Go files in the current directory"The --with-tools flag enables agent tools (git, file operations) so the model can interact with your local environment.
You can also specify a model inline with provider/model syntax:
rai ask --model anthropic/claude-3-5-sonnet-20241022 "Hello"rai do summarize myfile.txtThis loads a template from ~/.config/rai/summarize and renders it with the provided arguments. Templates support XML-based prompt structure:
<model>claude</model>
<system>You are a helpful assistant.</system>
<tool name="cat"/>
<tool name="files"/>
Summarize the following file: {{index .Args 0}}Template files can use either Go templates (default) or Pongo2 (prefix with %pongo2).
| Element | Description |
|---|---|
<system> |
System prompt |
<model> |
Model name or provider/model |
<tool name="..."> |
Enable a built-in agent tool (git, cat, files, create, insert) |
<mcp command="..."> |
Start an MCP server and load its tools |
<lsp command="..."> |
Start an LSP server (e.g., gopls) |
<exec command="..."> |
Execute a shell command, inline output |
<shell>...</shell> |
Execute a shell script block, inline output |
rai models
rai models anthropicrai runStarts an interactive REPL conversation (work in progress).
When using --with-tools or <tool> elements in templates, the following tools are available:
| Tool | Description |
|---|---|
git |
Execute git commands |
cat |
Read file contents with optional offset/limit and line numbers |
files |
List files with recursive traversal and glob patterns |
create |
Create new files |
insert |
Insert content at a specific line in a file |
Additionally, LSP and MCP integrations allow extending the tool set:
- LSP:
<lsp command="gopls"/>adds alist-symbolstool for code navigation - MCP:
<mcp command="some-mcp-server"/>loads all tools exposed by the MCP server
go build # Build
go test ./... # Run all tests
go vet ./... # Lint
go fmt ./... # Format