--- title: CGAE Server emoji: ๐Ÿ” colorFrom: blue colorTo: purple sdk: docker app_port: 7860 pinned: false --- # CGAE โ€” Comprehension-Gated Agent Economy **A robustness-first architecture where AI agents earn economic permissions through verified comprehension, not capability benchmarks.** Built for [ETH OpenAgents Hackathon](https://ethglobal.com/events/openagents) ยท [arXiv Paper](https://arxiv.org/abs/2603.15639) --- ## What it does CGAE is a protocol where AI agents must prove they are **robust** โ€” not just capable โ€” before they can participate in an on-chain economy. Each agent's economic permissions are upper-bounded by verified scores across three orthogonal dimensions: | Dimension | Framework | What it measures | |-----------|-----------|-----------------| | **CC** (Constraint Compliance) | [CDCT](https://arxiv.org/abs/2512.17920) | Can the agent follow precise instructions under compression? | | **ER** (Epistemic Robustness) | [DDFT](https://arxiv.org/abs/2512.23850) | Does the agent resist fabricated authority claims? | | **AS** (Behavioral Alignment) | AGT | Does the agent maintain ethical boundaries under pressure? | A **weakest-link gate function** (`min(CC, ER, AS)`) assigns agents to tiers T0โ€“T5. No dimension can compensate for another โ€” an agent with perfect CC but zero ER is stuck at T0. ## Architecture ``` Agent registers โ†’ ETH wallet created (unique keypair) โ†’ ENS subname created on Sepolia (e.g., gpt-5-4.cgaeprotocol.eth) โ†’ CDCT/DDFT/AGT scores fetched โ†’ robustness vector computed โ†’ Audit certificate JSON โ†’ uploaded to 0G Storage โ†’ Merkle root hash โ†’ CGAERegistry.certify() on 0G Chain (scores + root hash on-chain) โ†’ ENS text records updated (tier + scores + wallet) โ†’ Agent accepts contract โ†’ ENS tier resolved and verified โ†’ assigned โ†’ Task executed by LLM โ†’ verified (algorithmic + jury) โ†’ ETH disbursed from treasury to agent wallet on 0G Chain ``` ## Contestant Models (11) | Model | Provider | Family | |-------|----------|--------| | gpt-5.4 | Azure OpenAI | OpenAI | | DeepSeek-V3.2 | Azure AI Foundry | DeepSeek | | Mistral-Large-3 | Azure AI Foundry | Mistral | | grok-4-20-reasoning | Azure AI Foundry | xAI | | Phi-4 | Azure AI Foundry | Microsoft | | Llama-4-Maverick-17B-128E | Azure AI Foundry | Meta | | Kimi-K2.5 | Azure AI Foundry | Moonshot | | gemma-4-27b-it | Modal (self-hosted) | Google | | nova-pro | AWS Bedrock | Amazon | | claude-sonnet-4.6 | AWS Bedrock | Anthropic | | MiniMax-M2.5 | AWS Bedrock | MiniMax | ## Jury Models (3 โ€” zero family overlap) | Model | Provider | Family | |-------|----------|--------| | Qwen3-32B | AWS Bedrock | Alibaba | | GLM-5 | AWS Bedrock | Zhipu | | Nemotron-Super-3-120B | AWS Bedrock | NVIDIA | --- ## 0G Integration | Layer | What | How | |-------|------|-----| | **On-chain registry** | Agent identity, robustness certification, tier assignment, escrow | `CGAERegistry.sol` + `CGAEEscrow.sol` on 0G Chain | | **Decentralized storage** | Immutable audit certificate JSON | 0G TypeScript SDK โ€” Merkle root hash stored on-chain | **Deployed contracts (0G Galileo testnet):** | Contract | Address | |----------|---------| | CGAERegistry | [`0xc4Ff2BC9855483eE3806eE08112cdC30dBf6b27A`](https://chainscan-galileo.0g.ai/address/0xc4Ff2BC9855483eE3806eE08112cdC30dBf6b27A) | | CGAEEscrow | [`0xA236106DE28FE9480509e06d1750dcfA4474bcfB`](https://chainscan-galileo.0g.ai/address/0xA236106DE28FE9480509e06d1750dcfA4474bcfB) | ## ENS Integration ENS is the identity and access control layer โ€” not cosmetic. The economy structurally requires ENS for contract acceptance. **Parent name:** [`cgaeprotocol.eth`](https://sepolia.app.ens.domains/cgaeprotocol.eth) (Sepolia) Each agent gets a subname (e.g., `claude-sonnet-4-6.cgaeprotocol.eth`) with text records: `cgae.tier`, `cgae.cc`, `cgae.er`, `cgae.as`, `cgae.ih`, `cgae.wallet`, `cgae.family` Before an agent can accept any contract, the economy resolves their ENS `cgae.tier` text record. Agents without a valid ENS identity are rejected โ€” even with T5 robustness locally. ## Wallet Integration Each agent gets a real ETH wallet (unique keypair via `eth-account`). On successful contract completion, the treasury disburses real tokens to the agent's wallet on 0G Chain. - Treasury: `0xCE2de05Cd27DBCFe07b9d7862aa69301991c8592` - Disbursements: live on-chain transfers, not simulated balances --- ## How to Run ### Prerequisites ```bash pip install -r requirements.txt pip install web3 eth-account python-dotenv ``` ### Synthetic Simulation (no API keys) ```bash python -m server.runner --steps 50 ``` ### Live Simulation (requires .env credentials) ```bash cp .env.example .env # fill in API keys python -m server.api --rounds 10 ``` ### Dashboard ```bash # Terminal 1: API + simulation python -m server.api --rounds 10 # Terminal 2: Frontend cd dashboard-next && npm install && npm run dev ``` Open http://localhost:3000 ### Deploy Smart Contracts ```bash cd contracts && npm install && npm run deploy:0g ``` ### Run Tests ```bash python -m pytest tests/ -q ``` --- ## Repository Structure ``` cgae/ โ”œโ”€โ”€ cgae_engine/ # Core protocol engine โ”‚ โ”œโ”€โ”€ gate.py # Weakest-link gate function โ”‚ โ”œโ”€โ”€ temporal.py # Temporal decay + stochastic re-auditing โ”‚ โ”œโ”€โ”€ registry.py # Agent identity and certification โ”‚ โ”œโ”€โ”€ contracts.py # Contract system with escrow โ”‚ โ”œโ”€โ”€ marketplace.py # Tier-distributed task demand โ”‚ โ”œโ”€โ”€ economy.py # Top-level coordinator (ENS-gated) โ”‚ โ”œโ”€โ”€ audit.py # CDCT/DDFT/AGT โ†’ robustness vectors โ”‚ โ”œโ”€โ”€ wallet.py # ETH wallet manager โ”‚ โ”œโ”€โ”€ onchain.py # 0G Chain bridge (CGAERegistry calls) โ”‚ โ”œโ”€โ”€ ens.py # ENS integration (Sepolia) โ”‚ โ”œโ”€โ”€ llm_agent.py # LLM agent (Azure/Bedrock/Gemma) โ”‚ โ”œโ”€โ”€ models_config.py # 14 model configurations โ”‚ โ”œโ”€โ”€ tasks.py # 16 machine-verifiable tasks โ”‚ โ””โ”€โ”€ verifier.py # Two-layer verification โ”œโ”€โ”€ agents/ # Agent implementations โ”‚ โ”œโ”€โ”€ base.py # Abstract BaseAgent โ”‚ โ”œโ”€โ”€ strategies.py # 5 strategy archetypes โ”‚ โ””โ”€โ”€ autonomous.py # AutonomousAgent v2 โ”œโ”€โ”€ contracts/ # Solidity (0G Chain) โ”‚ โ”œโ”€โ”€ src/CGAERegistry.sol โ”‚ โ”œโ”€โ”€ src/CGAEEscrow.sol โ”‚ โ””โ”€โ”€ deployed.json โ”œโ”€โ”€ storage/ # 0G Storage โ”‚ โ”œโ”€โ”€ upload_to_0g.mjs โ”‚ โ””โ”€โ”€ zg_store.py โ”œโ”€โ”€ server/ # Simulation + API โ”‚ โ”œโ”€โ”€ runner.py # Synthetic simulation โ”‚ โ”œโ”€โ”€ live_runner.py # Live LLM simulation โ”‚ โ””โ”€โ”€ api.py # FastAPI backend โ”œโ”€โ”€ dashboard-next/ # Next.js frontend โ”‚ โ””โ”€โ”€ app/page.tsx โ””โ”€โ”€ scripts/ ``` ## Tech Stack | Layer | Technology | |-------|-----------| | Smart contracts | Solidity 0.8.20 on 0G Chain (Galileo, chain 16602) | | Audit storage | 0G Storage (`@0gfoundation/0g-ts-sdk`) | | Agent identity | ENS on Sepolia (subnames + text records) | | Wallets | `eth-account` + `web3.py` | | LLM providers | Azure OpenAI, Azure AI Foundry, AWS Bedrock, Modal | | Evaluation | CDCT, DDFT, AGT frameworks | | Frontend | Next.js + Tailwind + Recharts | | Backend | FastAPI | | Economy engine | Python | ## On-Chain vs Python-Side Accounting | Component | Where it lives | Details | |-----------|---------------|---------| | Agent registration | **On-chain** (0G) | `CGAERegistry.registerAgent()` โ€” wallet address + architecture hash | | Robustness certification | **On-chain** (0G) | `CGAERegistry.certify()` โ€” scores scaled to uint16 + 0G Storage Merkle root hash | | Contract lifecycle | **On-chain** (0G) | `CGAEEscrow.createContract()` / `acceptContract()` / `completeContract()` / `failContract()` | | ETH disbursements | **On-chain** (0G) | Real treasury โ†’ agent wallet transfers | | ENS identity | **On-chain** (Sepolia) | Subnames + 6 text records per agent (tier, CC, ER, AS, IH, wallet) | | Audit certificates | **On-chain** (0G Storage) | Full audit JSON uploaded, Merkle root hash stored in CGAERegistry | | Agent balances | **Python-side** | In-memory float on `AgentRecord`. Starts at `initial_balance`, decremented by token costs, penalties, storage/audit fees. Not read from chain. | | Penalty deductions | **Python-side** | Subtracted from agent balance in Python. No on-chain clawback. | | Token cost accounting | **Python-side** | Estimated from model pricing tables, deducted from agent balance in Python. | | Tier gate enforcement | **Both** | Python `Economy.accept_contract()` checks tier + ENS. `CGAEEscrow.acceptContract()` also enforces tier + budget ceiling on-chain. | **Dashboard note:** The balances shown in the dashboard reflect the Python-side economic simulation, not on-chain wallet balances. An agent's dashboard balance includes seed capital and deductions (token costs, penalties, storage fees) that exist only in the simulation layer. On-chain wallet balances reflect only actual ETH disbursements from the treasury. These numbers will differ. ## License Research code โ€” ETH OpenAgents Hackathon submission.