> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc-studio-tools-doc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Support Agent

> Multi-tenant support agent that learns solutions and applies them to similar issues.

## Overview

A customer support agent that combines all learning stores to provide faster resolutions over time. Uses namespace isolation for multi-tenant deployments where different organizations share the system but have separate knowledge.

## Code

```python support_agent.py theme={null}
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.knowledge import Knowledge
from agno.knowledge.embedder.openai import OpenAIEmbedder
from agno.learn import (
    EntityMemoryConfig,
    LearnedKnowledgeConfig,
    LearningMachine,
    LearningMode,
    SessionContextConfig,
    UserProfileConfig,
)
from agno.models.openai import OpenAIResponses
from agno.vectordb.pgvector import PgVector, SearchType

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)

# Shared knowledge base for solutions
knowledge = Knowledge(
    vector_db=PgVector(
        db_url=db_url,
        table_name="support_kb",
        search_type=SearchType.hybrid,
        embedder=OpenAIEmbedder(id="text-embedding-3-small"),
    ),
)


def create_support_agent(customer_id: str, ticket_id: str, org_id: str) -> Agent:
    """Create a support agent for a specific ticket."""
    return Agent(
        model=OpenAIResponses(id="gpt-5.2"),
        db=db,
        instructions=(
            "You are a helpful support agent. "
            "Check if similar issues have been solved before. "
            "Save successful solutions for future reference."
        ),
        learning=LearningMachine(
            knowledge=knowledge,
            user_profile=UserProfileConfig(mode=LearningMode.ALWAYS),
            session_context=SessionContextConfig(enable_planning=True),
            entity_memory=EntityMemoryConfig(
                mode=LearningMode.ALWAYS,
                namespace=f"org:{org_id}:support",
            ),
            learned_knowledge=LearnedKnowledgeConfig(mode=LearningMode.AGENTIC),
        ),
        user_id=customer_id,
        session_id=ticket_id,
        markdown=True,
    )


if __name__ == "__main__":
    org_id = "acme"

    # Ticket 1: First customer with login issue
    agent = create_support_agent("customer_1@example.com", "ticket_001", org_id)
    agent.print_response(
        "I can't log into my account. It says 'invalid credentials' "
        "even though I know my password is correct. I'm using Chrome.",
        stream=True,
    )

    # Solution worked - agent saves it
    agent.print_response("Clearing the cache worked! Thanks!", stream=True)

    # Ticket 2: Similar issue - agent finds prior solution
    agent2 = create_support_agent("customer_2@example.com", "ticket_002", org_id)
    agent2.print_response(
        "Login not working in Chrome, says wrong password but I'm sure it's right.",
        stream=True,
    )
```

## How It Works

* **User Profile**: Tracks customer history and preferences
* **Session Context**: Manages current ticket with goal/plan/progress
* **Entity Memory**: Stores product info, past tickets, shared across organization
* **Learned Knowledge**: Saves successful solutions for future retrieval

Key pattern: The `namespace=f"org:{org_id}:support"` isolates entity memory per organization while the learned knowledge base can be shared globally or per-org.

## Run This Example

```bash theme={null}
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/08_learning

# Setup (requires Docker for Postgres)
./setup_venv.sh
./cookbook/scripts/run_pgvector.sh

# Run
python 07_patterns/support_agent.py
```

Full source: [agno/cookbook/08\_learning/07\_patterns/support\_agent.py](https://github.com/agno-agi/agno/blob/main/cookbook/08_learning/07_patterns/support_agent.py)

## Related

* [Learning Overview](/cookbook/learning/overview) - All learning stores explained
* [Personal Assistant](/cookbook/learning/personal-assistant) - Single-user learning pattern
* [AI Support Team](/cookbook/teams/ai_support_team) - Multi-agent support team
