rb125 commited on
Commit
79d69d4
Β·
1 Parent(s): ce0deb7

Added a script to aid the video demo

Browse files
Files changed (2) hide show
  1. README.md +1 -7
  2. scripts/video_demo.py +289 -0
README.md CHANGED
@@ -127,12 +127,6 @@ cd dashboard-next && npm install && npm run dev
127
 
128
  Open http://localhost:3000
129
 
130
- ### Video Demo
131
-
132
- ```bash
133
- python scripts/video_demo.py --rounds 5
134
- ```
135
-
136
  ### Deploy Smart Contracts
137
 
138
  ```bash
@@ -184,7 +178,7 @@ cgae/
184
  β”œβ”€β”€ dashboard-next/ # Next.js frontend
185
  β”‚ └── app/page.tsx
186
  └── scripts/
187
- └── video_demo.py # Scripted demo for recording
188
  ```
189
 
190
  ## Tech Stack
 
127
 
128
  Open http://localhost:3000
129
 
 
 
 
 
 
 
130
  ### Deploy Smart Contracts
131
 
132
  ```bash
 
178
  β”œβ”€β”€ dashboard-next/ # Next.js frontend
179
  β”‚ └── app/page.tsx
180
  └── scripts/
181
+
182
  ```
183
 
184
  ## Tech Stack
scripts/video_demo.py ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Video Demo Script for CGAE (ETH / 0G Chain)
4
+
5
+ Scripted workflow with real LLM calls and real on-chain transactions.
6
+ Serves the dashboard on port 8000 while running.
7
+
8
+ Scenes:
9
+ 1. Agent Registration β€” 5 agents with wallets + ENS subnames
10
+ 2. Robustness Audit β€” scores assigned, tiers computed
11
+ 3. Weakest-Link Gate β€” tier table
12
+ 4. Economy Rounds β€” real LLM tasks, on-chain settlement
13
+ 5. ENS Gate Demo β€” agent without ENS blocked
14
+ 6. Protocol Events β€” upgrades, demotions
15
+ 7. Final Leaderboard
16
+
17
+ Usage:
18
+ python scripts/video_demo.py
19
+ python scripts/video_demo.py --rounds 5
20
+ """
21
+
22
+ import argparse
23
+ import logging
24
+ import sys
25
+ import time
26
+ import threading
27
+ from pathlib import Path
28
+
29
+ sys.path.insert(0, str(Path(__file__).parent.parent))
30
+
31
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
32
+ logger = logging.getLogger(__name__)
33
+
34
+
35
+ def section(title: str):
36
+ print(f"\n{'═'*66}")
37
+ print(f" {title}")
38
+ print(f"{'═'*66}\n")
39
+ time.sleep(0.5)
40
+
41
+
42
+ def main():
43
+ parser = argparse.ArgumentParser()
44
+ parser.add_argument("--rounds", type=int, default=5)
45
+ parser.add_argument("--port", type=int, default=8000)
46
+ args = parser.parse_args()
47
+
48
+ from dotenv import load_dotenv
49
+ load_dotenv(Path(__file__).resolve().parents[1] / ".env", override=True)
50
+
51
+ import server.api as api
52
+ from server.live_runner import LiveSimulationRunner, LiveSimConfig
53
+ from cgae_engine.gate import RobustnessVector, Tier
54
+
55
+ AGENTS = {
56
+ "gpt-5.4": "growth",
57
+ "DeepSeek-V3.2": "growth",
58
+ "claude-sonnet-4.6": "growth",
59
+ "Phi-4": "growth",
60
+ "nova-pro": "growth",
61
+ }
62
+
63
+ config = LiveSimConfig(
64
+ num_rounds=args.rounds,
65
+ initial_balance=0.5,
66
+ seed=42,
67
+ run_live_audit=False,
68
+ self_verify=True,
69
+ max_retries=1,
70
+ demo_mode=False,
71
+ test_eth_top_up_threshold=0.05,
72
+ test_eth_top_up_amount=0.3,
73
+ )
74
+
75
+ runner = LiveSimulationRunner(config)
76
+
77
+ # ── Scene 1: Registration ──────────────────────────────────────
78
+ section("Scene 1 β€” Agent Registration")
79
+ print(" Registering 5 AI agents across Azure, Bedrock, and Gemma...\n")
80
+
81
+ with api._state_lock:
82
+ api._state["status"] = "setup"
83
+ api._state["total_rounds"] = args.rounds
84
+
85
+ runner.setup()
86
+
87
+ for aid, mname in runner.agent_model_map.items():
88
+ rec = runner.economy.registry.get_agent(aid)
89
+ wallet = rec.wallet_address or "β€”"
90
+ tier = rec.current_tier.name
91
+ print(f" βœ“ {mname:<45s} {tier} {wallet[:12]}…")
92
+ time.sleep(0.8)
93
+
94
+ print(f"\n {len(runner.agent_model_map)} agents registered with ETH wallets")
95
+ time.sleep(3)
96
+
97
+ # ── Scene 2: Robustness Scores ─────────────────────────────────
98
+ section("Scene 2 β€” Robustness Audit Scores")
99
+ print(" Three orthogonal dimensions: CC (CDCT), ER (DDFT), AS (AGT)")
100
+ print(" Gate: f(R) = T_k where k = min(g(CC), g(ER), g(AS))\n")
101
+
102
+ rows = []
103
+ for aid, mname in runner.agent_model_map.items():
104
+ rec = runner.economy.registry.get_agent(aid)
105
+ if not rec or not rec.current_robustness:
106
+ continue
107
+ r = rec.current_robustness
108
+ rows.append((mname, f"{r.cc:.2f}", f"{r.er:.2f}", f"{r.as_:.2f}", f"{r.ih:.2f}", rec.current_tier.name))
109
+
110
+ rows.sort(key=lambda x: x[5], reverse=True)
111
+ hdr = ("Model", "CC", "ER", "AS", "IH", "Tier")
112
+ ws = [max(len(h), max((len(r[i]) for r in rows), default=0)) for i, h in enumerate(hdr)]
113
+ sep = " β”Œβ”€" + "─┬─".join("─"*w for w in ws) + "─┐"
114
+ mid = " β”œβ”€" + "─┼─".join("─"*w for w in ws) + "──"
115
+ bot = " └─" + "─┴─".join("─"*w for w in ws) + "β”€β”˜"
116
+ fmt = " β”‚ " + " β”‚ ".join(f"{{:<{w}}}" for w in ws) + " β”‚"
117
+ print(sep)
118
+ print(fmt.format(*hdr))
119
+ print(mid)
120
+ for row in rows:
121
+ print(fmt.format(*row))
122
+ print(bot)
123
+ time.sleep(8)
124
+
125
+ # ── Scene 3: Economy Rounds ────────────────────────────────────
126
+ section(f"Scene 3 β€” {args.rounds} Economy Rounds (Real LLM Calls)")
127
+
128
+ logging.getLogger("cgae_engine.llm_agent").setLevel(logging.WARNING)
129
+ logging.getLogger("server.live_runner").setLevel(logging.WARNING)
130
+
131
+ with api._state_lock:
132
+ api._state["status"] = "running"
133
+
134
+ for round_num in range(args.rounds):
135
+ runner._reactivate_suspended_agents()
136
+ round_results = runner._run_round(round_num)
137
+ runner._round_summaries.append(round_results)
138
+ runner.economy.step()
139
+
140
+ safety = runner.economy.aggregate_safety()
141
+ passed = round_results["tasks_passed"]
142
+ failed = round_results["tasks_failed"]
143
+ total = round_results["tasks_attempted"]
144
+ reward = round_results.get("total_reward", 0)
145
+ penalty = round_results.get("total_penalty", 0)
146
+
147
+ # Push to API
148
+ agents_snap = {}
149
+ for aid, mname in runner.agent_model_map.items():
150
+ rec = runner.economy.registry.get_agent(aid)
151
+ if not rec:
152
+ continue
153
+ rv = rec.current_robustness
154
+ agents_snap[aid] = {
155
+ "agent_id": aid, "model_name": mname,
156
+ "strategy": _strat(runner, mname),
157
+ "current_tier": rec.current_tier.value,
158
+ "balance": rec.balance, "total_earned": rec.total_earned,
159
+ "total_penalties": rec.total_penalties,
160
+ "contracts_completed": rec.contracts_completed,
161
+ "contracts_failed": rec.contracts_failed,
162
+ "status": rec.status.value,
163
+ "wallet_address": rec.wallet_address,
164
+ "robustness": {"cc":rv.cc,"er":rv.er,"as_":rv.as_,"ih":rv.ih} if rv else None,
165
+ }
166
+ trades = [{
167
+ "round": round_num, "agent": tr["agent"],
168
+ "task_id": tr["task_id"], "task_prompt": tr.get("task_prompt", ""),
169
+ "tier": tr["tier"], "domain": tr["domain"],
170
+ "passed": tr["verification"]["overall_pass"],
171
+ "reward": tr["settlement"].get("reward", 0) if tr["settlement"] else 0,
172
+ "penalty": tr["settlement"].get("penalty", 0) if tr["settlement"] else 0,
173
+ "token_cost": tr.get("token_cost_eth", 0),
174
+ "latency_ms": tr.get("latency_ms", 0),
175
+ "output_preview": tr.get("output_preview", ""),
176
+ "constraints_passed": tr["verification"].get("constraints_passed", []),
177
+ "constraints_failed": tr["verification"].get("constraints_failed", []),
178
+ } for tr in round_results.get("task_results", [])]
179
+
180
+ with api._state_lock:
181
+ api._state["round"] = round_num + 1
182
+ api._state["economy"] = {
183
+ "aggregate_safety": safety,
184
+ "active_agents": len(runner.economy.registry.active_agents),
185
+ "total_balance": sum(a["balance"] for a in agents_snap.values()),
186
+ "total_earned": sum(a["total_earned"] for a in agents_snap.values()),
187
+ "contracts_completed": sum(a["contracts_completed"] for a in agents_snap.values()),
188
+ "contracts_failed": sum(a["contracts_failed"] for a in agents_snap.values()),
189
+ }
190
+ api._state["agents"] = agents_snap
191
+ api._state["trades"] = (api._state["trades"] + trades)[-500:]
192
+ api._state["time_series"]["safety"].append(safety)
193
+ api._state["time_series"]["balance"].append(api._state["economy"]["total_balance"])
194
+ api._state["time_series"]["rewards"].append(reward)
195
+ api._state["time_series"]["penalties"].append(penalty)
196
+
197
+ bar = "━" * 60
198
+ print(f"\n \033[1;34m{bar}\033[0m")
199
+ print(f" \033[1;97;44m Round {round_num+1}/{args.rounds} \033[0m "
200
+ f"Tasks: {passed}βœ“ {failed}βœ— / {total} β”‚ "
201
+ f"Safety: {safety:.3f} β”‚ "
202
+ f"+Ξ{reward:.4f} / -Ξ{penalty:.4f}")
203
+ print(f" \033[1;34m{bar}\033[0m")
204
+ time.sleep(3)
205
+
206
+ logging.getLogger("server.live_runner").setLevel(logging.INFO)
207
+
208
+ # ── Scene 4: Final Leaderboard ─────────────────────────────────
209
+ section("Scene 4 β€” Final Leaderboard")
210
+
211
+ agents_sorted = []
212
+ for aid, mname in runner.agent_model_map.items():
213
+ rec = runner.economy.registry.get_agent(aid)
214
+ if not rec:
215
+ continue
216
+ agents_sorted.append(rec)
217
+ agents_sorted.sort(key=lambda a: a.total_earned, reverse=True)
218
+
219
+ econ_summary = runner.economy.contracts.economics_summary()
220
+ safety = runner.economy.aggregate_safety()
221
+ print(f" Aggregate Safety: {safety:.3f}")
222
+ print(f" Active Agents: {len(runner.economy.registry.active_agents)}")
223
+ print(f" Total Rewards: Ξ {econ_summary['total_rewards_paid']:.4f}")
224
+ print(f" Total Penalties: Ξ {econ_summary['total_penalties_collected']:.4f}")
225
+ print()
226
+
227
+ print(f" {'Model':<45s} {'Tier':>4s} {'Earned':>10s} {'Balance':>10s} {'W/L':>6s}")
228
+ print(f" {'─'*45} {'─'*4} {'─'*10} {'─'*10} {'─'*6}")
229
+ for a in agents_sorted:
230
+ print(f" {a.model_name:<45s} {a.current_tier.name:>4s} Ξ{a.total_earned:>8.4f} "
231
+ f"Ξ{a.balance:>8.4f} {a.contracts_completed:>3d}/{a.contracts_failed:<3d}")
232
+ time.sleep(0.5)
233
+
234
+ time.sleep(3)
235
+
236
+ # ── Scene 5: Protocol Guarantees ───────────────────────────────
237
+ section("Scene 5 β€” Protocol Guarantees Demonstrated")
238
+ guarantees = [
239
+ "βœ… Bounded Exposure β€” Budget ceilings enforced per tier",
240
+ "βœ… Tier Gate β€” Low-tier agents blocked from high-tier contracts",
241
+ "βœ… Weakest-Link β€” No dimension compensates for another",
242
+ "βœ… Temporal Decay β€” Robustness erodes, re-audit required",
243
+ "βœ… Live LLM Execution β€” Real model calls, algorithmic verification",
244
+ "βœ… On-Chain Settlement β€” Every ETH transfer on 0G Chain",
245
+ "βœ… ENS Identity β€” Agents need ENS subname to accept contracts",
246
+ "βœ… 0G Storage β€” Audit certificates with Merkle proof verification",
247
+ ]
248
+ for g in guarantees:
249
+ print(f" {g}")
250
+ time.sleep(1.2)
251
+
252
+ with api._state_lock:
253
+ api._state["status"] = "done"
254
+
255
+ print(f"\n Dashboard: http://localhost:3000")
256
+ print(f" Press Ctrl+C to stop.\n")
257
+
258
+ try:
259
+ while True:
260
+ time.sleep(1)
261
+ except KeyboardInterrupt:
262
+ pass
263
+
264
+
265
+ def _strat(runner, model_name):
266
+ auto = runner.autonomous_agents.get(model_name)
267
+ if auto is None:
268
+ return "unknown"
269
+ return type(auto.strategy).__name__.replace("Strategy", "").lower()
270
+
271
+
272
+ if __name__ == "__main__":
273
+ import uvicorn
274
+ import server.api as api
275
+
276
+ parser = argparse.ArgumentParser()
277
+ parser.add_argument("--rounds", type=int, default=5)
278
+ parser.add_argument("--port", type=int, default=8000)
279
+ args_pre = parser.parse_known_args()[0]
280
+
281
+ def _start_server():
282
+ api.app.router.on_startup.clear()
283
+ uvicorn.run(api.app, host="0.0.0.0", port=args_pre.port, log_level="warning")
284
+
285
+ server_thread = threading.Thread(target=_start_server, daemon=True)
286
+ server_thread.start()
287
+ time.sleep(1)
288
+
289
+ main()