How ezzuldinst/askme-bot works
Purpose and Entry Points
AskMe is a Rust long-running bot for the Things social network. It detects @AskMe mentions, gathers thread/media context, asks Gemini for a response, and posts a threaded reply. The production entry point is src/main.rs; a developer dry-run path accepts --test-post <id> and can optionally publish with --post.
Runtime Orchestration
src/main.rs owns startup: loads environment credentials, initializes Things, Gemini, and optional Qdrant clients, then drives post handling. The bot requires Things and Gemini credentials; Qdrant initialization is non-fatal so processing continues without persistent memory. Domain structures passed across stages are defined in src/models.rs and src/entities.rs.
Things Network Boundary
src/things_client.rs encapsulates authentication to Things (email/password with OTP) and network operations needed to read posts, replies, and attached media, as well as publish the bot’s threaded response. This isolates the social-network API and its post/thread identifiers from orchestration and AI logic.
Context Construction and Conversation Semantics
The bot treats the mentioned post and its reply ancestry as conversational context. It limits included thread history through CONTEXT_DEPTH_LIMIT, enabling follow-up questions to retain prior discussion. src/entities.rs represents Things-side content/entities and supports output-oriented entity handling, while src/models.rs provides application-level message/request data structures.
Gemini Generation and Multimodal AI
src/gemini_client.rs is the boundary for Gemini chat and embedding APIs. It receives constructed conversation context plus available image/video material and returns the raw model response used for the Things reply. Gemini also supplies embeddings for semantic memory; its API key and model choices are configured by GEMINI_API_KEY, EMBEDDING_MODEL, and embedding dimension/batch settings.
Persistent Memory and Idempotency
src/qdrant_client.rs manages optional Qdrant-backed storage and retrieval. It supports semantic recall of prior thread content and persistent “already handled” state, preventing duplicate replies across restarts or network retries. src/qdrant_models.rs defines the Qdrant collection payload/vector representations. If Qdrant is unavailable, the bot degrades to stateless processing: no cross-restart deduplication and no recalled context.
Infrastructure and Operational Dependencies
The executable runs as a Cargo/Rust process (Cargo.toml) and calls external Things, Gemini, and Qdrant services. Qdrant is expected over local gRPC at port 6334 by default and can be started through scripts/start_qdrant.sh. Runtime secrets and endpoint/model tuning are supplied through environment variables, with example values in .env.example.
Main entry points: main.rs Startup & orchestration · gemini_client.rs Gemini client · things_client.rs Things client · qdrant_client.rs Qdrant client
Components 16
Bot Runtime
- Cargo process
Cargo.toml - Startup & orchestration · Initializes clients and drives normal or dry-run post handling.
src/main.rs - Application models
src/models.rs - Things client · Authenticates, reads threads/media, and publishes replies.
src/things_client.rs - Environment settings · Documents credentials, endpoint, and model tuning variables.
.env.example
Context & AI
- Things entities · Represents Things content and output-oriented entities.
src/entities.rs - Thread context · Builds bounded reply ancestry using CONTEXT_DEPTH_LIMIT.
- Media context · Collects available images and videos for generation.
- Gemini client · Generates replies and embeddings.
src/gemini_client.rs - Model response
Persistent Memory
- Qdrant client · Optional semantic recall and handled-state persistence.
src/qdrant_client.rs - Qdrant models
src/qdrant_models.rs
External Services
- Things
- Gemini
- Qdrant · Optional local gRPC service on port 6334 by default.
- Qdrant launcher
scripts/start_qdrant.sh
Connections 20
- Cargo process → Startup & orchestration: runs
- Environment settings → Startup & orchestration: documents env
- Startup & orchestration → Things client: initializes
- Startup & orchestration → Gemini client: initializes
- Startup & orchestration → Qdrant client: optionally initializes
- Startup & orchestration → Application models: uses
- Startup & orchestration → Things entities: uses
- Things client → Things: authenticates and calls
- Things client → Thread context: post and ancestry
- Things client → Media context: attached media
- Thread context → Gemini client: conversation context
- Media context → Gemini client: image/video context
- Qdrant client → Thread context: recalled context
- Gemini client → Gemini: chat and embeddings
- Gemini client → Model response: generates
- Model response → Things client: threaded reply
- Gemini client → Qdrant client: embeddings
- Qdrant client → Qdrant models: stores
- Qdrant client → Qdrant: recall and deduplicate
- Qdrant launcher → Qdrant: starts