> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Telegram Agent with User Memory

> Personal assistant bot that remembers user preferences, hobbies, and interests across conversations.

Personal assistant bot that remembers user preferences, hobbies, and interests across conversations. Uses MemoryManager to automatically capture and recall personal details from chat history.

```python agent_with_user_memory.py theme={null}
"""
Telegram Agent with User Memory
================================

Personal assistant bot that remembers user preferences, hobbies, and
interests across conversations. Uses MemoryManager to automatically
capture and recall personal details from chat history.

Key concepts:
  - ``MemoryManager`` with custom capture instructions extracts user info.
  - ``enable_agentic_memory=True`` lets the agent store and retrieve memories.
  - ``WebSearchTools`` provides live information for conversational context.

Setup: Set TELEGRAM_TOKEN env var from @BotFather.
"""

from textwrap import dedent

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.memory.manager import MemoryManager
from agno.models.google import Gemini
from agno.os.app import AgentOS
from agno.os.interfaces.telegram import Telegram
from agno.tools.websearch import WebSearchTools

# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------

agent_db = SqliteDb(db_file="tmp/persistent_memory.db")

memory_manager = MemoryManager(
    memory_capture_instructions="""\
                    Collect User's name,
                    Collect Information about user's passion and hobbies,
                    Collect Information about the users likes and dislikes,
                    Collect information about what the user is doing with their life right now
                """,
    model=Gemini(id="gemini-2.0-flash"),
)


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=agent_db,
    memory_manager=memory_manager,
    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 themselves, their hobbies, what they like to do and what they like to talk about.
        Use web search to find latest information about things in the conversations
    """),
)


agent_os = AgentOS(
    agents=[personal_agent],
    interfaces=[Telegram(agent=personal_agent)],
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    """Run your AgentOS.

    You can see the configuration and available apps at:
    http://localhost:7777/config

    """
    agent_os.serve(app="agent_with_user_memory:app", reload=True)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[os]" ddgs fastmcp google-genai starlette
    ```
  </Step>

  <Step title="Export your API keys">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export GOOGLE_API_KEY="your_google_api_key_here"
      export JWT_VERIFICATION_KEY="your_jwt_verification_key_here"
      ```

      ```bash Windows theme={null}
      $Env:GOOGLE_API_KEY="your_google_api_key_here"
      $Env:JWT_VERIFICATION_KEY="your_jwt_verification_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `agent_with_user_memory.py`, then run:

    ```bash theme={null}
    python agent_with_user_memory.py
    ```
  </Step>
</Steps>

Full source: [cookbook/05\_agent\_os/interfaces/telegram/agent\_with\_user\_memory.py](https://github.com/agno-agi/agno/blob/main/cookbook/05_agent_os/interfaces/telegram/agent_with_user_memory.py)
