5.4 KiB
Telegram Inference Bot with Daemon and Apprentice System
This project implements a Telegram bot system with two instances: a daemon bot and an apprentice bot. The daemon bot handles the main workload, while the apprentice bot can be updated and take over when needed. The system supports both OpenAI (ChatGPT) and Anthropic (Claude) AI models.
Features
- Daemon bot for handling main workload
- Apprentice bot for updates and handovers
- Support for both OpenAI (ChatGPT) and Anthropic (Claude) AI models
- Dynamic tool integration for extended functionality
- Conversation history management
- Model switching capability (for ChatGPT implementation)
- Error handling and logging
Bot Implementations
ChatGPT Bot (OpenAI)
- Uses OpenAI's GPT models (gpt-4o-mini and gpt-4o)
- Supports model switching between gpt-4o-mini (16,384 tokens) and gpt-4o (4,096 tokens)
- Implements tool calls using OpenAI's function calling feature
Claude Bot (Anthropic)
- Uses Anthropic's Claude model (claude-3-5-sonnet-20240620)
- Implements tool calls using Anthropic's tool use feature
- Uses a maximum of 8,192 tokens per response
Setup
-
Clone the repository:
git clone https://github.com/your_username/your_repo_name.git cd your_repo_name -
Install the required dependencies:
pip install -r requirements.txt -
Copy the
.env.examplefile to.envand fill in your actual values:cp .env.example .env -
Edit the
.envfile with your specific tokens and settings. -
Run the bot:
python telegram_inference_bot.py
Environment Variables
Make sure to set the following environment variables in your .env file:
TELEGRAM_BOT_TOKEN: Token for the daemon botTELEGRAM_APPRENTICE_BOT_TOKEN: Token for the apprentice botOPENAI_API_KEY: Your OpenAI API keyANTHROPIC_API_KEY: Your Anthropic API keyGITHUB_REPO_OWNER: Your GitHub username or organizationGITHUB_REPO_NAME: Your repository nameGITHUB_ACCESS_TOKEN: Your GitHub personal access tokenDAEMON_CHAT_ID: Chat ID for the daemon botAPPRENTICE_CHAT_ID: Chat ID for the apprentice botSYSTEM_PROMPT_PATH: Path to the system prompt file
Usage
- Start the bot by running
python telegram_inference_bot.py - Use
/startto begin interacting with either bot - Use
/handoverin the daemon bot to initiate a handover to the apprentice bot - The apprentice bot will automatically check for updates every 15 minutes (feature to be implemented)
Commands
/start: Start interacting with the bot/clear: Clear conversation history/switch: (ChatGPT bot only) Switch between GPT models (gpt-4o-mini and gpt-4o)/status: Check the current model and provider/handover: (Daemon bot only) Initiate handover to apprentice bot (to be implemented)/update: (Apprentice bot only) Manually trigger an update (to be implemented)/abort: Abort current processing (to be implemented)
Contributing
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Future Improvements
- Implement handover functionality between daemon and apprentice bots
- Add automatic update checking for the apprentice bot
- Unify features across both bot implementations
- Enhance error handling and logging
- Move hardcoded values to configuration files
- Implement comprehensive unit testing
Roadmap
Here are some of the upcoming features and improvements planned for the bot:
- Refactor messaging service integration: Abstract the messaging service (currently Telegram) to allow for easier integration of other services like Slack or email. Dummy classes for new services will be created as a first step. (Issue #194)
- Dynamic inference service switching: Enable switching between different inference services (e.g., Gemini, OpenAI) during runtime without restarting the bot. Message history will be preserved across service switches. (Issue #195)
- Scheduled agent tasks: Allow agents to run on a timer to perform specific tasks autonomously, such as:
- Checking for newly created issues.
- Reviewing Pull Requests.
- Analyzing metrics. (Issue #196)
- Enhanced onboarding and GitHub configuration:
- On
/start, prompt the user for a GitHub API key and provide a pre-configured link to generate a new key with the required permissions. - Validate the API key and then ask for the target repository.
- Store the GitHub API key and current repository in
context.user_data["github_api_key"]andcontext.user_data["current_repository"]respectively on the Telegram side. (Issue #197)
- On
- Repository switching command: Implement a command to allow users to switch between different GitHub repositories seamlessly. (Issue #198)
- User-provided inference service API keys: Allow users to input their own API keys for inference services (e.g., OpenAI, Gemini, Anthropic, other OpenAI-compatible services). These keys will be stored in
context.user_data. A wizard may be implemented to guide users through obtaining API keys if needed. (Issue #199) - Server-side storage for timed agents: For agents running on a timer, API keys and other sensitive information will be stored server-side. This will eventually be a paid service. (Issue #200)