agent

AI Agent Runtime on the BEAM
Multi-gateway, SQLite-backed, tool-augmented chat — built in Gleam on Erlang/OTP.

CI Docs Documentation License

Documentation · Getting Started · Architecture · API Reference


Quick start

# Set your API key
echo 'DEEPSEEK_API_KEY=sk-...' > .env

# Run the CLI REPL
gleam run

# Run the daemon (Telegram bot + admin TCP listener)
gleam run -m agent_app

# Admin CLI (connect to running daemon)
gleam run -m agent_admin sessions list
gleam run -m agent_admin db stats

# Run tests
gleam test

Features

Chat & Gateways

Tool System

Persistence

Safety & Autonomy

Extensions & Config

Architecture

The project follows a three-category architecture. Full details in the Architecture Guide.

CategoryRoleExtensible?
CoreWireframe — behaviours (DI contracts), loop (orchestrator, runner, context, compression, error, guardrails), registry (dispatch, builder), session (state, handler), tool (types, executor), config (loader, helpers), types (8 modules)No
ServicesFixed branches the core depends on (Service shape: name, supervised, start, stop, health)No (built-in)
PluginsSwappable, shape-conforming components (Plugin shape + sub-type: Tool, Gateway, Hook, MemoryProvider)Yes (built-in + ~/.agent/)
src/
├── core/
│   ├── behaviours/        # 13 DI behaviour records (LLMClient, SessionStore, Guardrail, Logger, ...)
│   ├── types/             # session, message, client, response, hooks, tool_def, logging, guardrails
│   ├── config/            # config.gleam (loader), helpers.gleam
│   ├── loop/              # orchestrator, runner, context, compression, error, guardrails
│   ├── registry/          # registry.gleam (dispatch), builder.gleam (wires tools)
│   ├── session/           # session.gleam (state), handler.gleam (composition)
│   ├── tool/              # tool.gleam (types), executor.gleam (validation + parallel exec)
│   ├── schedule.gleam     # Shared cron parser
│   └── service.gleam      # Service shape definition
├── services/              # Fixed branches (api, storage, admin, tokens, guardrails, persona, context, titler, pulse, cron, harness, notifications, logger, supervisor)
│   ├── storage/           # db, db_behaviour, session_db, session_db_behaviour, memory_db, cron_db, schema, cfg
│   └── supervisor/        # Service lifecycle supervisor
├── plugins/               # Pluggable, shape-conforming — each module in its own folder
│   ├── types.gleam        # Plugin shape definition (Tool, Gateway, Hook, MemoryProvider)
│   ├── tools/             # bash/, browser/, code/, cron/, memory/, session_search/, web/, gateways/telegram/
│   ├── gateways/          # telegram/ (8 files), tui/README.md (planned), supervisor.gleam
│   ├── hooks/             # context_compressor/, reflection/, tool_guardrails/
│   └── memory/            # file_memory/
├── agent.gleam            # CLI REPL entry point
├── agent_app.gleam        # Daemon entry point (uses agent_supervisor)
├── agent_admin.gleam      # Admin CLI
└── agent_supervisor.gleam # Root supervisor (coordinates service + gateway supervisors)

Key patterns: behaviour-record DI, blessed violators, OTP supervision — see the Architecture Guide.

Admin Commands

Available in both CLI REPL (prefix with /) and via gleam run -m agent_admin:

Database:
  /db stats                 Show row counts and DB file size
  /db cost                  Show total cost across all sessions, per-model breakdown
  /db wipe memories         Delete all memory entries
  /db wipe sessions         Delete all sessions and messages
  /db prune sessions <days> Delete ended sessions older than N days

Sessions:
  /sessions list            List all sessions (key, source, model, tokens, cost)
  /sessions show <key>      Show session detail (persona, model, token breakdown)
  /sessions delete <key>    Delete a session and its messages
  /sessions search <query>  Full-text search across all message content
  /sessions rename <k> <t>  Rename a session
  /sessions export <key>    Export a session as JSON

REPL-only:
  /resume <id|title>        Switch to a previous session
  /continue                 Resume the most recent CLI session
  /clear                    End current session, start new one with parent linkage
  /title <text>             Set title for current session

Gateways:
  /gateways list            List configured gateways and their status
  /gateways status          Show detailed status for all active gateways

DND:
  /dnd status               Show active DND rules
  /dnd set <HH:MM> <HH:MM>  Add a scheduled quiet window (UTC)
  /dnd indefinite            Toggle indefinite DND on/off
  /dnd clear                 Remove all DND rules

Models:
  /models list              List all configured models
  /models primary           Show the primary model (name, base_url)

TCP protocol is line-delimited JSON: {"cmd":"sessions","action":"list"}{"ok":"..."}

Configuration

See the Configuration Reference for every option.

Dependencies

DependencyPurpose
gleam_stdlibStandard library
gleam_httpcHTTP client
gleam_jsonJSON codec
gleam_erlangErlang interop
envoyEnv var loading
sqlightSQLite
telegaTelegram Bot API
gleam_otpOTP integrations
tomTOML parsing
gleam_httpHTTP types
gleeunitTest framework (dev)

Documentation

Full documentation at agent-8x3.pages.dev:

Comparison with hermes-agent

Our agent is modeled after hermes-agent, a production Python AI agent.

Matched capabilities

AreaStatus
CLI REPL + daemon modeSame two-gateway architecture
SQLite session persistence (WAL, FTS5)Equivalent to hermes_state.py
Token/cost tracking per sessionSame per-message accumulator pattern
Session lifecycle (end, fork, prune, resume)Full lineage, crash recovery
Auto-titling via LLMSame fire-and-forget approach
Session search tool (Discovery/Scroll/Browse)Direct equivalent
Guardrails (hard blocks, approval patterns)46 tests, covers same patterns
SSRF protection (DNS-resolved, 2-tier, redirect re-validation)Exceeds hermes in redirect safety
Memory validation (injection/exfiltration/unicode scanning)Same scan patterns
Context file discovery (CLAUDE.md, AGENTS.md, etc.)Same walk-up algorithm
CJK-aware token estimationSame heuristic approach
API hardening (jittered retries, truncation continuation)Same retry policy
Config-driven (TOML + env vars)Same layered config model
Admin interface (TCP + slash commands)Own implementation, similar feature set
Parallel tool executionGleam/OTP process concurrency
Browser automation toolsPlaywright via agent-browser CLI (6 tools)

Deliberately deferred (design choices, not gaps)

Key gaps vs hermes-agent

Gaphermes approachPriority
Multi-platform gateway20+ chat platforms (Slack, Discord, Signal, etc.)Medium
Delegate/sub-agentdelegate_task tool spawns child agentLow
Provider fallback chainRotate credentials, chain through backup providersLow
Vision/image toolsImage analysis, generation, video generationLow
Skill systemSKILL.md knowledge packages with execution scriptsLow
LSP integrationLanguage Server Protocol clientLow
Voice/TTS/transcriptionTwo-way voice conversationLow

Test coverage

~630 tests. Guardrails (46), web/SSRF (42), admin (34), browser (14), and the full conversation loop (53 tests across unit, guardrails, compression, and integration suites) are well-covered. The only remaining untested areas are integration tests that require real API keys or external services.

Development

gleam run                     # Run the CLI REPL
gleam run -m agent_app        # Run the daemon (Telegram + admin)
gleam run -m agent_admin ...  # Connect to daemon's admin port
gleam test                    # Run all tests
gleam format                  # Format source files
Search Document