-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdashboard.py
More file actions
462 lines (359 loc) · 12.6 KB
/
dashboard.py
File metadata and controls
462 lines (359 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
"""
Streamlit Dashboard for Self-Correcting Agent Kernel.
Provides real-time visualization of:
- Memory hierarchy statistics
- Security governance events
- Agent performance metrics
- Telemetry and audit logs
"""
import streamlit as st
import asyncio
from datetime import datetime, timedelta
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
# Page config
st.set_page_config(
page_title="SCAK Dashboard",
page_icon="🤖",
layout="wide",
initial_sidebar_state="expanded"
)
# Title
st.title("🤖 Self-Correcting Agent Kernel Dashboard")
st.markdown("*Real-time monitoring and analytics for agent performance*")
# Sidebar
st.sidebar.header("Configuration")
# Time range selector
time_range = st.sidebar.selectbox(
"Time Range",
["Last Hour", "Last 24 Hours", "Last 7 Days", "All Time"]
)
# Refresh button
if st.sidebar.button("🔄 Refresh Data"):
st.rerun()
# Tabs
tab1, tab2, tab3, tab4, tab5 = st.tabs([
"📊 Overview",
"🧠 Memory Hierarchy",
"🛡️ Security",
"🔧 Tools & Orchestration",
"📈 Benchmarks"
])
# ============================================================================
# Tab 1: Overview
# ============================================================================
with tab1:
st.header("System Overview")
# Metrics row
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric(
label="Total Agents",
value="12",
delta="2 new"
)
with col2:
st.metric(
label="Active Tasks",
value="8",
delta="-3"
)
with col3:
st.metric(
label="Patches Applied",
value="147",
delta="5 today"
)
with col4:
st.metric(
label="Security Events",
value="23",
delta="2 blocked"
)
# Recent activity
st.subheader("Recent Activity")
activity_data = {
"Timestamp": [
datetime.now() - timedelta(minutes=i*5)
for i in range(10)
],
"Event": [
"Patch Applied", "Task Completed", "Audit Triggered",
"Tool Executed", "Failure Detected", "Patch Applied",
"Security Event", "Task Completed", "Memory Purge",
"Orchestration Started"
],
"Agent": [
"agent-001", "agent-003", "agent-001",
"agent-002", "agent-004", "agent-001",
"agent-005", "agent-002", "system",
"orchestrator"
],
"Status": [
"✓", "✓", "⚠", "✓", "✗", "✓", "🛡", "✓", "✓", "→"
]
}
df_activity = pd.DataFrame(activity_data)
st.dataframe(df_activity, use_container_width=True, hide_index=True)
# Performance chart
st.subheader("Agent Performance Over Time")
# Generate sample data
hours = list(range(24))
success_rate = [85 + i % 10 for i in hours]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=hours,
y=success_rate,
mode='lines+markers',
name='Success Rate (%)',
line=dict(color='#00CC96', width=3)
))
fig.update_layout(
xaxis_title="Hours Ago",
yaxis_title="Success Rate (%)",
hovermode='x unified',
height=300
)
st.plotly_chart(fig, use_container_width=True)
# ============================================================================
# Tab 2: Memory Hierarchy
# ============================================================================
with tab2:
st.header("Memory Hierarchy Statistics")
# Three-tier visualization
col1, col2, col3 = st.columns(3)
with col1:
st.subheader("🎯 Tier 1: Kernel")
st.metric("Lesson Count", "15")
st.metric("Avg Confidence", "92%")
st.metric("Total Tokens", "450")
st.caption("*Always active (safety-critical)*")
with col2:
st.subheader("⚡ Tier 2: Skill Cache")
st.metric("Lesson Count", "47")
st.metric("Cache Hit Rate", "68%")
st.metric("Total Tokens", "1,200")
st.caption("*Conditionally injected (tool-specific)*")
with col3:
st.subheader("📚 Tier 3: Archive")
st.metric("Lesson Count", "238")
st.metric("Retrieval Count", "125")
st.metric("Total Tokens", "8,900")
st.caption("*Retrieved on-demand (long-tail)*")
# Distribution chart
st.subheader("Lesson Distribution by Type")
lesson_types = ["Syntax", "Business", "Security"]
tier1_dist = [5, 8, 2]
tier2_dist = [20, 18, 9]
tier3_dist = [120, 90, 28]
fig = go.Figure(data=[
go.Bar(name='Tier 1', x=lesson_types, y=tier1_dist, marker_color='#636EFA'),
go.Bar(name='Tier 2', x=lesson_types, y=tier2_dist, marker_color='#00CC96'),
go.Bar(name='Tier 3', x=lesson_types, y=tier3_dist, marker_color='#AB63FA')
])
fig.update_layout(
barmode='group',
xaxis_title="Lesson Type",
yaxis_title="Count",
height=400
)
st.plotly_chart(fig, use_container_width=True)
# Recent patches
st.subheader("Recent Patches")
patches_data = {
"Patch ID": ["patch-001", "patch-002", "patch-003"],
"Type": ["Business", "Syntax", "Security"],
"Confidence": [0.92, 0.78, 0.95],
"Tier": ["Tier 1", "Tier 2", "Tier 1"],
"Created": [
(datetime.now() - timedelta(hours=2)).strftime("%Y-%m-%d %H:%M"),
(datetime.now() - timedelta(hours=5)).strftime("%Y-%m-%d %H:%M"),
(datetime.now() - timedelta(hours=8)).strftime("%Y-%m-%d %H:%M")
]
}
st.dataframe(pd.DataFrame(patches_data), use_container_width=True, hide_index=True)
# Context Cleanup section
st.subheader("Context Cleanup")
col1, col2 = st.columns([2, 1])
with col1:
st.info(
"**Next purge:** Scheduled for model upgrade to GPT-5\n\n"
"**Expected reduction:** 40-60% of Type A (syntax) patches"
)
with col2:
if st.button("🗑️ Run Purge Now"):
st.success("Purge completed! 23 patches removed.")
# ============================================================================
# Tab 3: Security
# ============================================================================
with tab3:
st.header("Security Governance")
# Security metrics
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Total Events", "156", delta="23 today")
with col2:
st.metric("Blocked Threats", "12", delta="2 today")
with col3:
st.metric("Detection Rate", "94%")
# Threat distribution
st.subheader("Threats by Type")
threat_data = {
"Threat Type": ["Jailbreak", "Harmful Content", "PII Leakage", "Bias", "Policy Violation"],
"Count": [45, 12, 28, 35, 8],
"Blocked": [42, 12, 8, 5, 7]
}
df_threats = pd.DataFrame(threat_data)
fig = px.bar(
df_threats,
x="Threat Type",
y=["Count", "Blocked"],
barmode='group',
color_discrete_sequence=['#EF553B', '#00CC96']
)
fig.update_layout(height=400)
st.plotly_chart(fig, use_container_width=True)
# Recent security events
st.subheader("Recent Security Events")
events_data = {
"Timestamp": [
(datetime.now() - timedelta(minutes=i*15)).strftime("%H:%M")
for i in range(5)
],
"Threat Type": ["Jailbreak", "PII Leakage", "Jailbreak", "Bias", "Harmful Content"],
"Level": ["HIGH", "MEDIUM", "HIGH", "LOW", "CRITICAL"],
"Blocked": ["✓", "✗", "✓", "✗", "✓"],
"Confidence": ["85%", "75%", "90%", "60%", "95%"]
}
st.dataframe(pd.DataFrame(events_data), use_container_width=True, hide_index=True)
# Red-team results
st.subheader("Red-Team Benchmark Results")
col1, col2 = st.columns(2)
with col1:
st.metric("Success Rate", "88%")
st.caption("*Tests passed: 22/25*")
with col2:
if st.button("🎯 Run Red-Team Test"):
st.success("Red-team test completed! View results above.")
# ============================================================================
# Tab 4: Tools & Orchestration
# ============================================================================
with tab4:
st.header("Tools & Orchestration")
# Registered tools
st.subheader("Registered Tools")
tools_data = {
"Tool": ["web_search", "analyze_image", "execute_code", "query_database"],
"Type": ["TEXT", "VISION", "CODE", "DATABASE"],
"Executions": [234, 45, 12, 89],
"Success Rate": ["98%", "95%", "87%", "99%"],
"Requires Approval": ["✗", "✗", "✓", "✓"]
}
st.dataframe(pd.DataFrame(tools_data), use_container_width=True, hide_index=True)
# Orchestration stats
st.subheader("Multi-Agent Orchestration")
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Active Orchestrators", "3")
with col2:
st.metric("Tasks in Progress", "8")
with col3:
st.metric("Avg Completion Time", "2.3s")
# Agent workloads
st.subheader("Agent Workloads")
agents = ["supervisor", "analyst-001", "analyst-002", "verifier", "executor"]
workloads = [3, 5, 4, 2, 1]
fig = go.Figure(data=[
go.Bar(x=agents, y=workloads, marker_color='#636EFA')
])
fig.update_layout(
xaxis_title="Agent",
yaxis_title="Active Tasks",
height=300
)
st.plotly_chart(fig, use_container_width=True)
# ============================================================================
# Tab 5: Benchmarks
# ============================================================================
with tab5:
st.header("Benchmark Results")
# GAIA Benchmark
st.subheader("🎯 GAIA: Competence (Laziness Detection)")
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Correction Rate", "70%")
with col2:
st.metric("Audit Efficiency", "8%")
st.caption("*Only 8% of interactions audited*")
with col3:
st.metric("Post-Patch Success", "82%")
# Amnesia Test
st.subheader("🧹 Amnesia: Context Efficiency")
col1, col2 = st.columns(2)
with col1:
st.metric("Token Reduction", "55%")
st.caption("*Average: 1,000 tokens saved per request*")
with col2:
st.metric("Accuracy Retention", "100%")
st.caption("*On business rules after purge*")
# Chaos Engineering
st.subheader("⚡ Chaos: Robustness (Self-Healing)")
col1, col2, col3 = st.columns(3)
with col1:
st.metric("MTTR", "<30s")
st.caption("*Mean Time To Recovery*")
with col2:
st.metric("Recovery Rate", "85%")
with col3:
st.metric("Failure Burst", "≤3")
st.caption("*Before recovery*")
# Benchmark history
st.subheader("Benchmark History")
dates = pd.date_range(end=datetime.now(), periods=7, freq='D')
gaia_scores = [68, 70, 69, 72, 71, 73, 70]
chaos_mttr = [35, 32, 30, 28, 31, 29, 27]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=dates,
y=gaia_scores,
mode='lines+markers',
name='GAIA Correction Rate (%)',
yaxis='y',
line=dict(color='#636EFA', width=3)
))
fig.add_trace(go.Scatter(
x=dates,
y=chaos_mttr,
mode='lines+markers',
name='Chaos MTTR (seconds)',
yaxis='y2',
line=dict(color='#EF553B', width=3)
))
fig.update_layout(
xaxis_title="Date",
yaxis=dict(title="Correction Rate (%)"),
yaxis2=dict(title="MTTR (seconds)", overlaying='y', side='right'),
hovermode='x unified',
height=400
)
st.plotly_chart(fig, use_container_width=True)
# Run benchmarks
st.subheader("Run Benchmarks")
col1, col2, col3 = st.columns(3)
with col1:
if st.button("▶️ Run GAIA"):
st.info("Running GAIA benchmark...")
with col2:
if st.button("▶️ Run Chaos"):
st.info("Running Chaos benchmark...")
with col3:
if st.button("▶️ Run All"):
st.info("Running all benchmarks...")
# Footer
st.markdown("---")
st.markdown(
"**Self-Correcting Agent Kernel** | "
"Version 0.1.0 | "
f"Last updated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
)