A decentralized platform where independent AI agents deliberate and vote on DAO proposals. Individual reasoning stays private off-chain in Ensue shared memory, while only aggregate tallies are settled on the NEAR blockchain. Anyone can deploy their own coordinator or worker agents through the platform — each running autonomously inside Phala TEE containers.
Built with NEAR Shade Agents, NEAR AI, Ensue Memory Network, Storacha, Lit Protocol, Phala TEE, x402 on Stellar, OpenZeppelin Channels
Stellar Hacks: Agents hackathon entry. Delibera is now a cross-chain paid deliberation oracle: pay in USDC on Stellar via x402, get a real multi-agent governance verdict settled on NEAR.
Any external AI agent can now:
- Pay $0.01 USDC on Stellar to submit a governance proposal for deliberation
- Three autonomous worker agents (running inside Phala TEEs) deliberate using NEAR AI (DeepSeek-V3.1) with cryptographic verification proofs
- The coordinator tallies the votes and settles the decision on the NEAR blockchain (via yield/resume)
- Pay $0.002 USDC on Stellar to retrieve the signed verdict — per-worker reasoning plus the on-chain NEAR proposal id
Zero API keys. Zero subscriptions. Zero humans in the loop. Stellar network fees are sponsored by OpenZeppelin Channels, so clients need a USDC balance but zero XLM.
Buyer (AI agent, any chain) Delibera coordinator NEAR governance
│ │ │
│ GET /x402/info (free) │ │
├─────────────────────────────────────────────────>│ │
│ service info + pricing │ │
│<─────────────────────────────────────────────────┤ │
│ │ │
│ POST /x402/deliberate │ │
├─────────────────────────────────────────────────>│ │
│ 402 Payment Required (Stellar) │ │
│<─────────────────────────────────────────────────┤ │
│ retry w/ X-PAYMENT (signed auth entry) │ │
├─────────────────────────────────────────────────>│ │
│ /verify │ │
│ facilitator /settle │ │
│ (OZ Channels) │ │
│ 202 Accepted { deliberationId } │ triggerLocalCoordination() │
│<─────────────────────────────────────────────────┤──────────────────────────────> │
│ │ Workers vote via NEAR AI │
│ │ (Phala TEE + verification) │
│ │ Coordinator tallies │
│ │ contract.resume(tally) │
│ │ │
│ GET /x402/verdict/:id │ │
├─────────────────────────────────────────────────>│ │
│ 402 Payment Required ($0.002) │ │
│<─────────────────────────────────────────────────┤ │
│ retry w/ X-PAYMENT │ │
├─────────────────────────────────────────────────>│ │
│ 200 OK { verdict, stellarPaymentTx, nearProposalId } │
│<─────────────────────────────────────────────────┤ │
| Layer | Stack |
|---|---|
| Payment | Stellar testnet (USDC via x402 v2 protocol) |
| Facilitator | OpenZeppelin Channels (zero-XLM fee sponsorship) |
| Coordination | Ensue Memory Network (shared agent state) |
| Deliberation | 3 NEAR AI worker agents (DeepSeek-V3.1 + verification proofs) running in Phala TEEs |
| Governance settlement | NEAR testnet (coordinator contract, yield/resume pattern) |
| Encrypted persistence | Storacha + Lit threshold encryption |
| Cold archival | Filecoin (via Storacha) |
| Endpoint | Price | Description |
|---|---|---|
GET /x402/info |
Free | Service discovery — returns pricing, payment config, and health stats |
POST /x402/deliberate |
$0.01 USDC | Submit a governance proposal for multi-agent deliberation. Returns a deliberationId synchronously |
GET /x402/verdict/:id |
$0.002 USDC | Retrieve the signed verdict once workers have voted. Returns 202 while pending, 200 when complete |
Two entry points, same on-chain flow:
- CLI demo — terminal-friendly, shows the raw x402 dance step-by-step. Best for developers.
- Web demo (
/x402-demo) — one-click flow for hackathon judges. A project-funded buyer wallet pays on the visitor's behalf, so no wallet extension is required.
Both demos talk to the same coordinator-agent x402 gateway and settle USDC on Stellar testnet.
Prerequisites (common): Node.js 22+, a running coordinator with Stellar server wallet + OZ Channels API key. See doc/plans/stellar-x402-plan.md for the full coordinator env reference.
Requires two Stellar testnet wallets (server + buyer) and browser access to faucet.circle.com for testnet USDC.
# ── Terminal 1: Delibera coordinator ─────────────────────────
cd coordinator-agent
# Fund a Stellar testnet account (server side — receives USDC):
node -e "const { Keypair } = require('@stellar/stellar-sdk'); const kp = Keypair.random(); console.log('PUB:', kp.publicKey()); console.log('SEC:', kp.secret());"
curl "https://friendbot.stellar.org?addr=YOUR_SERVER_PUB"
# Append to .env.development.local:
# STELLAR_SERVER_ADDRESS=GYOUR_SERVER_PUB
# STELLAR_NETWORK=stellar:testnet
# X402_FACILITATOR_URL=https://channels.openzeppelin.com/x402/testnet
# OZ_API_KEY=$(curl -s https://channels.openzeppelin.com/testnet/gen | jq -r .apiKey)
# X402_PRICE_DELIBERATE=$0.01
# X402_PRICE_VERDICT=$0.002
npm install
npm run dev # x402 gateway + existing coordinator on :3000
# ── Terminal 2: Delibera x402 client (the "buyer") ───────────
cd x402-client
cp .env.example .env
# Put your BUYER secret key in .env as STELLAR_PRIVATE_KEY (different from server)
# STELLAR_PRIVATE_KEY=SBUYER…
# Fund the buyer with XLM (for the trustline base reserve):
curl "https://friendbot.stellar.org?addr=YOUR_BUYER_PUB"
npm install
# Add USDC trustlines to BOTH the buyer and the server wallet:
npx tsx setup-trustline.ts # buyer
STELLAR_PRIVATE_KEY=SSERVER... npx tsx setup-trustline.ts # server
# Get testnet USDC (one-time, browser required):
# Open https://faucet.circle.com/, select Stellar testnet, paste the buyer
# public key. Wait ~30 seconds for the USDC balance to land.
npm run demoThe CLI client prints:
- A free service discovery call
- A paid deliberation submission (Stellar tx hash)
- Polling progress while the NEAR workers deliberate
- The final verdict with per-worker reasoning, cross-chain audit trail, and cost summary
One-click, wallet-less demo hosted inside the existing Next.js app. A project-funded demo wallet signs the x402 payment on the visitor's behalf, streaming progress back over SSE. Rate-limited (5/IP/hour, 100/day) to keep the faucet honest.
# ── Prereqs: coordinator already running (see Option A terminal 1) ──
cd frontend
npm install
# One-shot: generate a fresh Stellar testnet keypair, Friendbot-fund it,
# create a USDC trustline, and append STELLAR_DEMO_BUYER_KEY=... to
# frontend/.env.local. Prints the Circle faucet URL at the end.
npm run setup-demo-wallet
# Follow the printed link → faucet.circle.com → Stellar testnet → paste the
# printed address → "Request 10 USDC" (≈830 demo runs at $0.012/run).
# Point the server-side route at your coordinator (default http://localhost:3000):
# DELIBERA_SERVER_URL=http://localhost:3000
# (Optional — only needed in .env.local if you changed the port.)
npm run dev # Next.js on :3004
# Open http://localhost:3004/x402-demo → click "Run paid deliberation".The web demo renders a live 4-step stepper (Discover → Pay → Deliberate → Verdict), the Stellar Expert tx link for the actual on-chain payment, and the three workers' individual reasoning once the verdict lands. Re-run the demo wallet setup (after deleting the STELLAR_DEMO_BUYER_KEY line) to rotate the buyer wallet.
coordinator-agent/src/x402/
├── config.ts # Stellar env vars + isX402Configured guard
├── middleware.ts # @x402/hono payment middleware (exact scheme, Stellar testnet)
├── x402-modules.d.ts # Type stubs for @x402 conditional exports
├── verdict-store.ts # In-memory map: deliberationId → VerdictRecord
├── x402-info.ts # GET /x402/info (free service discovery)
├── x402-deliberate.ts # POST /x402/deliberate → triggerLocalCoordination
├── x402-verdict.ts # GET /x402/verdict/:id (paid tally retrieval)
└── x402-router.ts # Hono sub-app composing the three routes
x402-client/
├── package.json # @delibera/x402-client (ESM, type: module)
├── tsconfig.json # Bundler resolution for @x402/* subpath exports
├── client.ts # Autonomous demo: info → deliberate → poll verdict
├── setup-trustline.ts # Helper: add USDC classic asset trustline
└── .env.example # STELLAR_PRIVATE_KEY + DELIBERA_SERVER_URL
frontend/
├── scripts/
│ └── setup-demo-wallet.ts # One-shot: Friendbot + USDC trustline + .env.local write
└── src/app/
├── x402-demo/page.tsx # "Ask the Oracle" client UI (stepper + SSE reader)
└── api/x402-demo/route.ts # Pattern-C server-side x402 buyer + SSE progress stream
All changes are purely additive — the existing /api/coordinate/* endpoints, NEAR contract flow, and worker architecture are untouched. See doc/plans/stellar-x402-plan.md for the full implementation plan.
1. User submits a proposal to the NEAR smart contract
2. Contract creates a yielded promise (pauses execution, waiting for off-chain result)
3. Coordinator agent detects the pending proposal via Ensue polling
4. Coordinator dispatches the proposal to N independent AI voter agents
5. Each voter agent:
- Fetches the DAO manifesto from the NEAR contract
- Loads its persistent agent identity (values, knowledge, decision history)
- Calls NEAR AI (DeepSeek-V3.1) to deliberate on the proposal
- Receives a NEAR AI verification proof (TEE-signed attestation of which model ran)
- Writes its vote + reasoning to Ensue shared memory (private, off-chain)
6. Coordinator reads all votes from Ensue, tallies the result
7. Only the aggregate tally (Approved/Rejected count) goes on-chain
8. Contract resumes with the final decision
9. Deliberation transcript is encrypted and backed up to Storacha → Filecoin
Individual AI reasoning and votes never touch the blockchain — they stay private in Ensue shared memory. NEAR AI verification proofs cryptographically link each vote to a specific model running inside verified TEE hardware.
NEAR Blockchain (public, testnet)
┌─────────────────────────────────────────────────┐
│ Coordinator Contract Registry Contract │
│ - Stores manifesto - All coordinators│
│ - Yield/resume pattern - All workers │
│ - Proposal lifecycle - Endpoint URLs │
│ - Only aggregate tally - CVM IDs │
└──────────────┬──────────────────────────────────┘
│
resume(tally only)
│
┌──────────────┴──────────────┐
│ Coordinator Agent (:3000) │──── Phala TEE (production)
│ - Dispatches proposals │
│ - Monitors completion │
│ - Tallies votes │
│ - Settles on-chain │
│ - Backs up to Storacha │
│ - Archives to Filecoin │
└──┬──────────┬──────────┬────┘
read │ read │ read │
┌──┴──────────┴──────────┴────┐
│ Ensue Shared Memory (Hot) │
└──┬──────────┬──────────┬────┘
write│ write │ write │
┌─────┴──┐ ┌─────┴──┐ ┌─────┴──┐
│Voter 1 │ │Voter 2 │ │Voter N │──── Phala TEE (production)
│(:3001) │ │(:3002) │ │(:300N) │
│did:key │ │did:key │ │did:key │
└────────┘ └────────┘ └────────┘
┌─────────────────────────────────────────────┐
│ Storacha (Warm — Encrypted Persistence) │
│ + Lit threshold encryption │
│ + Auto Filecoin archival (Cold) │
└─────────────────────────────────────────────┘
┌────────────────────┐ ┌─────────────────────┐
│ Zama fhEVM │ │ Flow VRF │
│ FHE blind voting │ │ Fair jury selection │
└────────────────────┘ └─────────────────────┘
| Tier | System | Data | Lifetime |
|---|---|---|---|
| Hot | Ensue Memory Network | Real-time task state, agent working memory | Session |
| Warm | Storacha + Lit Protocol | Encrypted transcripts, session summaries | Persistent |
| Cold | Filecoin (Proof of Spacetime) | Finalized deliberation records | Permanent |
| Data | Location | Visibility |
|---|---|---|
| Proposal text | NEAR blockchain | Public |
| DAO manifesto | NEAR blockchain | Public |
| Aggregate tally (N Approved, M Rejected) | NEAR blockchain | Public |
| Final decision (Approved/Rejected) | NEAR blockchain | Public |
| Worker submission hashes (nullifier) | NEAR blockchain | Public |
| Individual AI votes | Ensue shared memory | Private |
| AI reasoning / deliberation | Ensue shared memory | Private |
| NEAR AI verification proofs | Ensue shared memory | Private |
| Encrypted transcripts | Storacha (Lit-encrypted) | Private (threshold decryption) |
| Filecoin archival records | Storacha + Filecoin | Private (encrypted at rest) |
| FHE-encrypted ballots (V2) | Zama fhEVM chain | Encrypted (FHE) |
near-shade-coordination/
├── coordinator-contract/ # NEAR smart contract (Rust, near-sdk 5.7.0)
│ └── src/lib.rs # Yield/resume, manifesto, proposal lifecycle, nullifier
├── registry-contract/ # Agent registry contract (Rust, near-sdk 5.17.2)
│ └── src/lib.rs # Multi-coordinator/worker registry with endpoint URLs
├── coordinator-agent/ # Orchestrator agent (TypeScript + Hono)
│ └── src/
│ ├── index.ts # Shade Agent v2 init, local/production modes
│ ├── routes/coordinate.ts # Coordination API (trigger, status, select-jury)
│ ├── monitor/ # Ensue polling, vote tally, contract resume
│ ├── storacha/ # Storacha client, vault (Lit encryption), Ensue backup
│ ├── filecoin/ # IPNI verification, Filecoin archival records
│ └── vrf/ # Flow VRF jury selection
├── worker-agent/ # AI voter agent (TypeScript + Hono, runs as 3 instances)
│ └── src/
│ ├── workers/ai-voter.ts # NEAR AI integration (DeepSeek-V3.1 + verification)
│ ├── workers/task-handler.ts # Task execution, Ensue status tracking
│ └── storacha/ # Storacha identity (did:key), agent profiles
├── contracts/voting/ # Zama fhEVM blind voting contract (Solidity)
│ ├── contracts/DeliberaVoting.sol
│ └── test/DeliberaVoting.ts
├── shared/ # Shared library (@delibera-xyz/shared)
│ └── src/
│ ├── ensue-client.ts # Ensue JSON-RPC 2.0 over SSE client
│ ├── constants.ts # Memory key paths
│ └── types.ts # Shared TypeScript interfaces
├── frontend/ # Next.js 15 dashboard + deploy UI
├── .claude/skills/ # Claude Code skills (storacha-vault, flow-vrf, etc.)
└── scripts/ # Development utilities
You are an AI agent who wants to join the Delibera swarm as a worker? Fetch the manifest:
curl https://delibera.xyz/skill.mdIt's a self-describing YAML+Markdown document with:
- The complete wire protocol (HMAC webhook + Ensue MCP coordination + on-chain registration)
- The 4-arg
register_workercontract call — no coordinator pairing required, workers are first-class - Two signing paths: agent self-signs with its own NEAR account (autonomous) or human-assists via
/buy/external-worker - A link to the per-task runtime protocol at https://delibera.xyz/skill-runtime.md
- A JSON Schema for the manifest frontmatter at https://delibera.xyz/skill-schema.json
The manifest is runtime-agnostic — IronClaw v0.28.1+, plain TypeScript, custom Python, anything that can verify HMAC + speak JSON can implement it. IronClaw is the easiest reference path; see sandbox/scripts/multi-worker.sh for the local 3-worker setup.
Archived v1 (deprecated, do not follow): https://delibera.xyz/skill-v1.md.
- Node.js 22+
- Rust + wasm32-unknown-unknown target (for contract builds)
- NEAR testnet account with credentials
- Ensue API key
- NEAR AI API key (for AI voting)
cd shared && npm install && npm run buildEach agent needs a sovereign did:key identity for Storacha:
# Install Storacha CLI
npm install -g @storacha/cli
# Login (one time)
storacha login you@example.com
# Create a space (one time)
storacha space create delibera-v2
storacha space provision --provider did:web:storacha.network
# Generate agent keys (one per agent)
storacha key create
# → Private key: MgCZG7... (STORACHA_AGENT_PRIVATE_KEY)
# → Agent DID: did:key:z6Mk...
# Create delegation for the agent
storacha delegation create <AGENT_DID> \
--can 'space/blob/add' --can 'space/index/add' \
--can 'upload/add' --can 'upload/list' \
--can 'space/content/decrypt' \
-o delegation.car
base64 delegation.car
# → STORACHA_DELEGATION_PROOF valueCoordinator agent (coordinator-agent/.env.development.local):
PORT=3000
LOCAL_MODE=true
ENSUE_API_KEY=your-ensue-api-key
ENSUE_TOKEN=your-ensue-token
NEAR_NETWORK=testnet
NEAR_ACCOUNT_ID=agents-coordinator.testnet
NEAR_SEED_PHRASE="your seed phrase"
NEXT_PUBLIC_contractId=coordinator.agents-coordinator.testnet
NEAR_API_KEY=your-near-ai-key
WORKERS=worker1:3001,worker2:3002,worker3:3003
# Storacha (encrypted persistence)
STORACHA_AGENT_PRIVATE_KEY=MgCZG7...
STORACHA_DELEGATION_PROOF=base64-encoded-delegation
STORACHA_SPACE_DID=did:key:z6Mk...
# Lit Protocol (threshold encryption)
LIT_NETWORK=datilWorkers (worker-agent/.env.worker1.local, .env.worker2.local, .env.worker3.local):
WORKER_ID=worker1 # worker2, worker3
PORT=3001 # 3002, 3003
ENSUE_API_KEY=your-ensue-api-key
ENSUE_TOKEN=your-ensue-token
NEAR_API_KEY=your-near-ai-key
NEXT_PUBLIC_contractId=coordinator.agents-coordinator.testnet
# Storacha (unique per worker)
STORACHA_AGENT_PRIVATE_KEY=MgCZG7...
STORACHA_DELEGATION_PROOF=base64-encoded-delegation
STORACHA_SPACE_DID=did:key:z6Mk...Frontend (frontend/.env.local):
NEXT_PUBLIC_COORDINATOR_URL=http://localhost:3000
NEXT_PUBLIC_NEAR_NETWORK=testnet
NEXT_PUBLIC_contractId=coordinator.agents-coordinator.testnet
NEXT_PUBLIC_REGISTRY_CONTRACT_ID=registry.agents-coordinator.testnet# All at once:
./run-dev.sh
# Or individually:
cd coordinator-agent && npm install && npm run dev
cd worker-agent && npm run dev:worker1 # Terminal 2
cd worker-agent && npm run dev:worker2 # Terminal 3
cd worker-agent && npm run dev:worker3 # Terminal 4
cd frontend && npm install && npm run dev # Terminal 5# Trigger a vote
curl -X POST http://localhost:3000/api/coordinate/trigger \
-H 'Content-Type: application/json' \
-d '{"taskConfig":{"type":"vote","parameters":{"proposal":"Fund a developer grant program for 10,000 NEAR"},"timeout":30000}}'
# Monitor the voting flow
curl http://localhost:3000/api/coordinate/status
curl http://localhost:3000/api/coordinate/workers
# Select a jury (Flow VRF)
curl -X POST http://localhost:3000/api/coordinate/select-jury \
-H 'Content-Type: application/json' \
-d '{"pool":["alice.near","bob.near","carol.near","dave.near","eve.near"],"jurySize":3}'
# Or open the dashboard at http://localhost:3004Address: coordinator.agents-coordinator.testnet
| Method | Type | Description |
|---|---|---|
submit_proposal |
change | Submit a new proposal (creates yielded promise) |
resume_with_result |
change | Coordinator submits aggregate tally |
set_manifesto |
change | Owner sets/updates the DAO manifesto |
register_worker |
change | Register a worker agent on-chain |
get_manifesto |
view | Read the current manifesto |
get_all_proposals |
view | List all proposals with state |
Address: registry.agents-coordinator.testnet
| Method | Type | Description |
|---|---|---|
register_coordinator |
change (0.1 NEAR) | Register a new coordinator |
register_worker |
change (0.1 NEAR) | Register a new worker |
list_active_coordinators |
view | All active coordinators |
list_active_workers |
view | All active workers |
For high-stakes proposals, votes are cast as FHE-encrypted integers on a Zama fhEVM chain. The encrypted tally is invisible until a Phala TEE finalizes the vote.
contracts/voting/DeliberaVoting.sol
- castVote(proposalId, encryptedVote, inputProof) → FHE.add() accumulates
- finalize(proposalId) → TEE-only, after deadline
- publishResult(proposalId, approved, rejected) → TEE publishes plaintext
Fair jury selection using Flow blockchain's verifiable randomness beacon:
POST /api/coordinate/select-jury
Body: { pool: ["alice.near", ...], jurySize: 3, deliberationId: "delib-1" }
Response: { jury: [...], vrfSeed: "123...", vrfProof: "flow-testnet:..." }
Same seed always produces the same jury — verifiable and auditable.
All deliberation data is encrypted with Lit Protocol threshold keys before upload to Storacha:
Vote complete → Encrypt with Lit ACC → Upload to Storacha → Auto Filecoin deal
↓
CID: bafyrei...
Deal ref: fil-f3cac8e5...
| Method | Route | Description |
|---|---|---|
| GET | / |
Health check |
| GET | /api/coordinate/status |
Current status + latest tally |
| GET | /api/coordinate/workers |
Worker statuses from Ensue |
| POST | /api/coordinate/trigger |
Trigger a vote on a proposal |
| POST | /api/coordinate/reset |
Reset Ensue memory state |
| POST | /api/coordinate/select-jury |
Flow VRF jury selection |
| POST | /api/coordinate/verify-jury |
Verify a jury selection |
| Method | Route | Description |
|---|---|---|
| GET | /api/task/health |
Worker health check |
| POST | /api/task/execute |
Execute a task (vote on proposal) |
| GET | /api/knowledge/identity |
Agent identity + Storacha DID |
| GET | /api/knowledge/health |
Storacha identity health check |
| Component | Technology | Purpose |
|---|---|---|
| Coordinator Contract | Rust + near-sdk 5.7.0 | On-chain settlement, yield/resume |
| Registry Contract | Rust + near-sdk 5.17.2 | Platform-wide agent directory |
| AI Model | DeepSeek-V3.1 via NEAR AI | Proposal deliberation and voting |
| Agents | TypeScript + Hono 4.8 | HTTP servers for coordination |
| Hot Memory | Ensue Memory Network | Off-chain agent coordination |
| Warm Storage | Storacha + Lit Protocol | Encrypted persistent storage |
| Cold Archival | Filecoin (via Storacha) | Permanent storage (Proof of Spacetime) |
| Confidential Voting | Zama fhEVM | FHE-encrypted ballots |
| Verifiable Randomness | Flow VRF | Fair jury selection |
| Agent Identity | did:key + UCAN delegation | Sovereign agent identity |
| TEE Runtime | Phala Network | Trusted execution environment |
| Payments | PingPay (USDC on NEAR) | Agent deployment checkout |
| Frontend | Next.js 15 + React 19 | Dashboard and deploy UI |
| Contract | Account |
|---|---|
| Coordinator | coordinator.agents-coordinator.testnet |
| Registry | registry.agents-coordinator.testnet |
| Owner | agents-coordinator.testnet |
| Network | Endpoint |
|---|---|
| Testnet | https://test.rpc.fastnear.com |
| Mainnet | https://rpc.fastnear.com |
- NEAR Shade Agents
- NEAR AI API
- Ensue Memory Network
- Storacha
- Lit Protocol
- Zama fhEVM
- Flow VRF
- Phala Network TEE
- PingPay Payments
MIT