Skip to main content

LLM-powered multi-platform bot framework (Telegram + Discord; OpenAI + Anthropic)

Project description

ForgeLLM

ForgeLLM bridges a chat platform and a Large Language Model (OpenAI GPT or Anthropic Claude). One bot identity can run multiple platform adapters at once, sharing the same persona and memory - see Supported Platforms.

Supported Platforms

Platform Requirements Bot creation
Telegram A Telegram account with a username (not just a phone number) - create one. In groups, the bot must be administrator to respond to its name/nickname/initials. BotFather
Discord Invite the bot with the bot and applications.commands scopes. Guild channels are opt-in - run /enable in each channel you want it active in (see Commands and Interactions). Discord Developer Portal

Every feature below - conversation memory, tools, image generation, search, account linking - is implemented once in the shared response engine (core/base_adapter.py) and works identically on every platform. Adding a future platform means adding a row here and a new adapter under forgellm/<platform>/, not touching the feature logic itself.

Core Features

  • Each platform's interface handles special commands and basic "chatty" responses that don't require an LLM, like "Hello". Dynamic conversations are handed off to the LLM while the platform acts as the interaction broker.
  • Pass URLs in [square brackets] and mention how the bot should interpret them.
    • Example: "What do you think of this article? [https://some_site/article]"
    • Uses a separate model (configurable via url_model) to handle larger URL content.
  • Share documents and text files for analysis and summarisation.
    • Supported formats: PDF (via pypdf), Microsoft Office documents (.docx via python-docx, .xlsx via openpyxl), plain-text files (.txt, .md, .rst, .csv, .json, etc.), HTML, and XML (via defusedxml).
    • The bot extracts and summarises content, with automatic encoding detection for non-UTF-8 files. Files over 20 MB are rejected.
    • Can be disabled via document_processing: false in config.
  • Share images for visual analysis.
    • The bot analyzes photos using your configured LLM's vision capabilities. Optional captions are preserved; EXIF metadata is stripped before sending to any provider.
    • Can be disabled via image_analysis: false in config. Requires the chat_model to support vision (controlled per-model in models.yaml, default true).
  • Generate images from text descriptions.
    • Request images using natural language. The bot creates them via gpt-image-1 and sends them to your chat with a brief description as the caption.
    • Requires an OpenAI API key. Supports three sizes: 1024x1024 (default), 1536x1024, and 1024x1536.
    • Configurable cooldown between requests via image_gen_cooldown_s (default 30 seconds per user).
    • The bot stores generation prompts in conversation history (the full prompt, not the caption), enabling it to recall past images and refine them across sessions. Ask for variations (e.g., "make it darker", "different composition") without repeating the full original prompt.
  • Ask questions about message history across all your chats using natural language; the bot will search, attribute messages to speakers, and include messages from other bots.
    • Example: "Who said thanks for the breakdown?" or "What did George say about the project?" or "Show me the last few messages."
    • All search filters (speaker, chat, date) are optional. Results are ordered most-recent-first. Configure search_limit to control how many results to return (default: 30).
    • Search automatically finds users and chats by their current or past names, so you can reference them however you remember them.
  • Token limits measure conversation length and determine when to prune oldest messages to stay within model limits.
    • The bot loads the user's full history across all chats up to 50% of the token budget. In private chats, shared group context fills the remaining budget, enabling the bot to reference group conversations from a private context.
    • This eliminates amnesia when switching between private and group chats.
  • Conversation archive preserves long-term context without consuming token budget.
    • Older messages are automatically distilled into concise daily summaries (Tier 1), then progressively compressed into monthly digests (Tier 2). Raw messages are never deleted; archive rows surface seamlessly in search results and context loading.
    • Configurable via archive_days (default 60 days before Tier 1 triggers; Tier 2 triggers at 2x this value).
  • Persistent tone preference, carried across every chat and linked platform.
    • Just ask, in natural conversation - e.g. "talk to me in a cute voice from now on" or "be more formal with me." The bot recognizes the request and remembers it for you specifically, without affecting how it talks to anyone else in a shared chat.
    • Clear it the same way (e.g. "go back to normal"). Not a slash command - the LLM detects and applies the request automatically.
  • Users can manage privacy via two commands:
    • /forget - In private chats, clears your full conversation and resets all active sessions. In group/guild chats, removes only your messages and cleans up paired bot replies.
    • /private - Show status, or use /private on//private off to change it (private chats only). When ON, your messages in private chats are excluded from group conversation contexts, enabling selective privacy even in shared groups.
  • Link your accounts across platforms with /link//unlink, so the bot shares one unified memory for you regardless of which platform you're talking on - facts, search results, and tone preference all carry over.

Why a Chat Platform?

Using a chat platform as the interface not only solves "exposing" the interface, but gives you boatloads of interactivity over a standard Command Line interface, or trying to create a website with input boxes and submit buttons to try to handle everything:

  1. Chat platforms already let you paste in verbose, multiline messages.
  2. Chat platforms already let you paste in pictures, videos, links, etc.
  3. Chat platforms already let you react with emojis, stickers, etc.
  4. Message reactions (👀) provide a lightweight read receipt without breaking conversation flow.

Supported LLM Providers

ForgeLLM selects the LLM provider automatically based on the model name:

Model prefix Provider Example models
gpt- OpenAI gpt-4o, gpt-4o-mini, gpt-5-mini
claude- Anthropic claude-sonnet-4-6, claude-haiku-4-5

Simply set chat_model (and optionally url_model) in your config.yaml to any supported model and supply the corresponding API key - no other changes needed. A future provider only needs a new prefix mapping in core/providers/factory.py.

Directories

ForgeLLM creates the following directories:

  • configs - Bot configuration and model parameters (path configurable via FORGELLM_CONFIGS_PATH)
    • config.yaml - Default bot configuration file (filename used throughout this README); can be changed by passing config_file to any adapter's .set()
    • models.yaml - Token limits for each LLM model. Sensible defaults are built into the code, so the bot runs without this file. To override or add models, copy configs/models.yaml.example to models.yaml in this directory and edit it (an instance models.yaml replaces the built-in defaults entirely - list every model you use, not just the ones you change)
  • prompts - Bot personas (path configurable via FORGELLM_PROMPTS_PATH)
    • test_personality.prmpt - Default bot persona file (filename used throughout this README); can be changed by passing prompt_file to any adapter's .set()
    • A system appendix is automatically appended to every persona at runtime, teaching the LLM about cross-chat memory, search behavior, self-addressing, and confidentiality guidelines. User messages include speaker annotations with chat context and timestamps so the LLM always knows who is speaking, in which chat, and when.
  • logs - Bot instance logs (one per startup, named after the bot's platform username or instance_name config, e.g. my_bot_2026-03-29_10-30-45.log)
    • Logs include anonymized platform IDs (user/chat/channel numeric identifiers) for privacy. Console shows INFO-level ForgeLLM messages only, prefixed with an [identity label] (the bot's platform username by default, or instance_name when configured).
    • Log file timestamps are UTC in [YYYY-MM-DD HH:MM:SS.mmm] format.
    • Bot keeps the 10 most recent logs per bot instance, automatically pruning older ones.
    • Pass -v or --verbose on startup for DEBUG-level logging.
  • data - SQLite database (default conversations.db, customizable via instance_name config) storing all messages, users, and chats
    • Users manage their data via /forget and /private commands.

Environment Variables for Paths

Override default directory locations by setting these environment variables (useful for containerized deployments):

Variable Purpose Default
FORGELLM_CONFIGS_PATH Directory containing config.yaml and models.yaml {exec_dir}/configs
FORGELLM_PROMPTS_PATH Directory containing prompt files {exec_dir}/prompts
FORGELLM_LOGS_PATH Directory for log files {exec_dir}/logs
FORGELLM_DATA_PATH Directory containing conversations.db {exec_dir}/data

If unset, all paths default to subdirectories of the execution directory (the directory containing your entry-point script).

API Keys

ForgeLLM supports five API keys. OpenAI, Anthropic, and VirusTotal keys load from environment variables or .key files. Platform keys load from their own platforms.<name>.api_key config field or env var (no .key file); config wins when explicitly set:

Key Env Var File/Config When required
OpenAI FORGELLM_OPENAI_API_KEY openai.key For gpt-* models, or for image generation in any deployment
Anthropic FORGELLM_ANTHROPIC_API_KEY anthropic.key For claude-* models
Telegram FORGELLM_TELEGRAM_API_KEY platforms.telegram.api_key in config.yaml Required to run the Telegram adapter
Discord FORGELLM_DISCORD_API_KEY platforms.discord.api_key in config.yaml Required to run the Discord adapter
VirusTotal FORGELLM_VIRUSTOTAL_API_KEY virustotal.key For URL analysis

Missing provider keys (OpenAI or Anthropic) disable chat and URL analysis but allow the bot to start. Missing OpenAI key disables image generation. Missing VirusTotal disables URL analysis. At least one platform key is required - whichever adapter(s) you .set() will not start without its own key.

Key files are created in the execution directory (or FORGELLM_KEYS_PATH for legacy deployments). Alternatively, set environment variables before launching, e.g.:

os.environ['FORGELLM_OPENAI_API_KEY'] = my_vault.get('openai_key')
os.environ['FORGELLM_ANTHROPIC_API_KEY'] = my_vault.get('anthropic_key')
os.environ['FORGELLM_TELEGRAM_API_KEY'] = my_vault.get('telegram_key')
os.environ['FORGELLM_DISCORD_API_KEY'] = my_vault.get('discord_key')
os.environ['FORGELLM_VIRUSTOTAL_API_KEY'] = my_vault.get('virustotal_key')

Commands and Interactions

User Commands

  • /nick <name> - Set your nickname (for bot use in group/guild chats).
  • /forget - Clear your conversation history. Shows a confirmation prompt before deletion. In private chats, clears everything and resets all active sessions. In group/guild chats, removes only your messages.
  • /private - Show your current private mode status (private/DM chats only). Use /private on or /private off to change it. When ON, your messages are excluded from group context loading; turning OFF permanently deletes your private-flagged messages.
  • /link [code] - Without a code, issues a 15-minute single-use linking code. Redeem it from another platform with /link <code> to merge your accounts into one shared memory. Private/DM chats only.
  • /unlink - Remove your account from its linked group. Private/DM chats only.

Admin Commands

  • /tools - List tools available to this bot instance (admin-only; private, group/guild, and supergroup chats - channels always denied). Shows the built-in search_messages and generate_image tools plus any webhook or MCP tools defined in config.yaml; in group/guild chats only tools with allow_groups: true are listed.
  • /start / /stop - Bring the bot online or offline (admin-only).
  • /wipe - Permanently delete all bot data (admin-only; confirmation prompt before deletion).
  • /help - Display available commands and usage information. In private/DM chats, if you are a bot owner, also shows administrator-only commands.
  • /enable / /disable (Discord only) - Opt the current guild channel into or out of bot activity (admin-only). Discord channels are opt-in by default; there's no Telegram equivalent since a Telegram group is always implicitly active.

Group/Guild Chat Triggers

The bot responds in a group (Telegram) or guild channel (Discord) when you mention the bot, mention it by nickname/initials (configured via config.yaml), or reply directly to one of its messages.

When multiple bots are @mentioned in the same message, the bot coexists: if you mention its nickname/initials or reply to its message, it always engages (you may be intentionally addressing both bots). If the only trigger is a reply to the bot's message AND the message exclusively addresses a different bot via @mention or plain-text name-address (e.g., "Cesura, response?" or "thoughts, Cesura?"), the bot yields silently - this supports threaded context without redundant responses. Plain-text addresses must match a known bot in the chat (its current username, or its current or past display name) to trigger a yield.

Admin slash commands (/help, /nick, /forget, /private, /tools, /start, /stop, /wipe) work identically everywhere in private/DM chats. In groups/guilds, addressing differs per platform - see the mechanics table below.

Private Chat Behavior

In a private/DM chat, the bot responds to all your messages. If you reply to an earlier message not already in the bot's context window, that message is automatically surfaced as inline context so the bot understands the full conversation thread.

Read Receipt

As soon as the bot is triggered and about to respond (not deferring to another bot), it sends a 👀 emoji reaction on your message and shows a typing indicator while composing the reply - both arrive before the full LLM response, so you get quick feedback that the bot received your message.

Platform Mechanics

Everything above is shared, platform-neutral behavior. Only the underlying wire protocol differs:

Telegram Discord
Mentioning the bot @botname native @ mention
Slash commands in groups need addressing? Yes - use /help@botname, or reply to the bot's message, so co-present bots don't all answer a bare command No - Discord routes slash commands natively to whichever bot registered them
Read-receipt fallback Falls back to a "Got it!" text reply on older clients without reaction support N/A (reactions always supported)

Bot Setup

  1. Ensure API keys are set up (see API Keys) and create your bot on each platform you plan to run (see Supported Platforms).

  2. Install ForgeLLM: pip install digitalheresy-forgellm (the importable package is forgellm regardless of the install name, e.g. from forgellm.telegram.adapter import TelegramAdapter).

  3. Configure config.yaml (created on first run). Top-level keys apply regardless of platform; each platform gets its own platforms.<name> section:

    • platforms.<name>.bot_owner: username(s) with admin access (required, no @). Accepts a single string or a YAML list - matched by username string on every platform (no numeric IDs anywhere).
    • platforms.<name>.api_key: that platform's bot API key (required to run that adapter). Lookup order: (1) this config field, (2) the platform's env var from the API Keys table. Config wins when explicitly set. Exits on placeholder, missing, or malformed key.
    • chat_model / url_model: LLM models for conversation and URL analysis (e.g. gpt-4o-mini, claude-sonnet-4-6).
    • bot_nickname / bot_initials: Names the bot responds to in groups/guilds.
    • instance_name: Optional label for console prefix, log filename, and database name (e.g. MyBot produces [MyBot] INFO: ... on console, MyBot_{timestamp}.log logs, and MyBot.db database); omit to use the bot's platform username for logging and conversations.db for database. Use distinct names when running multiple bot instances in the same directory.
    • token_limit / search_limit: Max tokens (default: model's maximum) / max search results (default: 30).
    • archive_days: Days before messages are eligible for archival (optional; default 60, minimum 1). See Core Features.
    • document_processing / image_analysis: Optional bools (default: true) to disable document summarisation / image analysis. image_analysis requires the chat_model to support vision (default true per-model in models.yaml).
    • image_gen_cooldown_s: Optional int (default 30, minimum 0). Seconds a user must wait between image generation requests.
    • allow_local_webhooks: Set to true to permit webhook/MCP URLs targeting loopback or link-local addresses (optional; default false). Useful when tools like Home Assistant run on the same host.
    • max_conversations: Optional max chats kept in memory at once (default: 500, minimum 1). Least-recently-used chats beyond this cap are evicted and reload from the database on their next message.
    • idle_minutes: Optional minutes a chat can sit untouched before being evicted from memory (default: 60, minimum 0). Set to 0 to disable idle-based eviction. Evicted chats reload from the database on their next message.
    • tools: Optional list of webhook and MCP tool definitions (admin-only, private chat only). See docs/tools.md for schema and examples.

    Example config.yaml:

    instance_name: MyBot
    bot_nickname: Panzer
    bot_initials: PZ
    chat_model: gpt-4o
    url_model: gpt-4o
    
    platforms:
      telegram:
        api_key: abc123...
        bot_owner: [MyUsername]
    

    Swap telegram: for discord: (with a Discord username in bot_owner) to run Discord instead - everything else is identical. Include both sections to run both (see Running Multiple Platforms Together).

  4. One-time platform setup:

    Platform One-time setup
    Telegram Disable group privacy mode in BotFather: /setprivacy -> select your bot -> Disable. Otherwise the bot won't receive group messages that don't mention it, so it can't index other bots or load cross-chat context.
    Discord Run /enable in each guild channel you want the bot active in - channels are opt-in by default.
  5. Run the bot:

    from forgellm.telegram.adapter import TelegramAdapter
    telegram_bot = TelegramAdapter.set()
    telegram_bot.run()
    

    Swap in forgellm.discord.adapter.DiscordAdapter to run Discord instead - same .set()/.run() shape. run() is synchronous and blocks until the bot is stopped.

  6. Type /help to see all available commands.

Running Multiple Platforms Together

Construct every adapter you want, then run them concurrently via start_async() instead of run() (they share one event loop) so they share one bot identity, persona, and memory - the bot's own accounts on each platform are automatically linked to each other on startup, the same way /link connects two user accounts:

import asyncio
from forgellm.telegram.adapter import TelegramAdapter
from forgellm.discord.adapter import DiscordAdapter

async def main():
    telegram_bot = TelegramAdapter.set()
    discord_bot = DiscordAdapter.set()
    await asyncio.gather(telegram_bot.start_async(), discord_bot.start_async())

asyncio.run(main())

The bundled run_bots.py wires this up for you, including the bot's own cross-platform auto-link.

Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

digitalheresy_forgellm-1.0.4.tar.gz (264.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

digitalheresy_forgellm-1.0.4-py3-none-any.whl (272.5 kB view details)

Uploaded Python 3

File details

Details for the file digitalheresy_forgellm-1.0.4.tar.gz.

File metadata

  • Download URL: digitalheresy_forgellm-1.0.4.tar.gz
  • Upload date:
  • Size: 264.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for digitalheresy_forgellm-1.0.4.tar.gz
Algorithm Hash digest
SHA256 83ebc5557dcc94edbba36baa13ba5e4ba359752642d144c12e88162b0f0bdd6d
MD5 cafbaedd0f13b39dbf9ee5d6f838a37e
BLAKE2b-256 8b03410eb08441515ef3a2f9c7b3f28a80a7340803959192c967c440ceeabc93

See more details on using hashes here.

Provenance

The following attestation bundles were made for digitalheresy_forgellm-1.0.4.tar.gz:

Publisher: python-publish.yml on Digital-Heresy/ForgeLLM

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file digitalheresy_forgellm-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for digitalheresy_forgellm-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9c7dc5709ec4d8515fab95a76c94637a100340a5b116fa5c4ef822979fbce5e9
MD5 15ea0317f6814038be96216ee3e1f686
BLAKE2b-256 af6adb538dad2f938451fccca1857a812155f5d4d7a183c799ebecaedf9b6bd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for digitalheresy_forgellm-1.0.4-py3-none-any.whl:

Publisher: python-publish.yml on Digital-Heresy/ForgeLLM

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page