Features
- 🤖 Responds to messages in Telegram chats with Elon Musk’s personality
- 🌤️ Can check weather conditions using the Composio Weather API
- ⏰ Provides current time information
- 🔄 Maintains context and can engage in multi-turn conversations
Framework Components Used
This example demonstrates several key features of the Galadriel framework:TelegramClient: Handles Telegram message input/outputToolCallingAgent: Base agent class for handling tool-based interactionsLiteLLMModel: Integration with language models via LiteLLM- Custom tools:
- Composio Weather API (converted using
convert_action) - Time tool
- Composio Weather API (converted using
Prerequisites
Before you begin, make sure you have the following:- Python 3.10 or higher
- A Telegram account
- An OpenAI API key
- A Composio API key (optional, for weather information)
Step 1: Setting Up Your Environment
-
Create a new directory for your project:
-
Create a virtual environment:
-
Install the Galadriel framework:
Step 2: Creating a Telegram Bot
- Follow the instructions in this Telegram Bot Tutorial to create a new bot and obtain a token.
Step 3: Setting Up Environment Variables
-
Create a
.envfile in your project directory with the following variables:Replace the placeholder values with your actual API keys and bot token.
Step 4: Implementing the Telegram Agent
-
Create a file named
agent.pyand add the following code: -
Create a file named
character_agent.pyand add the following code: -
Create a file named
tools.pyand add the following code: -
Create a file named
agent.jsonand add the following code:
Step 5: Running the Agent
-
Run the
agent.pyfile: - Start a conversation with your bot on Telegram!
Code Explanation
Dependencies
LiteLLMModel: Used for accessing and managing the OpenAI GPT-4o model.TelegramClient: Handles communication with the Telegram bot, sending and receiving messages.ToolCallingAgent: The agent implementation that processes user messages and generates responses.convert_action: Converts Composio actions into Galadriel tools.
Bot Logic
- The
CharacterAgentclass extends theToolCallingAgentto simulate Elon Musk’s persona. - The
TELEGRAM_SYSTEM_PROMPTtemplate defines the system prompt for the bot, incorporating information from theagent.jsonfile. - The
executemethod handles incoming messages, formats the prompt, and generates a response using the OpenAI GPT-4o model. - The
ComposioandTimetool and used to enhance agent capabilities.
API
- LiteLLMModel: The language model used for generating responses.
- TelegramClient: Connects to the Telegram bot API.
Customization
Modifying the Agent’s Persona
- Edit the
agent.jsonfile to change the agent’s name, system prompt, bio, lore, topics, and style. - Update the
TELEGRAM_SYSTEM_PROMPTincharacter_agent.pyto reference the new attributes inagent.json. - Modify the
character_json_pathvariable in theCharacterAgentclass to point to the newagent.jsonfile.
Adding New Tools
- Create a new Python file for your tool or use one of the available built-in tools from Galadriel or Composio
-
Import the new tool in
agent.py. -
Add the new tool to the
toolslist in theCharacterAgentclass.
Running the Agent with Different Clients
-
Modify the
inputsandoutputslists in theAgentRuntimeclass to use a different client. - Update the client-specific configurations, such as API keys and tokens.

