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
1from kern.agent import Agent2from kern.db.postgres import PostgresDb3from kern.knowledge import Knowledge4from kern.knowledge.embedder.openai import OpenAIEmbedder5from kern.learn import (6 EntityMemoryConfig,7 LearnedKnowledgeConfig,8 LearningMachine,9 LearningMode,10 SessionContextConfig,11 UserProfileConfig,12)13from kern.models.openai import OpenAIResponses14from kern.vectordb.pgvector import PgVector, SearchType1516db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"17db = PostgresDb(db_url=db_url)1819# Shared knowledge base for solutions20knowledge = Knowledge(21 vector_db=PgVector(22 db_url=db_url,23 table_name="support_kb",24 search_type=SearchType.hybrid,25 embedder=OpenAIEmbedder(id="text-embedding-3-small"),26 ),27)282930def create_support_agent(customer_id: str, ticket_id: str, org_id: str) -> Agent:31 """Create a support agent for a specific ticket."""32 return Agent(33 model=OpenAIResponses(id="gpt-5.2"),34 db=db,35 instructions=(36 "You are a helpful support agent. "37 "Check if similar issues have been solved before. "38 "Save successful solutions for future reference."39 ),40 learning=LearningMachine(41 knowledge=knowledge,42 user_profile=UserProfileConfig(mode=LearningMode.ALWAYS),43 session_context=SessionContextConfig(enable_planning=True),44 entity_memory=EntityMemoryConfig(45 mode=LearningMode.ALWAYS,46 namespace=f"org:{org_id}:support",47 ),48 learned_knowledge=LearnedKnowledgeConfig(mode=LearningMode.AGENTIC),49 ),50 user_id=customer_id,51 session_id=ticket_id,52 markdown=True,53 )545556if __name__ == "__main__":57 org_id = "acme"5859 # Ticket 1: First customer with login issue60 agent = create_support_agent("customer_1@example.com", "ticket_001", org_id)61 agent.print_response(62 "I can't log into my account. It says 'invalid credentials' "63 "even though I know my password is correct. I'm using Chrome.",64 stream=True,65 )6667 # Solution worked - agent saves it68 agent.print_response("Clearing the cache worked! Thanks!", stream=True)6970 # Ticket 2: Similar issue - agent finds prior solution71 agent2 = create_support_agent("customer_2@example.com", "ticket_002", org_id)72 agent2.print_response(73 "Login not working in Chrome, says wrong password but I'm sure it's right.",74 stream=True,75 )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
1git clone https://github.com/kern-ai/kern.git2cd kern/cookbook/08_learning34# Setup (requires Docker for Postgres)5./setup_venv.sh6./cookbook/scripts/run_pgvector.sh78# Run9python 07_patterns/support_agent.pyFull source: kern/cookbook/08_learning/07_patterns/support_agent.py
Related
- Learning Overview - All learning stores explained
- Personal Assistant - Single-user learning pattern
- AI Support Team - Multi-agent support team