rai

command module
v0.0.0-...-7edc2c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

RAI - LLM from CLI

A headless agentic loop, supporting scripting, tools, template-based prompts, LSP, and MCP integrations.

Status

Features

  • 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

Installation

go install github.com/elek/rai@latest

Or build from source:

git clone https://github.com/elek/rai.git
cd rai
go build

Configuration

Create ~/.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: 4000

Usage

Ask a question
rai 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"
Run custom prompts
rai do summarize myfile.txt

This 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).

Template XML elements
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
List available models
rai models
rai models anthropic
Interactive mode
rai run

Starts an interactive REPL conversation (work in progress).

Agent Tools

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 a list-symbols tool for code navigation
  • MCP: <mcp command="some-mcp-server"/> loads all tools exposed by the MCP server

Development

go build                # Build
go test ./...           # Run all tests
go vet ./...            # Lint
go fmt ./...            # Format

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package llm defines a provider-neutral interface for large language models and an agent loop that drives multi-turn tool calling on top of it.
Package llm defines a provider-neutral interface for large language models and an agent loop that drives multi-turn tool calling on top of it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL