$ show AstrBotDevs/AstrBot
AstrBot is a production-grade, multi-platform LLM chatbot framework and development platform. It connects to 10+ instant messaging platforms (QQ, Telegram, Discord, Slack, WeChat, Lark, etc.) via adapter pattern, integrates with 20+ LLM providers (OpenAI, Anthropic, Gemini, DashScope, etc.), and provides a plugin system (Stars) with command/regex/filter decorators. The architecture is a modular monolith: a FastAPI backend serves a Vue 3 dashboard for management, while a pipeline of stages processes incoming messages through waking checks, rate limiting, content safety, LLM interaction, and response delivery. It includes a knowledge base with RAG (FAISS vector store, chunking, hybrid retrieval), agent runners (Dify, Coze, DeerFlow), sandboxed code execution (computer use), TTS/STT, cron jobs, and a CLI. The codebase is well-structured with extensive test coverage, but its broad scope introduces some duplication and deprecated modules.
The LLM identified 9 files worth highlighting for reuse:
Defines the abstract Stage base class with async initialize/process methods and a decorator-based registration system. Stages are ordered via STAGES_ORDER and composed into a pipeline. This pattern is cleanly isolated and could be extracted for any event-processing system.
Implements a decorator-based registry for LLM, embedding, TTS, STT, and rerank providers. Each adapter class is decorated with @register_provider_adapter and lazy-loaded. The registry pattern is self-contained and reusable for any plugin-style architecture.
A Markdown-aware text chunker that splits documents by heading hierarchy while respecting code fences and merging short chunks. It falls back to a recursive character splitter. This is a standalone, well-tested component suitable for any RAG pipeline.
Abstract base class for process sandboxing with resource limits, workspace isolation, and timeout enforcement. Concrete implementations (Unix, Seatbelt, Bubblewrap) extend it. The pattern is cleanly separated and could be reused for any code execution sandbox.
Provides TOTP generation, verification, recovery code management, and trusted device tokens. Uses standard HOTP/TOTP algorithms with configurable period and digits. Self-contained and could be extracted for any authentication system.
Implements a context compressor protocol with two strategies: turn-based truncation and LLM-based summarization. The protocol is defined via should_compress and __call__ methods, making it easy to swap or extend. Reusable for any LLM context management.
Combines dense and sparse retrieval results using weighted fusion with RRF tie-breaking. Configurable weights and normalization. A standalone utility for any multi-stage retrieval system.
Manages chunked file uploads with session lifecycle, atomic chunk writes, expiry cleanup, and progress tracking. The pattern (init/chunk/complete/abort/status) is generic and could be reused for any large file upload service.
Monitors asyncio event loop lag with a watchdog thread that dumps thread stacks on timeout. Provides lag statistics and automatic recovery hints. A self-contained utility for debugging event loop stalls in any async application.