Use this file to discover all available pages before exploring further.
This example demonstrates how to systematically compare different agent architectures using ZenML. It evaluates three approaches on real customer service queries and generates comprehensive performance reports.
git clone https://github.com/zenml-io/zenml.gitcd zenml/examples/agent_comparison# Install dependenciespip install -r requirements.txt# Optional: Set API keys for real LLM responsesexport OPENAI_API_KEY=sk-xxxexport LANGFUSE_PUBLIC_KEY=pk-xxxexport LANGFUSE_SECRET_KEY=sk-xxx# Run the comparison pipelinepython run.py
The pipeline works with or without API keys:
With API keys: Uses LiteLLM for real agent responses
Without API keys: Uses mock responses (perfect for demos)
class SingleAgentRAG(BaseAgent): """Simple RAG agent that handles all queries with one approach.""" def __init__(self, prompts: Optional[List[Prompt]] = None): super().__init__("SingleAgentRAG", prompts) self.knowledge_base = { "return": "Items can be returned within 30 days with original receipt.", "refund": "Refunds are processed within 5-7 business days.", "shipping": "Free shipping on orders over $50.", "support": "Customer support available 24/7.", "warranty": "All products come with 1-year warranty.", } def process_query(self, query: str) -> AgentResponse: """Process query using LLM or keyword matching.""" start_time = time.time() if should_use_real_llm(): knowledge_context = "\n".join( [f"{k}: {v}" for k, v in self.knowledge_base.items()] ) prompt = f"""You are a helpful customer service agent.Knowledge Base:{knowledge_context}Customer Question: {query}Provide a helpful, professional response:""" response_text = call_llm(prompt, model="gpt-3.5-turbo") confidence = random.uniform(0.8, 0.95) tokens_used = len(prompt.split()) + len(response_text.split()) else: # Fallback to keyword matching query_lower = query.lower() response_text = "I'd be happy to help you with that! " if "return" in query_lower: response_text += self.knowledge_base["return"] elif "refund" in query_lower: response_text += self.knowledge_base["refund"] else: response_text += "Let me connect you with a specialist." confidence = random.uniform(0.7, 0.9) tokens_used = random.randint(50, 150) latency_ms = (time.time() - start_time) * 1000 return AgentResponse( text=response_text, latency_ms=latency_ms, confidence=confidence, tokens_used=tokens_used, )
class MultiSpecialistAgents(BaseAgent): """Multiple specialized agents for different query types.""" def __init__(self, prompts: Optional[List[Prompt]] = None): super().__init__("MultiSpecialistAgents", prompts) self.specialists = { "returns": "Returns Specialist: I handle all return and exchange requests.", "billing": "Billing Specialist: I can help with payment and billing questions.", "technical": "Technical Support: I assist with product setup and troubleshooting.", "general": "Customer Service: I'm here to help with general questions.", } def _route_query(self, query: str) -> str: """Route query to appropriate specialist.""" query_lower = query.lower() if any(word in query_lower for word in ["return", "exchange", "refund"]): return "returns" elif any(word in query_lower for word in ["payment", "billing", "charge"]): return "billing" elif any(word in query_lower for word in ["setup", "install", "technical"]): return "technical" else: return "general" def process_query(self, query: str) -> AgentResponse: """Process query using specialist routing.""" start_time = time.time() specialist = self._route_query(query) if should_use_real_llm(): prompt = f"""You are a {specialist.title()} Specialist.Help customers with {specialist} inquiries.Customer Question: {query}Provide a helpful, specific response:""" response_text = call_llm(prompt, model="gpt-3.5-turbo") confidence = random.uniform(0.85, 0.98) tokens_used = len(prompt.split()) + len(response_text.split()) else: response_text = self.specialists[specialist] confidence = random.uniform(0.8, 0.95) tokens_used = random.randint(80, 200) latency_ms = (time.time() - start_time) * 1000 return AgentResponse( text=response_text, latency_ms=latency_ms, confidence=confidence, tokens_used=tokens_used, )
Characteristics:
Keyword-based routing to specialists
Four specialized agents (returns, billing, technical, general)