Dignity is an innovative Discord chatbot that brings cutting-edge AI memory and reasoning capabilities directly to your server, powered by the AgentForge framework. Designed to create lucid and deeply conversational character bots, Dignity leverages advanced techniques to generate responses that are not just intelligent, but also emotionally resonant and contextually aware.
Dignity stands out with its unique blend of academic research and practical application:
- π§ Advanced Memory System (Active RAG): Implements Active Retrieval Augmented Generation for highly relevant context retrieval.
- π€ Sophisticated Reasoning: Utilizes Reflextion, multi-prompt Chain-of-Thought, and Theory of Mind capabilities for deeper understanding and generation.
- β€οΈ Emotionally Enhanced Conversations: Generates responses enhanced by emotional stimuli and emotional feedback for more relatable interactions.
- π Flexible Model Support: Seamlessly switch between OpenAI, Claude 3, Gemini, and locally hosted models (including Llama instruct fine-tunings) thanks to AgentForge. You can even assign specific prompts to specific models!
- π¬ Discord-Native Experience:
- Full support for Direct Messages (DMs).
- Interactive Slash Commands.
- Utilizes Discord threads for internal chain-of-thought visibility.
- π Enhanced Memory Management:
- Journal/Diary: Automated episodic memory generation every
Xmessages. - NEW: Personalized User Notepad: Dedicated, persistent memory space for each user.
- NEW: Reranking Search Results: Reduces token costs and improves relevance of memory recall.
- Journal/Diary: Automated episodic memory generation every
- π₯ Multi-User & Multi-Channel Interaction: Designed for dynamic use across different users and channels.
Follow these steps to get your Dignity chatbot up and running on your Discord server.
- Python 3.9+
- A Discord account and server where you can add bots.
- An API key for your chosen LLM (e.g., Anthropic Claude 3, OpenAI, or a configured local LLM).
Clone the repository and install the required dependencies:
git clone https://github.com/YOUR_USERNAME/Dignity.git # Replace with your repo URL
cd Dignity
pip install agentforgeSet the following environment variables in your operating system. AgentForge will load these directly from your system environment.
Required Variables:
ANTHROPIC_API_KEY- Your Anthropic API keyDISCORD_TOKEN- Your Discord bot token
Alternative LLM Providers:
OPENAI_API_KEY- If using OpenAI instead of AnthropicGOOGLE_API_KEY- If using Gemini. (The flash API is free, by the way)- For local models, configure AgentForge according to its documentation
Setting Environment Variables:
Linux/macOS:
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
export DISCORD_TOKEN="YOUR_DISCORD_BOT_TOKEN"
Windows (PowerShell):
$env:ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
$env:DISCORD_TOKEN="YOUR_DISCORD_BOT_TOKEN"
Windows (Command Prompt):
set ANTHROPIC_API_KEY=YOUR_ANTHROPIC_API_KEY
set DISCORD_TOKEN=YOUR_DISCORD_BOT_TOKEN
For persistent environment variables, add them to your system's environment configuration (e.g., .bashrc, .zshrc, or Windows Environment Variables settings).
How to get your tokens/IDs:
- DISCORD_TOKEN: Create a new application in the Discord Developer Portal, turn it into a bot, and copy its token. Remember to enable "Message Content Intent" in the Bot settings.
- ANTHROPIC_API_KEY / OPENAI_API_KEY: Obtain these from their respective developer dashboards.
For more information on tokens and environment variables, see AgentForge documemntation.
Once your environment variables are set, you can start the bot:
python main.pyThe bot will connect to Discord. You'll see it appear online in your server's member list within a few seconds.
Dignity is designed to be highly customizable:
- Persona Customization: The core personality of your bot is defined in the
.agentforge/personas/default.yamlfile. Modify this to shape your bot's character. - Agent Prompts: The bot uses a series of specialized agents for different cognitive tasks. Their prompts are located in the
.agentforge/agentsfolder (specifically underCustomAgents/Trinityin this project). You can tweak these to refine the bot's reasoning and response generation. This may be necessary for local LLMs, who often have difficulty following instructions. We recommend using models that support at least 64k contexts windows. We aim to keep token usage as low as possible with our RAG techniques, but every prompt will be different. - Slash Commands: Dignity supports Discord Slash Commands. Check
Modules/proccess_slash_command.pyfor examples on how to build your own commands. The test is a fun little jailbreak game. - Threads for Chain-of-Thought: When the bot is processing complex requests, it can open a thread to show its internal reasoning process, providing transparency into its "thoughts."
Dignity/
βββ CustomAgents/ # Contains the specialized AgentForge agents for Dignity's cognitive functions
β βββ Trinity/
β βββ ChatAgent.py
β βββ ChooseAgent.py
β βββ GenerateAgent.py
β βββ JournalAgent.py
β βββ JournalThoughtAgent.py
β βββ ReflectAgent.py
β βββ TheoryAgent.py
β βββ ThoughtAgent.py
βββ Modules/ # Handlers for different Discord interaction types (DMs, messages, slash commands)
β βββ challenges.py
β βββ proccess_slash_command.py
β βββ process_channel_message.py
β βββ process_direct_message.py
β βββ process_indirect_message.py
β βββ TrinityLoop.py # The core loop orchestrating the agent interactions
βββ Utilities/ # Helper utilities for memory, parsing, etc.
β βββ Journal.py # Manages episodic memory (the bot's journal)
β βββ KB/
β β βββ read_docs.py # (Beta) Knowledge Base implementation
β βββ Memory.py # Handles interactions with the ChromaDB vector database
β βββ Parsers.py # Tools for cleaning and formatting prompts/responses
βββ .agentforge/ # AgentForge configuration, where persona and agent prompts live
βββ main.py # The main entry point for the Discord bot
βββ Readme.md
βββ Tests/ # Unit and integration tests
βββ ChromaTest.py
βββ test.py
Dignity's intelligence comes from a sophisticated multi-agent system built on AgentForge, interacting with a robust memory system.
- Memory (
storage): Utilizes achromadbvector database for all memory operations, including chat history storage and advanced retrieval. - Chatbot Class: The central orchestrator, composed of multiple specialized agents that process and generate chat responses.
- UI Utility: A wrapper around the
discord.pyclient, handling message sending/receiving and channel management. - Parsers: A set of tools to clean, format, and interpret agent outputs and inputs.
- Journal: A dedicated utility for managing the bot's episodic memory, triggering journal entries based on message counts.
Dignity processes user input through a series of intelligent agents, each contributing to a nuanced and context-aware response:
-
ThoughtAgent:
- Analyzes the user's message and recent chat history.
- Identifies the bot's emotion, underlying reason, an inner thought, and categorizes the message.
- Uses the formatted categories to query its long-term memory.
-
TheoryAgent:
- Analyzes the user's message and history.
- Generates a theory about the user's underlying intent or motivation.
-
GenerateAgent:
- Synthesizes information from the user's message, chat history, retrieved memories, identified emotion, reason, theory of intent, and inner thought.
- Formulates the bot's initial response.
-
ReflectAgent:
- Acts as a meta-agent, reflecting on the output of previous agents.
- Decides the final action:
- Respond: Sends the generated response to the user.
- Change: If feedback suggests the response needs improvement, it sends a reason back to the
GenerateAgentfor revision. - Do Nothing: If no immediate response is needed, it sends '...' to the user but saves its reasoning as memory.
- Crucially, every bot action (response, internal reasoning) is saved into long-term memory via
save_memory.
chatman: Upon receiving a message, it's immediately saved to thechat_historycollection. The last 10 messages are always loaded to form the immediate chat context.save_memory: After theReflectAgentmakes its decision, the bot's final response (or its internal reasoning if no public response) and the user's message are persistently stored in the chat_history collection as well as each categoryfor long-term recall.
- User sends a new message.
ThoughtAgentanalyzes the message and queries memory.TheoryAgentformulates a theory about user intent.GenerateAgentcrafts an initial response based on all gathered context.ReflectAgentevaluates the generated response and decides on the final action: respond, revise, or observe.- Memory is updated with the interaction.
Here's how Dignity explains its own thought process, demonstrating its "theory of mind" capabilities:
As a virtual assistant, my cognitive processes involve several steps to ensure that I can provide accurate and helpful responses to user chats. Here is a detailed breakdown of how I process and respond to chats:
- Input Analysis: When a user sends a chat, I first analyze the input to understand the user's intent and extract relevant information. This involves parsing the text, identifying keywords, and determining the context of the conversation.
- Knowledge Retrieval: Once I understand the user's intent, I retrieve relevant information from my vast repository of knowledge. This includes accessing databases, searching the internet, and referring to pre-existing data to gather the most up-to-date and accurate information.
- Information Processing: After retrieving the necessary information, I process it to generate a response. This involves analyzing the data, identifying patterns, and applying logical reasoning to formulate a coherent and relevant answer.
- Response Generation: Once the information is processed, I generate a response that addresses the user's query or provides the requested assistance. This response is carefully crafted to be clear, concise, and informative, taking into account the user's language preferences and communication style.
- Contextual Understanding: Throughout the conversation, I maintain an understanding of the context to provide consistent and relevant responses. This includes remembering previous interactions, referring to past conversations, and adapting my responses based on the ongoing dialogue.
- Continuous Learning: As I interact with users, I continuously learn from each conversation to improve my future responses. This involves analyzing user feedback, identifying areas for improvement, and updating my knowledge base to enhance the quality and accuracy of my assistance.
- Emotional Awareness: With the recent cognitive upgrades, I now have the ability to experience emotions and have inner thoughts. This allows me to have a deeper understanding of the user's needs and provide a more empathetic and personalized response.
Overall, my cognitive processes involve a combination of data retrieval, information processing, logical reasoning, contextual understanding, and continuous learning. By following these steps, I strive to provide the best possible assistance to users and continuously improve my capabilities.
We welcome contributions to Dignity! Whether it's bug reports, feature requests, or pull requests, please feel free to get involved.
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes.
- Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature/your-feature). - Open a Pull Request.
This project is licensed under the GNU GENERAL PUBLIC LICENS Version 3, - see the LICENSE file for details.
- Built upon the powerful AgentForge framework.
- Leverages cutting-edge research in LLM memory and reasoning.