MicroClaw is a Rust multi-platform chat bot with a channel-agnostic core and platform adapters. It currently supports Telegram, Discord, Slack, Feishu/Lark, and Web, and can be extended to more platforms. It provides agentic tool execution, web search, scheduled tasks, and persistent memory. Inspired by nanoclaw (TypeScript/WhatsApp), incorporating some of its design ideas.
Rust 2021, Tokio, teloxide 0.17, serenity 0.12, provider-agnostic LLM runtime (Anthropic + OpenAI-compatible), SQLite (rusqlite bundled), cron crate for scheduling.
src/-- Rust source for the bot binaryweb/-- Built-in Web UI (React + Vite). Compiled toweb/dist/and embedded into the Rust binary viainclude_dir!. This is the chat interface and settings panel served by microclaw itself at runtime.website/-- Separate git repository (landing page + documentation site). Not part of the microclaw binary. Contains the public-facing marketing site and docs. Changes here have no effect on the bot.
crates/microclaw-core/-- shared error/types/text modules (error,llm_types,text)crates/microclaw-storage/-- SQLite DB schema/query layer + memory/usage domain modulescrates/microclaw-tools/-- tool runtime primitives (trait/auth/risk/schema/path) + sandboxcrates/microclaw-channels/-- channel abstraction and delivery boundary modulescrates/microclaw-app/-- app-level support modules (logging, builtin skills, transcribe)src/main.rs-- entry point, CLIsrc/runtime.rs-- app wiring (AppState), provider/tool initialization, channel bootsrc/agent_engine.rs-- shared agent loop (process_with_agent)src/llm.rs-- provider implementations + format translationsrc/web.rs-- web API routes and streamingsrc/memory.rs-- file-memory manager (runtime/groups/.../AGENTS.md)src/scheduler.rs-- background scheduler + memory reflector loopssrc/channels/*.rs-- Telegram/Discord/Slack/Feishu adapterssrc/tools/*.rs-- concrete built-in tools; registry assembly insrc/tools/mod.rs
- Agentic loop in
agent_engine.rs:process_with_agent: call provider -> if tool_use -> execute -> loop (up tomax_tool_iterations) - Session resume: full
Vec<Message>(including tool_use/tool_result blocks) persisted insessionstable; on next invocation, loaded and appended with new user messages./resetclears session. - Context compaction: when session messages exceed
max_session_messages, older messages are summarized and replaced with a compact summary + recent messages kept verbatim - Sub-agent:
sub_agenttool spawns a fresh agentic loop with 9 restricted tools (no send_message, write_memory, schedule, or recursive sub_agent) - Tool trait:
name(),definition()(JSON Schema),execute(serde_json::Value) -> ToolResult - Shared state:
AppStateinArc, tools holdBot/Arc<Database>as needed - Group catch-up:
db.get_messages_since_last_bot_response()loads all messages since bot's last reply - Scheduler:
tokio::spawnloop, polls DB for due tasks, callsprocess_with_agentwithoverride_prompt - Typing: spawned task sends typing action every 4s, aborted when response is ready
- Path guard: sensitive paths (.ssh, .aws, .env, credentials, etc.) are blocked in file tools via
path_guardmodule - Platform-extensible core: Telegram/Discord/Slack/Feishu/Web adapters reuse
process_with_agent; new platforms integrate through the same core loop - SOUL.md: optional personality file injected into system prompt. Loaded from
soul_pathconfig,data_dir/SOUL.md, or./SOUL.md. Per-chat overrides viadata_dir/runtime/groups/{chat_id}/SOUL.md
cargo build
cargo run -- start # requires config.yaml with at least one enabled channel plus model credentials
cargo run -- setup # interactive setup wizard to create config.yaml
cargo run -- helpMicroClaw uses microclaw.config.yaml (or .yml) for configuration. Override the path with MICROCLAW_CONFIG env var. See microclaw.config.example.yaml for all available fields.
MicroClaw supports a SOUL.md file that defines the bot's personality, voice, values, and working style. The file content is injected into the system prompt, replacing the default "helpful AI assistant" identity.
Loading priority (first match wins):
soul_pathin config (explicit path)<data_dir>/SOUL.md./SOUL.md(project root, ships with the repo as the default soul)
Per-chat override: place a SOUL.md at <data_dir>/runtime/groups/<chat_id>/SOUL.md to give a specific chat a different personality.
Implementation: load_soul_content() and build_system_prompt() in src/agent_engine.rs. The soul content is wrapped in <soul> XML tags in the system prompt.
- Create
src/tools/my_tool.rsimplementing theTooltrait - Add
pub mod my_tool;tosrc/tools/mod.rs - Register in
ToolRegistry::new()withBox::new(my_tool::MyTool::new(...))
Core persistence is provided by microclaw-storage (Database wrapper over SQLite). Runtime state and observability tables are managed through versioned migrations.
- All timestamps are ISO 8601 / RFC 3339 strings
- Cron expressions use 6-field format (sec min hour dom month dow)
- Messages are stored for all chats regardless of whether bot responds
- In groups, bot only responds to @mentions
- Consecutive same-role messages are merged before sending to the configured LLM provider
- Responses > 4096 chars are split at newline boundaries (Telegram), > 2000 chars for Discord, > 4000 chars for Slack/Feishu