wu981526092 commited on
Commit
b450ab8
ยท
1 Parent(s): 9aa4f2b

Add Perfect Sample Data for HF Spaces Demo

Browse files

- Created comprehensive multi-agent customer service scenario
- Sample trace with 5 specialized agents and error handling
- Knowledge graph with 15 entities and 18 relations
- Demonstrates optimization opportunities and failure recovery
- Auto-loads only on HF Spaces when database is empty
- Users see immediate value instead of empty dashboard

backend/app.py CHANGED
@@ -82,23 +82,6 @@ async def startup_event():
82
  if os.getenv("SPACE_ID"):
83
  logger.info("๐Ÿ”’ HF Spaces: Using in-memory database for user privacy")
84
  logger.info("๐Ÿ“ Note: Data will be cleared when container restarts")
85
-
86
- # Load perfect demo data for HF Spaces
87
- try:
88
- from backend.database.demo_data_loader import load_demo_trace_for_hf_spaces
89
- from backend.database import SessionLocal
90
-
91
- # Create database session for demo loading
92
- with SessionLocal() as demo_session:
93
- demo_loaded = load_demo_trace_for_hf_spaces(demo_session)
94
- if demo_loaded:
95
- logger.info("๐ŸŽฏ Perfect demonstration trace loaded for immediate user experience")
96
- else:
97
- logger.info("โš ๏ธ Demo trace loading skipped - users will start with empty database")
98
-
99
- except Exception as demo_error:
100
- logger.warning(f"Demo data loading failed (non-critical): {demo_error}")
101
-
102
  else:
103
  logger.info("๐Ÿ’พ Local development: Using persistent database")
104
 
 
82
  if os.getenv("SPACE_ID"):
83
  logger.info("๐Ÿ”’ HF Spaces: Using in-memory database for user privacy")
84
  logger.info("๐Ÿ“ Note: Data will be cleared when container restarts")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  else:
86
  logger.info("๐Ÿ’พ Local development: Using persistent database")
87
 
backend/database/demo_data_loader.py DELETED
@@ -1,135 +0,0 @@
1
- """
2
- Demo Data Loader for HF Spaces
3
- Automatically loads a perfect demonstration trace with rich analysis results
4
- """
5
-
6
- import os
7
- import json
8
- import logging
9
- from pathlib import Path
10
- from typing import Dict, Any
11
- from datetime import datetime
12
-
13
- logger = logging.getLogger(__name__)
14
-
15
- def load_demo_trace_for_hf_spaces(db_session):
16
- """
17
- Load demonstration trace data for HF Spaces to provide immediate user experience
18
- Only runs in HF Spaces environment with in-memory database
19
- """
20
-
21
- # Only load demo data in HF Spaces environment
22
- if not os.getenv("SPACE_ID"):
23
- logger.info("Not in HF Spaces environment, skipping demo data loading")
24
- return False
25
-
26
- try:
27
- # Get demo trace file path
28
- demo_file = Path(__file__).parent.parent.parent / "datasets" / "demo" / "perfect_demo_trace.json"
29
-
30
- if not demo_file.exists():
31
- logger.warning(f"Demo trace file not found at {demo_file}")
32
- return False
33
-
34
- # Load demo trace data
35
- with open(demo_file, 'r', encoding='utf-8') as f:
36
- demo_data = json.load(f)
37
-
38
- logger.info("๐Ÿ“Š Loading perfect demonstration trace for HF Spaces...")
39
-
40
- # Import the trace using the existing save_trace utility
41
- from backend.database.utils import save_trace
42
-
43
- # Convert demo data to trace format
44
- trace_content = json.dumps(demo_data, indent=2)
45
-
46
- # Create the trace record
47
- trace = save_trace(
48
- session=db_session,
49
- content=trace_content,
50
- filename="perfect_demo_trace.json",
51
- title="๐Ÿš€ Perfect Demo: E-commerce Recommendation System Optimization",
52
- description="Complete multi-agent analysis of a failing recommendation system with performance recovery, failure analysis, and optimization strategies. Demonstrates model drift detection, infrastructure scaling, and systematic problem-solving.",
53
- trace_type="demo",
54
- trace_source="hf_spaces_demo",
55
- tags=["demo", "multi-agent", "optimization", "failure-analysis", "e-commerce", "ml-system"]
56
- )
57
-
58
- logger.info(f"โœ… Demo trace loaded successfully: {trace.trace_id}")
59
- logger.info(f"๐Ÿ“ˆ Title: {trace.title}")
60
- logger.info(f"๐Ÿท๏ธ Tags: {', '.join(trace.tags) if trace.tags else 'none'}")
61
-
62
- # Process the trace to generate knowledge graph
63
- logger.info("๐Ÿง  Generating knowledge graph from demo trace...")
64
-
65
- try:
66
- # Import and use the knowledge graph generation
67
- from agentgraph.methods.production.multi_agent_knowledge_extractor import create_knowledge_graph
68
-
69
- # Extract knowledge graph from the trace
70
- kg_result = create_knowledge_graph(trace_content)
71
-
72
- if kg_result and "final_kg" in kg_result:
73
- # Save the knowledge graph
74
- from backend.database.utils import save_knowledge_graph
75
-
76
- kg_record = save_knowledge_graph(
77
- session=db_session,
78
- trace_id=trace.trace_id,
79
- knowledge_graph_data=kg_result["final_kg"],
80
- metadata={
81
- "demo_type": "perfect_example",
82
- "generated_at": datetime.now().isoformat(),
83
- "entities_count": len(kg_result["final_kg"].get("entities", [])),
84
- "relations_count": len(kg_result["final_kg"].get("relations", [])),
85
- "analysis_depth": "comprehensive",
86
- "optimization_identified": True,
87
- "failure_patterns_detected": 3
88
- }
89
- )
90
-
91
- logger.info(f"๐ŸŽฏ Knowledge graph generated successfully: {kg_record.kg_id}")
92
- logger.info(f"๐Ÿ“Š Entities: {len(kg_result['final_kg'].get('entities', []))}")
93
- logger.info(f"๐Ÿ”— Relations: {len(kg_result['final_kg'].get('relations', []))}")
94
-
95
- else:
96
- logger.warning("Knowledge graph generation returned empty result")
97
-
98
- except Exception as kg_error:
99
- logger.error(f"Failed to generate knowledge graph from demo trace: {kg_error}")
100
- # Don't fail the whole demo loading process
101
-
102
- # Add some summary stats for the UI
103
- logger.info("๐ŸŽ‰ Perfect demo environment ready!")
104
- logger.info("๐Ÿ‘ค Users will see: Rich trace analysis, failure detection, optimization strategies")
105
- logger.info("๐Ÿ” Features demonstrated: Multi-agent collaboration, system optimization, performance recovery")
106
-
107
- return True
108
-
109
- except FileNotFoundError:
110
- logger.error(f"Demo trace file not found: {demo_file}")
111
- return False
112
- except json.JSONDecodeError as e:
113
- logger.error(f"Invalid JSON in demo trace file: {e}")
114
- return False
115
- except Exception as e:
116
- logger.error(f"Failed to load demo trace: {e}")
117
- return False
118
-
119
-
120
- def get_demo_stats():
121
- """Get statistics about the loaded demo data for display"""
122
- return {
123
- "demo_loaded": True,
124
- "trace_title": "Perfect Demo: E-commerce Recommendation System Optimization",
125
- "agent_count": 4,
126
- "optimization_steps": 8,
127
- "failures_analyzed": 3,
128
- "performance_improvements": {
129
- "model_accuracy": "+18%",
130
- "inference_latency": "-39%",
131
- "system_cpu": "-35%",
132
- "cache_hit_rate": "+48%"
133
- },
134
- "business_impact": "$1.8-2.1M monthly revenue recovery"
135
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/database/init_db.py CHANGED
@@ -43,6 +43,233 @@ def confirm_reset():
43
  response = input("Are you sure you want to continue? (yes/no): ")
44
  return response.lower() in ["yes", "y"]
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def init_database(reset=False, force=False):
47
  """
48
  Initialize the database with the required tables.
@@ -330,6 +557,11 @@ def init_database(reset=False, force=False):
330
 
331
  logger.info(f"Database contains: {kg_count} knowledge graphs, {entity_count} entities, {relation_count} relations, {trace_count} traces")
332
 
 
 
 
 
 
333
  # Close connection
334
  conn.close()
335
 
 
43
  response = input("Are you sure you want to continue? (yes/no): ")
44
  return response.lower() in ["yes", "y"]
45
 
46
+ def add_sample_data(cursor, conn):
47
+ """Add sample trace and knowledge graph data for demonstration purposes."""
48
+ import json
49
+ import uuid
50
+ import hashlib
51
+
52
+ # Sample trace content - Multi-agent customer service scenario
53
+ sample_trace_content = '''[
54
+ {
55
+ "role": "user",
56
+ "content": "I need help with my order #12345. It was supposed to arrive yesterday but I still haven't received it. This is very frustrating as I need it for an important meeting tomorrow.",
57
+ "timestamp": "2024-08-31T10:00:00Z",
58
+ "metadata": {"priority": "high", "emotion": "frustrated"}
59
+ },
60
+ {
61
+ "role": "assistant",
62
+ "name": "RouterAgent",
63
+ "content": "I understand your frustration about the delayed order. Let me route this to our order tracking specialist who can provide detailed information about your shipment.",
64
+ "timestamp": "2024-08-31T10:00:15Z",
65
+ "actions": [{"type": "route", "target": "OrderTrackingAgent", "priority": "high"}]
66
+ },
67
+ {
68
+ "role": "assistant",
69
+ "name": "OrderTrackingAgent",
70
+ "content": "I'll look up order #12345 immediately. Checking our tracking system... I found the issue - there was a delay at the distribution center due to weather conditions. Your package is currently in transit and should arrive by 2 PM today.",
71
+ "timestamp": "2024-08-31T10:01:00Z",
72
+ "actions": [
73
+ {"type": "database_query", "query": "SELECT * FROM orders WHERE order_id = '12345'"},
74
+ {"type": "api_call", "endpoint": "shipping_tracker", "response": "in_transit"}
75
+ ],
76
+ "findings": {
77
+ "issue": "Weather delay at distribution center",
78
+ "current_status": "In transit",
79
+ "estimated_delivery": "2024-08-31T14:00:00Z"
80
+ }
81
+ },
82
+ {
83
+ "role": "assistant",
84
+ "name": "CompensationAgent",
85
+ "content": "Given this delay caused inconvenience, I'm authorizing a $10 credit to your account and providing free expedited shipping on your next order. I'm also escalating this to ensure better communication about delays in the future.",
86
+ "timestamp": "2024-08-31T10:02:00Z",
87
+ "actions": [
88
+ {"type": "credit_account", "amount": 10, "reason": "delivery_delay"},
89
+ {"type": "add_benefit", "type": "free_expedited_shipping"},
90
+ {"type": "escalate", "department": "operations", "issue": "delayed_delivery_communication"}
91
+ ],
92
+ "error": "Failed to process account credit - payment system temporarily unavailable"
93
+ },
94
+ {
95
+ "role": "assistant",
96
+ "name": "SupervisorAgent",
97
+ "content": "I see there was an error processing the account credit. I'm manually flagging your account for the $10 credit and expedited shipping benefit. Our technical team will resolve the payment system issue. You should see the credit within 24 hours.",
98
+ "timestamp": "2024-08-31T10:03:00Z",
99
+ "actions": [
100
+ {"type": "manual_flag", "account_credit": 10},
101
+ {"type": "technical_escalation", "system": "payment_processor"},
102
+ {"type": "follow_up_schedule", "timeframe": "24_hours"}
103
+ ],
104
+ "optimization_opportunity": "Implement payment system redundancy to prevent credit processing failures"
105
+ },
106
+ {
107
+ "role": "user",
108
+ "content": "Thank you for the quick response and compensation. I appreciate you taking care of this issue promptly.",
109
+ "timestamp": "2024-08-31T10:04:00Z",
110
+ "sentiment": "satisfied"
111
+ },
112
+ {
113
+ "role": "assistant",
114
+ "name": "QualityAgent",
115
+ "content": "Session completed successfully. Customer satisfaction restored. Identified system improvement: need better proactive communication about shipping delays and payment system reliability backup.",
116
+ "timestamp": "2024-08-31T10:05:00Z",
117
+ "session_analysis": {
118
+ "resolution_time": "5 minutes",
119
+ "customer_satisfaction": "high",
120
+ "agents_involved": 4,
121
+ "system_errors": 1,
122
+ "optimization_recommendations": [
123
+ "Implement proactive delay notifications",
124
+ "Add payment system redundancy",
125
+ "Improve agent handoff protocols"
126
+ ]
127
+ }
128
+ }
129
+ ]'''
130
+
131
+ # Generate trace metadata
132
+ trace_id = str(uuid.uuid4())
133
+ content_hash = hashlib.sha256(sample_trace_content.encode()).hexdigest()
134
+
135
+ # Insert sample trace
136
+ cursor.execute('''
137
+ INSERT INTO traces (
138
+ trace_id, filename, title, description, content, content_hash,
139
+ uploader, trace_type, trace_source, character_count, turn_count,
140
+ status, tags, trace_metadata
141
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
142
+ ''', (
143
+ trace_id,
144
+ "sample_customer_service.json",
145
+ "Multi-Agent Customer Service Resolution",
146
+ "Demonstration of multi-agent system handling customer complaint with error handling and optimization opportunities",
147
+ sample_trace_content,
148
+ content_hash,
149
+ "AgentGraph Demo",
150
+ "multi_agent",
151
+ "sample",
152
+ len(sample_trace_content),
153
+ 6, # Number of turns
154
+ "processed",
155
+ json.dumps(["sample", "customer_service", "multi_agent", "error_handling", "optimization"]),
156
+ json.dumps({
157
+ "scenario": "customer_service",
158
+ "agents": ["RouterAgent", "OrderTrackingAgent", "CompensationAgent", "SupervisorAgent", "QualityAgent"],
159
+ "domain": "e_commerce",
160
+ "complexity": "high"
161
+ })
162
+ ))
163
+
164
+ # Create sample knowledge graph
165
+ kg_id = 1 # First knowledge graph
166
+
167
+ # Insert knowledge graph metadata
168
+ cursor.execute('''
169
+ INSERT INTO knowledge_graphs (
170
+ filename, creator, entity_count, relation_count, namespace,
171
+ system_name, system_summary, status, trace_id, window_index,
172
+ window_total, processing_run_id
173
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
174
+ ''', (
175
+ "sample_customer_service_kg.json",
176
+ "AgentGraph Demo",
177
+ 15, # Will match actual entities inserted
178
+ 18, # Will match actual relations inserted
179
+ "customer_service_demo",
180
+ "Multi-Agent Customer Service System",
181
+ "An intelligent customer service system featuring multiple specialized agents working together to resolve customer issues, handle errors, and identify optimization opportunities. The system demonstrates sophisticated agent coordination, error recovery mechanisms, and continuous improvement processes.",
182
+ "completed",
183
+ trace_id,
184
+ 0,
185
+ 1,
186
+ "sample_demo_run"
187
+ ))
188
+
189
+ # Sample entities with rich properties
190
+ entities_data = [
191
+ # Agents
192
+ ("agent_1", "agent", "RouterAgent", {"role": "traffic_routing", "specialization": "request_classification", "priority_handling": True}),
193
+ ("agent_2", "agent", "OrderTrackingAgent", {"role": "order_management", "specialization": "shipping_tracking", "data_sources": ["internal_db", "shipping_apis"]}),
194
+ ("agent_3", "agent", "CompensationAgent", {"role": "customer_retention", "specialization": "compensation_authorization", "max_credit_limit": 50}),
195
+ ("agent_4", "agent", "SupervisorAgent", {"role": "escalation_handling", "specialization": "system_error_recovery", "override_authority": True}),
196
+ ("agent_5", "agent", "QualityAgent", {"role": "quality_assurance", "specialization": "session_analysis", "improvement_tracking": True}),
197
+
198
+ # Systems and Tools
199
+ ("system_1", "system", "OrderDatabase", {"type": "database", "function": "order_storage", "performance": "high"}),
200
+ ("system_2", "system", "ShippingTracker", {"type": "external_api", "function": "package_tracking", "reliability": "99.5%"}),
201
+ ("system_3", "system", "PaymentProcessor", {"type": "financial_system", "function": "account_credits", "status": "temporarily_unavailable"}),
202
+
203
+ # Issues and Problems
204
+ ("issue_1", "issue", "DeliveryDelay", {"severity": "medium", "cause": "weather_conditions", "impact": "customer_satisfaction"}),
205
+ ("issue_2", "issue", "PaymentSystemFailure", {"severity": "high", "cause": "system_unavailability", "impact": "compensation_processing"}),
206
+
207
+ # Actions and Processes
208
+ ("action_1", "action", "RouteRequest", {"type": "traffic_management", "success_rate": "98%"}),
209
+ ("action_2", "action", "TrackPackage", {"type": "information_retrieval", "data_sources": 2}),
210
+ ("action_3", "action", "AuthorizeCredit", {"type": "financial_transaction", "approval_required": True}),
211
+ ("action_4", "action", "EscalateIssue", {"type": "process_escalation", "department": "operations"}),
212
+
213
+ # Improvements and Optimizations
214
+ ("improvement_1", "improvement", "ProactiveNotifications", {"priority": "high", "implementation_effort": "medium", "expected_impact": "reduce_complaints_by_30%"})
215
+ ]
216
+
217
+ # Insert entities
218
+ for entity_id, entity_type, name, properties in entities_data:
219
+ cursor.execute('''
220
+ INSERT INTO entities (
221
+ graph_id, entity_id, type, name, properties, knowledge_graph_namespace
222
+ ) VALUES (?, ?, ?, ?, ?, ?)
223
+ ''', (kg_id, entity_id, entity_type, name, json.dumps(properties), "customer_service_demo"))
224
+
225
+ # Sample relations showing complex interactions
226
+ relations_data = [
227
+ # Agent interactions
228
+ ("rel_1", "agent_1", "routes_to", "agent_2", {"context": "order_inquiry", "priority": "high", "success": True}),
229
+ ("rel_2", "agent_2", "collaborates_with", "agent_3", {"context": "customer_compensation", "coordination": "automated"}),
230
+ ("rel_3", "agent_3", "escalates_to", "agent_4", {"context": "system_error", "escalation_reason": "payment_failure"}),
231
+ ("rel_4", "agent_4", "coordinates_with", "agent_5", {"context": "quality_improvement", "outcome": "optimization_identified"}),
232
+
233
+ # System interactions
234
+ ("rel_5", "agent_2", "queries", "system_1", {"query_type": "order_lookup", "response_time": "0.5s", "success": True}),
235
+ ("rel_6", "agent_2", "calls", "system_2", {"api_endpoint": "track_package", "response_time": "1.2s", "success": True}),
236
+ ("rel_7", "agent_3", "attempts_transaction", "system_3", {"transaction_type": "credit", "amount": 10, "success": False}),
237
+
238
+ # Problem identification and resolution
239
+ ("rel_8", "agent_2", "identifies", "issue_1", {"detection_method": "system_query", "severity_assessed": "medium"}),
240
+ ("rel_9", "agent_3", "encounters", "issue_2", {"error_handling": "automatic_escalation", "recovery_action": "manual_override"}),
241
+ ("rel_10", "agent_4", "resolves", "issue_2", {"resolution_method": "manual_flag", "permanent_fix": False}),
242
+
243
+ # Action execution
244
+ ("rel_11", "agent_1", "executes", "action_1", {"execution_time": "15s", "outcome": "successful_routing"}),
245
+ ("rel_12", "agent_2", "performs", "action_2", {"data_retrieved": True, "accuracy": "100%"}),
246
+ ("rel_13", "agent_3", "initiates", "action_3", {"authorization_level": "standard", "blocked_by": "system_error"}),
247
+ ("rel_14", "agent_4", "triggers", "action_4", {"escalation_department": "operations", "follow_up_required": True}),
248
+
249
+ # Improvement opportunities
250
+ ("rel_15", "agent_5", "identifies", "improvement_1", {"analysis_method": "session_review", "confidence": "high"}),
251
+ ("rel_16", "issue_1", "leads_to", "improvement_1", {"causal_relationship": "direct", "prevention_potential": "high"}),
252
+ ("rel_17", "issue_2", "exposes", "system_3", {"vulnerability_type": "single_point_of_failure", "risk_level": "high"}),
253
+ ("rel_18", "improvement_1", "would_prevent", "issue_1", {"prevention_mechanism": "early_warning", "effectiveness": "85%"})
254
+ ]
255
+
256
+ # Insert relations
257
+ for relation_id, from_entity, relation_type, to_entity, properties in relations_data:
258
+ cursor.execute('''
259
+ INSERT INTO relations (
260
+ graph_id, relation_id, from_entity_id, relation_type, to_entity_id,
261
+ properties, knowledge_graph_namespace
262
+ ) VALUES (?, ?, ?, ?, ?, ?, ?)
263
+ ''', (kg_id, relation_id, from_entity, relation_type, to_entity, json.dumps(properties), "customer_service_demo"))
264
+
265
+ # Commit the sample data
266
+ conn.commit()
267
+
268
+ logger.info("โœ… Sample data added successfully!")
269
+ logger.info(f" โ€ข 1 sample trace: Multi-Agent Customer Service Resolution")
270
+ logger.info(f" โ€ข 1 knowledge graph with {len(entities_data)} entities and {len(relations_data)} relations")
271
+ logger.info(f" โ€ข Demonstrates: Multi-agent coordination, error handling, optimization opportunities")
272
+
273
  def init_database(reset=False, force=False):
274
  """
275
  Initialize the database with the required tables.
 
557
 
558
  logger.info(f"Database contains: {kg_count} knowledge graphs, {entity_count} entities, {relation_count} relations, {trace_count} traces")
559
 
560
+ # Add sample data for HF Spaces if database is empty
561
+ if os.getenv("SPACE_ID") and kg_count == 0 and trace_count == 0:
562
+ logger.info("๐ŸŽฏ HF Spaces detected with empty database - adding sample data...")
563
+ add_sample_data(cursor, conn)
564
+
565
  # Close connection
566
  conn.close()
567
 
datasets/demo/perfect_demo_trace.json DELETED
@@ -1,288 +0,0 @@
1
- {
2
- "trace_metadata": {
3
- "trace_id": "demo_trace_001",
4
- "task": "Analyze and optimize a failing e-commerce recommendation system",
5
- "timestamp": "2024-08-31T12:00:00Z",
6
- "duration": "18.5 minutes",
7
- "total_agents": 4,
8
- "total_tool_calls": 12,
9
- "status": "completed_with_optimizations"
10
- },
11
- "agent_interactions": [
12
- {
13
- "step": 1,
14
- "timestamp": "2024-08-31T12:00:00Z",
15
- "agent": "TaskPlanner",
16
- "role": "system",
17
- "content": "Received task: Analyze failing e-commerce recommendation system with 23% CTR drop. Planning multi-agent approach with Data Analyst, ML Engineer, and System Optimizer.",
18
- "reasoning": "Complex system analysis requires specialized agents for data investigation, model evaluation, and system optimization.",
19
- "next_agents": ["DataAnalyst", "MLEngineer"]
20
- },
21
- {
22
- "step": 2,
23
- "timestamp": "2024-08-31T12:01:30Z",
24
- "agent": "DataAnalyst",
25
- "role": "assistant",
26
- "content": "Analyzing recommendation system performance data. Checking user interaction patterns, conversion rates, and system metrics.",
27
- "tool_calls": [
28
- {
29
- "tool": "database_query",
30
- "input": "SELECT user_id, item_id, click_through_rate, conversion_rate FROM recommendations WHERE date >= '2024-08-01'",
31
- "output": "Retrieved 45,892 recommendation records. Average CTR: 23.1% (down from 46.3%). Conversion rate: 3.2% (down from 7.8%)",
32
- "success": true
33
- }
34
- ],
35
- "findings": [
36
- "CTR dropped significantly starting August 15th",
37
- "Most affected category: Electronics (67% CTR drop)",
38
- "Peak failure times: 2-4 PM and 8-10 PM (high traffic periods)"
39
- ],
40
- "reasoning": "Data shows clear performance degradation pattern. Need to investigate model and infrastructure causes."
41
- },
42
- {
43
- "step": 3,
44
- "timestamp": "2024-08-31T12:04:15Z",
45
- "agent": "MLEngineer",
46
- "role": "assistant",
47
- "content": "Evaluating recommendation model performance and feature engineering pipeline.",
48
- "tool_calls": [
49
- {
50
- "tool": "model_evaluation",
51
- "input": "Evaluate current recommendation model accuracy and latency",
52
- "output": "Model accuracy: 0.73 (down from 0.89). Average inference time: 145ms (up from 67ms)",
53
- "success": true
54
- },
55
- {
56
- "tool": "feature_analysis",
57
- "input": "Analyze feature drift and data quality issues",
58
- "output": "ERROR: Feature pipeline timeout. 23% of features showing null values. Embedding service responding slowly.",
59
- "success": false,
60
- "error": "Feature pipeline instability detected"
61
- }
62
- ],
63
- "findings": [
64
- "Model accuracy degraded by 18%",
65
- "Inference latency increased 2.2x",
66
- "Feature pipeline showing instability",
67
- "Embedding service bottleneck identified"
68
- ],
69
- "reasoning": "Performance issues stem from both model degradation and infrastructure problems. Need system optimization.",
70
- "escalation": "SystemOptimizer",
71
- "priority": "high"
72
- },
73
- {
74
- "step": 4,
75
- "timestamp": "2024-08-31T12:07:45Z",
76
- "agent": "SystemOptimizer",
77
- "role": "assistant",
78
- "content": "Investigating system architecture and infrastructure bottlenecks affecting recommendation performance.",
79
- "tool_calls": [
80
- {
81
- "tool": "system_monitoring",
82
- "input": "Check CPU, memory, and network utilization for recommendation services",
83
- "output": "CPU: 87% avg (recommendation service), Memory: 92% (embedding cache), Network: 340ms avg latency to ML models",
84
- "success": true
85
- },
86
- {
87
- "tool": "database_performance",
88
- "input": "Analyze database query performance and connection pools",
89
- "output": "Average query time: 890ms (up 4x). Connection pool: 98% utilization. 12 slow queries identified.",
90
- "success": true
91
- },
92
- {
93
- "tool": "caching_analysis",
94
- "input": "Evaluate recommendation cache hit rates and invalidation patterns",
95
- "output": "Cache hit rate: 34% (down from 78%). Cache invalidation frequency: 340% increase due to model updates",
96
- "success": true
97
- }
98
- ],
99
- "findings": [
100
- "Recommendation service under severe load (87% CPU)",
101
- "Embedding cache nearly full (92% memory usage)",
102
- "Database queries 4x slower than baseline",
103
- "Cache hit rate dropped from 78% to 34%",
104
- "Frequent cache invalidations due to model update strategy"
105
- ],
106
- "reasoning": "System bottlenecks are cascading - high memory usage affects caching, slow queries increase CPU load, poor cache performance increases database pressure."
107
- },
108
- {
109
- "step": 5,
110
- "timestamp": "2024-08-31T12:12:20Z",
111
- "agent": "TaskPlanner",
112
- "role": "system",
113
- "content": "Synthesizing findings from all agents. Root causes identified: model drift, infrastructure overload, and cache inefficiency.",
114
- "synthesis": {
115
- "root_causes": [
116
- "Model performance degraded due to data drift and feature pipeline issues",
117
- "Infrastructure cannot handle current load with increased latency",
118
- "Cache strategy inefficient due to frequent model updates"
119
- ],
120
- "impact_analysis": {
121
- "business_impact": "23% CTR drop = ~$2.3M monthly revenue loss",
122
- "user_experience": "Poor recommendations leading to decreased engagement",
123
- "system_stability": "High resource utilization risking system failures"
124
- }
125
- }
126
- },
127
- {
128
- "step": 6,
129
- "timestamp": "2024-08-31T12:14:00Z",
130
- "agent": "MLEngineer",
131
- "role": "assistant",
132
- "content": "Proposing model optimization strategy based on identified issues.",
133
- "optimization_plan": {
134
- "immediate_fixes": [
135
- "Retrain model with recent data to address drift",
136
- "Optimize feature pipeline to reduce null values",
137
- "Implement model compression to reduce inference time"
138
- ],
139
- "tool_calls": [
140
- {
141
- "tool": "model_retraining",
142
- "input": "Retrain recommendation model with last 30 days of clean data",
143
- "output": "New model accuracy: 0.86 (+13%). Inference time: 89ms (-39%)",
144
- "success": true
145
- }
146
- ]
147
- },
148
- "expected_improvements": {
149
- "accuracy": "+13% (from 0.73 to 0.86)",
150
- "latency": "-39% (from 145ms to 89ms)",
151
- "CTR_projection": "+15-20% improvement expected"
152
- }
153
- },
154
- {
155
- "step": 7,
156
- "timestamp": "2024-08-31T12:16:30Z",
157
- "agent": "SystemOptimizer",
158
- "role": "assistant",
159
- "content": "Implementing infrastructure optimizations to support improved model performance.",
160
- "optimization_actions": [
161
- {
162
- "action": "Scale embedding cache cluster",
163
- "tool_calls": [
164
- {
165
- "tool": "infrastructure_scaling",
166
- "input": "Add 2 cache nodes and optimize memory allocation",
167
- "output": "Cache cluster scaled. Memory utilization: 67% (-25%). Hit rate projected: 82%",
168
- "success": true
169
- }
170
- ]
171
- },
172
- {
173
- "action": "Optimize database queries",
174
- "tool_calls": [
175
- {
176
- "tool": "query_optimization",
177
- "input": "Add indexes and optimize slow query patterns",
178
- "output": "12 queries optimized. Average query time: 210ms (-76%)",
179
- "success": true
180
- }
181
- ]
182
- },
183
- {
184
- "action": "Implement smart cache invalidation",
185
- "details": "Reduced invalidation frequency by 60% using incremental updates"
186
- }
187
- ],
188
- "performance_gains": {
189
- "cpu_utilization": "-35% (from 87% to 57%)",
190
- "query_performance": "-76% latency improvement",
191
- "cache_hit_rate": "+48% (from 34% to 82%)"
192
- }
193
- },
194
- {
195
- "step": 8,
196
- "timestamp": "2024-08-31T12:18:30Z",
197
- "agent": "TaskPlanner",
198
- "role": "system",
199
- "content": "Final optimization results and monitoring recommendations.",
200
- "final_results": {
201
- "performance_improvements": {
202
- "model_accuracy": "0.86 (+18% from degraded state)",
203
- "inference_latency": "89ms (-39% improvement)",
204
- "system_cpu": "57% (-35% improvement)",
205
- "cache_hit_rate": "82% (+48% improvement)",
206
- "projected_ctr": "38-42% (+15-19% improvement)"
207
- },
208
- "business_impact": {
209
- "estimated_revenue_recovery": "$1.8-2.1M monthly",
210
- "user_experience_score": "+25% improvement expected",
211
- "system_reliability": "High load handling capacity restored"
212
- },
213
- "monitoring_recommendations": [
214
- "Set up alerts for model accuracy below 0.80",
215
- "Monitor cache hit rate - alert if below 75%",
216
- "Track feature pipeline health continuously",
217
- "Implement gradual model rollback capability"
218
- ],
219
- "failure_prevention": [
220
- "Automated model performance monitoring",
221
- "Infrastructure auto-scaling triggers",
222
- "Feature pipeline redundancy",
223
- "A/B testing framework for safe model updates"
224
- ]
225
- }
226
- }
227
- ],
228
- "failure_analysis": {
229
- "identified_failures": [
230
- {
231
- "type": "model_drift",
232
- "severity": "high",
233
- "impact": "18% accuracy loss",
234
- "root_cause": "Training data staleness and feature pipeline degradation",
235
- "prevention": "Automated retraining triggers and feature monitoring"
236
- },
237
- {
238
- "type": "infrastructure_bottleneck",
239
- "severity": "critical",
240
- "impact": "2.2x latency increase",
241
- "root_cause": "Insufficient cache capacity and database optimization",
242
- "prevention": "Auto-scaling policies and performance monitoring"
243
- },
244
- {
245
- "type": "tool_failure",
246
- "severity": "medium",
247
- "impact": "Feature analysis timeout in step 3",
248
- "root_cause": "Feature pipeline instability under load",
249
- "prevention": "Pipeline redundancy and timeout handling"
250
- }
251
- ],
252
- "optimization_opportunities": [
253
- {
254
- "area": "model_deployment",
255
- "opportunity": "Implement blue-green deployment for safer model updates",
256
- "potential_impact": "Zero-downtime updates, reduced risk of performance degradation"
257
- },
258
- {
259
- "area": "caching_strategy",
260
- "opportunity": "Machine learning-based cache pre-warming",
261
- "potential_impact": "90%+ cache hit rate, 50% further latency reduction"
262
- },
263
- {
264
- "area": "monitoring",
265
- "opportunity": "Predictive performance alerting using ML",
266
- "potential_impact": "Prevent issues before they impact users"
267
- }
268
- ]
269
- },
270
- "knowledge_extraction": {
271
- "key_entities": [
272
- "RecommendationSystem", "MLModel", "DataPipeline", "CacheCluster",
273
- "DatabaseQuery", "UserEngagement", "SystemPerformance", "ModelAccuracy"
274
- ],
275
- "critical_relationships": [
276
- "ModelDrift -> PerformanceDegradation",
277
- "InfrastructureBottleneck -> LatencyIncrease",
278
- "CacheInvalidation -> DatabaseLoad",
279
- "ModelOptimization -> AccuracyImprovement",
280
- "SystemScaling -> PerformanceRecovery"
281
- ],
282
- "success_patterns": [
283
- "MultiAgentCollaboration -> ComprehensiveAnalysis",
284
- "DataDrivenOptimization -> MeasurableImprovements",
285
- "InfrastructureScaling -> SystemStability"
286
- ]
287
- }
288
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontend/src/components/features/workspace/DashboardView.tsx CHANGED
@@ -4,7 +4,6 @@ import { DashboardVisualization } from "../dashboard/DashboardVisualization";
4
  import { EntityRelationAnalysisModal } from "../dashboard/modals/EntityRelationAnalysisModal";
5
  import { TinyTrendChart } from "@/components/shared/TinyTrendChart";
6
  import { EntityRelationTreeChart } from "@/components/shared/EntityRelationTreeChart";
7
- import { DemoBanner } from "@/components/shared/DemoBanner";
8
  import {
9
  generateTrendData,
10
  calculateFailureCount,
@@ -77,9 +76,6 @@ export function DashboardView() {
77
 
78
  {/* Content with relative positioning */}
79
  <div className="relative z-10 flex flex-col gap-6 h-full">
80
- {/* Demo Banner for HF Spaces */}
81
- <DemoBanner />
82
-
83
  {/* Error State */}
84
  {error && (
85
  <Card className="border-destructive/50 bg-destructive/10">
 
4
  import { EntityRelationAnalysisModal } from "../dashboard/modals/EntityRelationAnalysisModal";
5
  import { TinyTrendChart } from "@/components/shared/TinyTrendChart";
6
  import { EntityRelationTreeChart } from "@/components/shared/EntityRelationTreeChart";
 
7
  import {
8
  generateTrendData,
9
  calculateFailureCount,
 
76
 
77
  {/* Content with relative positioning */}
78
  <div className="relative z-10 flex flex-col gap-6 h-full">
 
 
 
79
  {/* Error State */}
80
  {error && (
81
  <Card className="border-destructive/50 bg-destructive/10">
frontend/src/components/shared/DemoBanner.tsx DELETED
@@ -1,113 +0,0 @@
1
- import React from "react";
2
- import { Card, CardContent } from "@/components/ui/card";
3
- import { Badge } from "@/components/ui/badge";
4
- import { Button } from "@/components/ui/button";
5
- import {
6
- Sparkles,
7
- TrendingUp,
8
- Zap,
9
- Target,
10
- ArrowRight,
11
- Users,
12
- BarChart3
13
- } from "lucide-react";
14
- import { useAgentGraph } from "@/context/AgentGraphContext";
15
- import { IS_HF_SPACES } from "@/lib/config";
16
-
17
- export function DemoBanner() {
18
- const { actions } = useAgentGraph();
19
-
20
- // Only show on HF Spaces
21
- if (!IS_HF_SPACES) {
22
- return null;
23
- }
24
-
25
- const handleExploreDemo = () => {
26
- // Navigate to traces view to show the loaded demo trace
27
- actions.setActiveView("traces");
28
- };
29
-
30
- return (
31
- <Card className="border-2 border-blue-200 bg-gradient-to-r from-blue-50 to-indigo-50 mb-6">
32
- <CardContent className="p-6">
33
- <div className="flex items-start justify-between">
34
- <div className="flex-1">
35
- {/* Header */}
36
- <div className="flex items-center gap-2 mb-3">
37
- <Sparkles className="h-5 w-5 text-blue-600" />
38
- <h3 className="text-lg font-semibold text-blue-900">
39
- ๐Ÿš€ Perfect Demo Environment Ready
40
- </h3>
41
- <Badge variant="secondary" className="bg-blue-100 text-blue-700">
42
- Pre-loaded Demo
43
- </Badge>
44
- </div>
45
-
46
- {/* Description */}
47
- <p className="text-gray-700 mb-4 leading-relaxed">
48
- Explore a complete <strong>multi-agent system analysis</strong> of a failing e-commerce
49
- recommendation system. See how AI agents collaborate to identify problems,
50
- implement optimizations, and recover system performance.
51
- </p>
52
-
53
- {/* Key Features Grid */}
54
- <div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
55
- <div className="flex items-center gap-2 text-sm text-gray-600">
56
- <Users className="h-4 w-4 text-blue-500" />
57
- <span>4 AI Agents</span>
58
- </div>
59
- <div className="flex items-center gap-2 text-sm text-gray-600">
60
- <Target className="h-4 w-4 text-green-500" />
61
- <span>3 Failures Analyzed</span>
62
- </div>
63
- <div className="flex items-center gap-2 text-sm text-gray-600">
64
- <TrendingUp className="h-4 w-4 text-orange-500" />
65
- <span>Performance +39%</span>
66
- </div>
67
- <div className="flex items-center gap-2 text-sm text-gray-600">
68
- <BarChart3 className="h-4 w-4 text-purple-500" />
69
- <span>$2.1M Recovery</span>
70
- </div>
71
- </div>
72
-
73
- {/* Highlights */}
74
- <div className="flex flex-wrap gap-2 mb-4">
75
- <Badge variant="outline" className="border-green-200 text-green-700 bg-green-50">
76
- <Zap className="h-3 w-3 mr-1" />
77
- Model Optimization
78
- </Badge>
79
- <Badge variant="outline" className="border-orange-200 text-orange-700 bg-orange-50">
80
- <TrendingUp className="h-3 w-3 mr-1" />
81
- System Scaling
82
- </Badge>
83
- <Badge variant="outline" className="border-purple-200 text-purple-700 bg-purple-50">
84
- <Target className="h-3 w-3 mr-1" />
85
- Failure Recovery
86
- </Badge>
87
- </div>
88
- </div>
89
-
90
- {/* Action Button */}
91
- <div className="ml-4 flex-shrink-0">
92
- <Button
93
- onClick={handleExploreDemo}
94
- className="bg-blue-600 hover:bg-blue-700 text-white shadow-md"
95
- >
96
- Explore Demo
97
- <ArrowRight className="h-4 w-4 ml-2" />
98
- </Button>
99
- </div>
100
- </div>
101
-
102
- {/* Bottom note */}
103
- <div className="mt-4 pt-4 border-t border-blue-200">
104
- <p className="text-xs text-blue-600 flex items-center gap-1">
105
- <Sparkles className="h-3 w-3" />
106
- This demonstration shows AgentGraph's complete analysis capabilities.
107
- Upload your own traces to analyze real AI agent interactions!
108
- </p>
109
- </div>
110
- </CardContent>
111
- </Card>
112
- );
113
- }