The Agentic Chat Service, known as Zarna AI, provides a natural language interface to query and interact with CRM data using a multi-agent AI system with persistent agent pools. Zarna AI is the intelligent chatbot that understands your questions and retrieves relevant CRM data.Location: scripts/agentic_chat/
Role: Coordinates other agents and routes queriesCapabilities:
Parse user queries
Determine which agents to invoke
Aggregate results from multiple agents
Format final response
Example:
User: "Show me all tech companies with revenue over $10M"Manager thinks:1. This needs data retrieval (CRM database)2. Assign to Data Retrieval Agent3. Wait for results4. Format and return to user
Manager request: "Get tech companies with revenue > $10M"Agent generates SQL:SELECT * FROM companiesWHERE industry = 'Technology'AND revenue > 10000000ORDER BY revenue DESCReturns: List of matching companies
# Query requires multiple steps"Find all tech companies, then calculate their average revenue"Step 1: Data Retrieval Agent └─> Fetches tech companiesStep 2: Analysis Agent └─> Calculates average revenueStep 3: Manager Agent └─> Formats final response
# Query can be parallelized"Get company overview and market intelligence for Acme Corp"Parallel:├─> Data Retrieval Agent: Fetch company data└─> Web Search Agent: Research marketManager: Combine results
from scripts.agentic_chat.core.agent_pool import AgentPoolManager# Global singletonpool_manager = AgentPoolManager()# Get pool for firmpool = await pool_manager.get_pool(firm_id)# Execute query with warm agentsresult = await pool.execute_query(query, chat_id)
Query 1: "Show me all tech companies"Response: "Found 42 tech companies..."Query 2: "Which ones have revenue over $10M?" (Refers back to tech companies from Query 1)Response: "Of the 42 tech companies, 15 have revenue over $10M..."Query 3: "Show me their deal pipelines" (Refers to the 15 companies from Query 2)Response: "Here are the deal pipelines for those 15 companies..."
try: # Try using agentic system result = await agentic_chat.query(user_query)except AgentPoolError: # Fall back to direct CRM query result = await crm_agent.query(user_query)except Exception as e: # Return helpful error message return "I encountered an error processing your query. Could you try rephrasing it?"
# Ambiguous query handlingif query_is_ambiguous(query): return { "type": "clarification_needed", "message": "I found multiple interpretations:", "options": [ "Show all companies (across all industries)", "Show companies in your most active industry", "Show recently created companies" ] }
# AI ModelsAGENTIC_MANAGER_MODEL=claude-3-opus-20240229AGENTIC_AGENT_MODEL=claude-3-sonnet-20240229AGENTIC_FAST_MODEL=claude-3-haiku-20240307# Pool SettingsAGENT_POOL_MAX_INSTANCES=3AGENT_POOL_CLEANUP_TIMEOUT_MIN=30AGENT_POOL_MAX_TOTAL_POOLS=20# PerformanceAGENTIC_MAX_CONCURRENT_QUERIES=10AGENTIC_QUERY_TIMEOUT_SEC=120# SearchEXA_API_KEY=your-exa-key