agent

A Gleam AI agent runtime on the BEAM/Erlang VM. Multi-gateway, SQLite-backed persistence, tool-augmented chat with any OpenAI-compatible API.

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

Architecture

The project follows a three-category architecture:

CategoryRoleExtensible?
CoreLightweight wireframe connecting components — event loop, registry, config, session typeNo
ServicesFixed branches the core depends on, each with a Service shape (name, supervised, start, stop, health).No (built-in)
PluginsSwappable, shape-conforming components. Each has a top-level Plugin shape plus a sub-type shape (Tool, Gateway, Hook, MemoryPlugin). Users can add their own in ~/.agent/.Yes
src/
├── core/                  # Wireframe (loop, registry, config, session, tool shape)
├── services/              # Fixed branches (api, storage, admin, tokens, guardrails, persona, context, titler, pulse, cron, harness, notifications)
│   ├── shapes.gleam       #   Service shape (name, supervised, start, stop, health)
│   └── supervisor.gleam   #   Service supervisor
├── plugins/               # Pluggable, shape-conforming — each module in its own folder
│   ├── shapes.gleam       #   Plugin shape (name, description, plugin_type, supervised, start, stop, health)
│   ├── tools/             #   bash/, browser/, code/, cron/, memory/, session_search/, web/, gateways/telegram/
│   ├── gateways/          #   telegram/, tui/ + 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)

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
  /sessions export all      Export all sessions as JSONL (deferred)

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

Dependencies

Comparison with hermes-agent

Our agent is modeled after hermes-agent, a production Python AI agent. Below is a summary of where we match, where we diverge by design, and where gaps remain.

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)Actually 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
Fuzzy command suggestionsUnique to our agent
Parallel tool executionGleam/erlang/process concurrency (spawn_unlinked + Subject message passing)
Browser automation toolsPlaywright via agent-browser CLI (6 tools, URL safety reuses SSRF)

Deliberately deferred (not gaps — design choices)

Key gaps vs hermes-agent

Gaphermes approachPriority
Conversation loop tests18 tests covering pure functions, tool execution, and loop logic with mock chat functions✅ Done
Tool loop guardrailsCircuit breaker: detect stuck tool loops, warn → block → halt. 16 unit + 6 integration tests.✅ Done
Context compressionSummarize middle messages, protect head/tail; triggered at token threshold. 12 unit + 5 integration tests.✅ Done
Guardrails + compression integrationBoth modules wired into loop.gleam. 23 integration tests verify correctness end-to-end.✅ Done
Multi-platform gateway20+ chat platforms (Slack, Discord, Signal, WhatsApp, etc.)Medium
Delegate/sub-agentdelegate_task tool spawns child agent for multi-step subtasksLow
Provider fallback chainRotate credentials, chain through backup providers on failureLow
Vision/image toolsImage analysis, generation, video generationLow
Skill systemSKILL.md knowledge packages with execution scriptsLow
Background memory reviewPost-turn daemon thread auto-saves to memory/skillsDone (Reflection hook)
ACP (Agent Communication Protocol)IDE integration protocolLow
LSP integrationLanguage Server Protocol clientLow
Voice/TTS/transcriptionTwo-way voice conversationLow
Cron job managementScheduled task tool + runtime CRUDDone (Cron service + cron_create/list/update/delete tools)
Notifications + DNDGateway-specific notify + quiet hoursDone (telegram/send_message tool + DND service with /dnd admin commands)

Test coverage highlights

Our agent has ~590 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