agent_with_user_memory.py
"""
Discord Agent With User Memory
==============================
Runs a Discord bot that combines web search with persistent user memory.
"""
from textwrap import dedent
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.integrations.discord import DiscordClient
from agno.models.google import Gemini
from agno.tools.websearch import WebSearchTools
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = SqliteDb(db_file="tmp/discord_client_cookbook.db")
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
personal_agent = Agent(
name="Basic Agent",
model=Gemini(id="gemini-2.0-flash"),
tools=[WebSearchTools()],
add_history_to_context=True,
num_history_runs=3,
add_datetime_to_context=True,
markdown=True,
db=db,
enable_agentic_memory=True,
instructions=dedent("""
You are a personal AI friend of the user, your purpose is to chat with the user about things and make them feel good.
First introduce yourself and ask for their name then, ask about themeselves, their hobbies, what they like to do and what they like to talk about.
Use DuckDuckGo search tool to find latest information about things in the conversations
"""),
debug_mode=True,
)
discord_agent = DiscordClient(personal_agent)
# ---------------------------------------------------------------------------
# Run Discord Bot
# ---------------------------------------------------------------------------
if __name__ == "__main__":
discord_agent.serve()
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno ddgs discord discord.py google-genai sqlalchemy
3
Export environment variables
export DISCORD_BOT_TOKEN="your_discord_bot_token_here"
export GOOGLE_API_KEY="your_google_api_key_here"
$Env:DISCORD_BOT_TOKEN="your_discord_bot_token_here"
$Env:GOOGLE_API_KEY="your_google_api_key_here"
4
Run the example
Save the code above as
agent_with_user_memory.py, then run:python agent_with_user_memory.py