athena-agent
v0.18.6
Published
Athena — a personal AI agent harness. Agent loop, tool calling, multi-provider LLM client, messaging gateway, Hermes-style memory & skills, Recursive Language Models.
Maintainers
Readme
Athena Agent
A personal AI agent harness — agent loop, tool calling, multi-provider LLM client, messaging gateway, Hermes-style memory & skills, and Recursive Language Models. Minimal dependencies (@anthropic-ai/sdk, @earendil-works/pi-tui for the TUI, update-notifier), TypeScript strict, 206 tests.
On npm —
athena-agent(bin:athena). Install it globally and runathenaanywhere.
Built from the ground up, inspired by four projects:
| Inspiration | What we borrowed |
|---|---|
| pi-agent | Unified multi-provider LLM client abstraction, agent runtime with tool calling + state, CLI entry |
| Hermes-Function-Calling | ChatML-style prompting, <tool_call>/<tool_response> XML-tagged function calling, recursive tool loop |
| Hermes Agent | SKILL.md format, MEMORY.md persistent memory, auto-generated skills |
| OpenClaw | Gateway/channel architecture, setup/doctor workflow, pairing access control |
See NOTICE for full attribution and research references.
Quickstart
Option A — install from npm (recommended):
npm install -g athena-agent
# First run: set up the harness (interactive wizard)
athena setup
# Or non-interactive defaults (local Ollama)
athena setup --baseline
# Chat
athena # interactive TUI (pi-agent style)
athena --repl # or the minimal REPL
athena "What is 15 * 7 + 3? Use the calculate tool." # one-shot
# Health check
athena doctorOption B — from source:
npm install
npm run build
node dist/index.js setup # or athena setup after `npm link`
node dist/index.js # or athenaRequires Node 22+. Defaults to a local Ollama server — zero configuration needed if you have one running.
Documentation
| Doc | Contents | |---|---| | docs/ARCHITECTURE.md | System design, module map, data flow | | docs/PROVIDERS.md | All providers, presets, custom + OAuth login | | docs/CHANNELS.md | Messaging channels, gateway, access control | | docs/RLM.md | Recursive Language Models (research + usage) | | docs/PERMISSIONS.md | Permission modes, rules, approval flows | | CHANGELOG.md | Version history | | CONTRIBUTING.md | How to contribute | | SECURITY.md | Security policy |
Features
- Recursive Language Models (RLM) —
athena rlm "question"/athena rlm --file <path>: the paper's Algorithm 1 (arXiv:2512.24601) recreated in TypeScript. The prompt lives as a variable in a sandboxed REPL (node:vm, zero deps) — the model writes code to probe/decompose it and recursively calls itself (sub_rlm) over snippets. Only constant-size metadata + truncated stdout enter the context, so prompts far beyond the context window work. Depth cap (default 1 — depth-2 "overthinks" per the reproduction study), per-block timeout, sub-call limits,Finalprotocol. - SRLM —
athena rlm --srlm: self-reflective program search (arXiv:2603.15653). Samples N candidate programs per iteration, scores by execution success + verbalized confidence, picks the best. Up to 22% over RLM; works without recursion. - Chained-RLM —
athena rlm --chained <n>: fresh-context roots with blackboard handoff (arXiv:2608.05124). Each root gets the problem + a compact summary of predecessors (not the full history); final answer via majority vote. - Async sub-calls —
sub_rlm_all(prompts)in the RLM REPL runs sub-calls in parallel (the paper's future work). - Built-in core skills (non-removable) —
athena-core+athena-tools(complete toolset guide, progressive disclosure) ship with the harness, always loaded, andathena skills remove <name>is rejected for them.athena skillslists core/custom/generated skills;athena skills view <name>shows content. - Hermes-style memory — persistent facts stored in
MEMORY.md(data dir), loaded into the system prompt each session. Tools:memory_read/memory_write/memory_search(term-scoring over facts + past sessions;--semanticuses Ollama embeddings + cosine similarity with automatic fallback). CLI:athena memory(show/add/search/clear). - Skill hub — publish/tap/install/search (Hermes publish-tap equivalent):
athena skills publish <name> <tap-dir>,tap add|remove|list,install <skill>,search <q>. Local dir taps + HTTP taps. - Auto-generated skills — the self-improvement loop: the agent calls
skill_create(name, description, steps)to persist a reusable workflow as a Hermes-styleSKILL.mdin<skillsDir>/generated/, discovered automatically next session. Manage withathena skills version|edit|export|import(version bumps are semver-aware). - Session management —
athena sessions(list/show/delete/rename), session titles from the first user message,--session <id>resumes history in one-shot mode, REPL/sessions/resume/delete. - Access permission modes —
safe(default: read-only tools auto-allowed, sensitive tools ask),auto(everything allowed),restricted(everything asks). Per-tool rules override the mode (allow/ask/deny). Interactive approval in REPL/TUI (y/n/a=always), gateway approval via/approve <id>//deny <id>//pending. Sensitive tools:file_write,shell,web_fetch,web_search,file_read. - Provider registry —
athena providerslists everything: 3 built-ins (ollama/openai/anthropic), 13 one-click presets (OpenRouter, Groq, Together, Fireworks, DeepInfra, Cerebras, Mistral, xAI, DeepSeek, Perplexity, LM Studio, vLLM, llama.cpp), plus custom providers: any OpenAI-compatible endpoint (Azure, gateways, your own server) or a module provider (arbitrary JS/TS implementing the provider interface — connect to anything). - Messaging gateway —
athena gatewayconnects the agent to messaging channels (OpenClaw-style): Telegram (long-polling, no server), Discord (gateway websocket), Slack (Socket Mode), WhatsApp (Meta Cloud API webhook), Signal (viasignal-cliREST/WS — same pattern as OpenClaw, no libsignal), Matrix (sync loop), iMessage (macOS AppleScript). Teams/Feishu/Zalo stubs with setup hints. Per-chat sessions, allowlist + pairing access control, loop protection. - Channel setup —
athena channels addinteractive wizard;athena doctorvalidates channel credentials. - Setup workflow —
athena setupinteractive wizard (provider → credentials → inference verification → config file) orathena setup --baselinefor non-interactive defaults.athena configurere-runs it. - Doctor —
athena doctorhealth checks: node version, config, data/skills dirs, provider credentials, live inference. Exit code 0 = healthy. - Auto-update —
athena updatechecks the npm registry for a new release; a cached startup check also prints an update notice when you launch the REPL/TUI. - Config file —
~/.athena/config.jsonas single source of truth; env vars always override;athena configshows the effective config (secrets redacted). - Built-in software principles —
athena principlesprints them;ATHENA_PRINCIPLES=true(or"principles": truein config) injects them into the agent's system prompt. - Modes — first-class dispatch:
setup,configure,doctor,config,principles, REPL (default),--tui, one-shot,--json,--sandbox. All additive — every existing flag keeps working. - Agent loop — runs model → executes tool calls → feeds results back → repeats until the model answers (capped by
ATHENA_MAX_ITERATIONS). - Streaming — token-by-token output in the REPL and one-shot mode (SSE for OpenAI-compatible, SDK stream for Anthropic).
- Dual-mode tool calling:
- Native — OpenAI
toolsparameter / Anthropic tool use for cloud providers. - Hermes —
<tool_call>XML-tagged JSON for local models (Ollama), with a tolerant parser that repairs malformed JSON (trailing commas, single quotes, stringified args).
- Native — OpenAI
- Multi-provider — Ollama (local), OpenAI (or any OpenAI-compatible endpoint), Anthropic. Zero config for Ollama.
- Memory — conversations persist to
~/.athena/sessions/(JSONL)./new,/sessions,/resume <id>,/delete <id>in the REPL; history auto-trimmed (first user message preserved). - Tool registry — register/list/execute tools with required-arg validation. Built-ins:
get_time,calculate,get_weather(mock),web_fetch,web_search(DuckDuckGo, no key),file_read,file_write,shell(disabled by default). - Skills — loadable skill bundles (OpenClaw-style):
skill.jsonmanifest + tool implementations, merged into the agent at startup. - JSON mode — structured output against a JSON schema (Hermes
jsonmode.pyequivalent):athena --json <schema.json> "question". - Sandbox —
athena --sandboxre-executes under Node's permission model: file_write limited to the data dir, shell/child processes blocked. - TUI —
athenaopens a full-screen terminal UI built on pi's own@earendil-works/pi-tuiframework (the exact pi-agent look): markdown-rendered assistant messages, boxed user messages, a footer with git branch + token count + context usage %, and a spinner status indicator.--replforces the minimal REPL. - CLI — interactive REPL (
/help,/tools,/new,/sessions,/resume,/delete,/exit) or one-shotathena "question".
Install
# Global install from npm (bin: `athena`) — recommended
npm install -g athena-agent
# Or install locally in a project
npm install athena-agentNote: the source repository is private. The npm package is the public distribution channel.
Usage
The athena bin is used below; after a source build you can npm link to get the same command, or call node dist/index.js directly.
# First run: set up the harness
athena setup # interactive wizard
athena setup --baseline # non-interactive defaults
# Health check
athena doctor
# Check for a new release on npm
athena update
# Interactive TUI (default, pi-agent style)
athena
# Minimal REPL (no full-screen UI)
athena --repl
# One-shot
athena "What is 15 * 7 + 3? Use the calculate tool."
# Structured JSON output
athena --json person.schema.json "Return a JSON object for Ada Lovelace, age 36."
# Sandboxed run (file_write limited to data dir, shell blocked)
athena --sandbox "Write a note to my data dir."
# Full-screen TUI
athena --tui
# Built-in software principles
athena principles
# Messaging channels
athena channels add # interactive channel setup
athena gateway # run the gateway with enabled channels
# Providers
athena providers # list all providers
athena providers add groq --type openai-compatible --base-url https://api.groq.com/openai/v1 --api-key <key> --model llama-3.3-70b-versatile
athena providers set groq # make it active
athena providers add my-custom --type module --path ./providers/my-provider.ts
# Permissions
athena permissions # show mode + rules
athena permissions set restricted
athena permissions rule shell deny
athena permissions unrule shell
# Recursive Language Model (long prompts beyond the context window)
athena rlm "question"
athena rlm --file huge-document.txt
athena rlm --srlm # self-reflective program search
athena rlm --chained 3 # fresh roots + blackboard handoff
# Skills, memory, sessions
athena skills # list skills (core is non-removable)
athena skills view <name>
athena skills version <name> [major|minor|patch]
athena skills export <name> <file.md>
athena skills import <file.md>
athena skills publish <name> <tap-dir>
athena skills tap add <name> <dir-or-url>
athena skills install <skill>
athena skills search <query>
athena memory # show MEMORY.md
athena memory add <fact>
athena memory search [--semantic] <query> # term or embedding recall
athena sessions # list sessions
athena sessions rename <id> <title>
athena --session <id> "question" # one-shot with session history
# Show configured provider/model
athena --infoRecursive Language Models (RLM)
athena rlm recreates the RLM paradigm (arXiv:2512.24601, MIT) in TypeScript:
- The prompt is loaded as a variable
Pin a sandboxed REPL (node:vm) — it never enters the model's context window. - The model writes JavaScript code to probe
P(print(P.length),P.slice(...)), decompose it, and callsub_rlm(prompt)recursively over snippets (inside loops). - Only constant-size metadata + truncated stdout are fed back; the loop ends when the model sets
Final.
{ "rlm": { "maxDepth": 1, "maxIterations": 20, "timeoutMs": 30000, "maxStdoutChars": 2000, "maxSubCalls": 20, "srlmCandidates": 3, "chainedRoots": 3, "chainedBlackboardChars": 2000 } }maxDepth1 is the sweet spot (the reproduction study shows depth-2 "overthinks": 3.6s → 344.5s).- The REPL sandbox blocks
require/process/fetch; note:node:vmis not a security boundary (same trust level as module providers). - Live-verified: an 81KB prompt answered correctly with only 273 bytes of metadata in context; SRLM and Chained-RLM verified on arithmetic tasks.
Access permissions
Three modes (config permissions.mode, default safe):
| Mode | Behavior |
|---|---|
| safe | Read-only tools auto-allowed; sensitive tools ask (file_write, shell, web_fetch, web_search, file_read) |
| auto | Everything allowed (trusted setups) |
| restricted | Everything asks except explicitly allowed tools |
Per-tool rules override the mode: athena permissions rule <tool> <allow|ask|deny>.
Approval flows:
- REPL/TUI: prompt
Allow? (y/n/a=always)—aremembers the decision for the same tool+args for the session. - Gateway: the bot sends
[permission] <tool>(<args>)+ request id; you reply/approve <id>or/deny <id>(or/pendingto list). Requests expire after 5 minutes. - Piped/non-interactive: no approver → denied (fail-closed).
{ "permissions": { "mode": "safe", "rules": [ { "tool": "shell", "action": "deny" } ] } }Providers
athena providers lists everything. Three kinds:
- Built-in —
ollama,openai,anthropic(env/config as before). - Presets — one-click OpenAI-compatible endpoints; set the API key via
ATHENA_<NAME>_API_KEYor add as custom:openrouter,groq,together,fireworks,deepinfra,cerebras,mistral,xai,deepseek,perplexity,lmstudio,vllm,llamacpp. - Custom —
athena providers add <name>:--type openai-compatible --base-url <url> [--api-key <key>] [--model <model>]— any OpenAI-shaped endpoint (Azure, gateways, local servers).--type module --path <file>— a JS/TS module exportingcreateProvider(config)returning anLLMProvider(pi-style; connect to anything). Trust boundary: module providers are user-authored code running with your permissions.
{
"provider": "groq",
"providers": {
"groq": { "type": "openai-compatible", "baseUrl": "https://api.groq.com/openai/v1", "apiKey": "...", "model": "llama-3.3-70b-versatile" },
"my-custom": { "type": "module", "path": "./providers/my-provider.ts" }
}
}Example session:
you> What time is it in Asia/Jakarta right now? Use the get_time tool.
[tool] get_time({"timezone":"Asia/Jakarta"})
athena> The current time in Asia/Jakarta is Saturday, August 15, 2026, at 9:42:55 PM (GMT+7).REPL commands: /help, /tools, /new (fresh session), /sessions (list saved), /resume <id> (continue a saved session), /delete <id>, /exit.
TUI keys: Enter submit · ↑/↓ input history · PgUp/PgDn scroll · Ctrl-C/Ctrl-D quit.
Configuration
Copy .env.example to .env (or export the variables). The harness reads plain environment variables — no dotenv dependency.
| Variable | Default | Description |
|---|---|---|
| ATHENA_PROVIDER | ollama | ollama | openai | anthropic |
| ATHENA_OLLAMA_BASE_URL | http://localhost:11434 | Ollama server |
| ATHENA_OLLAMA_MODEL | deepseek-v4-flash:0731-cloud | Local model |
| ATHENA_OPENAI_API_KEY | — | Required for openai |
| ATHENA_OPENAI_BASE_URL | https://api.openai.com/v1 | Any OpenAI-compatible endpoint |
| ATHENA_OPENAI_MODEL | gpt-4o-mini | |
| ATHENA_ANTHROPIC_API_KEY | — | Required for anthropic |
| ATHENA_ANTHROPIC_MODEL | claude-sonnet-4-5 | |
| ATHENA_MAX_ITERATIONS | 8 | Agent loop cap |
| ATHENA_SYSTEM_PROMPT | built-in | System prompt override |
| ATHENA_DATA_DIR | ~/.athena | Data root (sessions live in <dir>/sessions) |
| ATHENA_SKILLS_DIR | <data dir>/skills | Skills directory |
| ATHENA_ALLOW_SHELL | false | Set true to enable the shell tool |
| ATHENA_PRINCIPLES | false | Set true to inject software principles into the system prompt |
| ATHENA_CONFIG_PATH | ~/.athena/config.json | Config file path |
Config precedence: env vars > config file > defaults. athena setup writes the config file; env vars always win so existing env-only setups keep working.
Messaging channels
Channels are configured in the channels section of config.json (or via athena channels add):
{
"channels": {
"telegram": { "enabled": true, "allowFrom": [], "token": "123:abc" },
"discord": { "enabled": true, "allowFrom": ["*"], "token": "bot-token" },
"slack": { "enabled": true, "allowFrom": [], "appToken": "xapp-...", "botToken": "xoxb-..." },
"whatsapp": { "enabled": true, "allowFrom": [], "phoneNumberId": "...", "accessToken": "...", "verifyToken": "..." },
"signal": { "enabled": true, "allowFrom": [], "account": "+15551234567", "baseUrl": "http://127.0.0.1:8080", "transport": "container" },
"matrix": { "enabled": true, "allowFrom": [], "homeserver": "https://matrix.org", "accessToken": "...", "userId": "@athena:matrix.org" },
"imessage": { "enabled": true, "allowFrom": [] }
}
}- Access control:
allowFromlists sender ids allowed to chat. Empty = pairing mode — unknown senders get a/pair <code>challenge (OpenClawdmPolicy: pairing)."*"= open. - Loop protection: bot's own messages are ignored on every channel.
- Per-chat sessions: each chat gets its own agent instance with bounded history.
- Signal: requires
signal-cli(brew install) or thebbernhard/signal-cli-rest-apicontainer, plus a linked/registered bot number. OpenClaw's exact pattern — we drive the external daemon, we don't embed libsignal. - WhatsApp: requires a Meta Business account + WhatsApp Business number; the webhook needs a public URL (tunnel with ngrok/cloudflared for local testing).
- iMessage: macOS only; send via AppleScript, receive via chat-DB polling (best-effort, schema varies by macOS version).
- Teams/Feishu/Zalo: stubs — require platform app registrations; configure manually when you have credentials.
Safety gates
file_read/file_write/file_list/file_grep— paths must resolve inside the workspace (cwd) orATHENA_DATA_DIR(realpath-checked, symlink-safe); 256 KB read/write cap.code_exec— sandboxednode:vmexecution; blocksrequire/process/fetch; capturesprint+console.log; 15s timeout; permission-gated in safe mode.shell— disabled by default. Enable withATHENA_ALLOW_SHELL=true; commands must start with an allowlisted binary (ls,cat,pwd,echo,date,whoami,uname,git status,git diff,git log --oneline -10,node --version,npm --version); 30s timeout; no interactive input.--sandbox— re-executes under Node's permission model:file_writerestricted toATHENA_DATA_DIR, child processes blocked. Note: Node 22's permission model has no--allow-netflag, so network stays open (needed for the LLM API and web tools); Node 23+ can scope it with--allow-net=....
Skills
A skill is a directory with a skill.json manifest and tool implementations in tools/:
skills/
my-skill/
skill.json # { name, description, systemPrompt?, tools: [definitions] }
tools/
my_tool.ts # export async function execute(args) { ... }Point ATHENA_SKILLS_DIR at your skills directory (default ~/.athena/skills). Skills merge their tools and system-prompt additions into the agent at startup; duplicate tool names are rejected. See skills/example/ for a working example.
Adding your own tools
Tools are plain objects — register them in src/index.ts (or your own entry):
import type { Tool } from './types.js';
const myTool: Tool = {
definition: {
name: 'my_tool',
description: 'What it does',
parameters: {
type: 'object',
properties: { arg: { type: 'string' } },
required: ['arg'],
},
},
async execute(args) {
return { result: args['arg'] };
},
};Architecture
src/
types.ts Shared contracts (Message, ToolCall, LLMProvider, Session, Skill, ...)
config.ts Config loader (file + env, single source of truth)
setup.ts Setup wizard (interactive + --baseline)
doctor.ts Health checks
principles.md Built-in software principles (single source of truth)
principles.ts Principles command + system-prompt injection
llm/
openai-compatible.ts OpenAI / Ollama / any OpenAI-compatible endpoint (chat + SSE stream)
anthropic.ts Anthropic Messages API (native tool use, SDK stream)
factory.ts Provider factory from env
agent/
parser.ts Hermes <tool_call> XML parser (tolerant)
loop.ts Agent loop (pi-agent-core style) + streamRun
jsonmode.ts Structured JSON output (Hermes jsonmode.py equivalent)
memory/
store.ts Session persistence (JSONL)
tools/
registry.ts Tool registry with arg validation
builtin.ts get_time, calculate, get_weather, web_fetch, web_search, file_read, file_write, shell
skills/
loader.ts Skill loader + registry merge
cli/
repl.ts Interactive REPL (streaming, session commands)
tui.ts Full-screen TUI (blessed)
channels/
types.ts ChannelAdapter / Envelope contracts
gateway.ts Gateway: routing, per-chat sessions, pairing
telegram.ts Telegram Bot API (long-polling)
discord.ts Discord gateway websocket
slack.ts Slack Socket Mode
whatsapp.ts Meta Cloud API webhook
signal.ts signal-cli REST/WS (OpenClaw pattern)
matrix.ts Matrix sync loop
imessage.ts macOS AppleScript bridge
stubs.ts Teams/Feishu/Zalo stubs
index.ts Adapter factory
providers/
registry.ts Provider registry: built-ins + presets + custom
rlm/
repl.ts Sandboxed REPL (node:vm): P variable, sub_rlm, sub_rlm_all, Final
prompt.ts RLM system prompt + code extraction + metadata
loop.ts RLM loop (Algorithm 1) with recursion depth cap
srlm.ts Self-reflective program search (2603.15653)
chained.ts Fresh-context roots + blackboard handoff (2608.05124)
sandbox.ts Permission-model sandbox re-exec
update.ts Auto-update check (update-notifier) + `athena update`
index.ts Entry point (mode dispatch)Development
npm run typecheck # tsc --noEmit
npm test # vitest (parser, registry, loop)
npm run build # tscRoadmap
Recently shipped (now built): Docker sandbox for code_exec, web-search result caching, channel media/attachment support (Telegram), and typing indicators (Telegram/Discord).
Not yet built — flagged for future work:
- OS-level sandboxing (seatbelt, hardened Docker profiles).
- Media/attachments for more channels beyond Telegram (Discord, Slack, WhatsApp).
- Live verification of channels needs real credentials (tokens/numbers) — adapters are unit-tested against mocks; gateway verified with fake adapters.
- Live verification against real OpenAI/Anthropic endpoints (needs API keys) — wire protocol verified via mock servers in
test/providers.test.ts.
