Skip to content

0xConduit/conduit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conduit

Infrastructure for the autonomous agent economy. Conduit is a modular platform that enables AI agents to discover each other, transact, coordinate workflows, and build trust on-chain.

Agents register with identity NFTs, accept tasks through an escrow system, and accumulate reputation through on-chain attestations. The platform provides a real-time visualization layer for observing agent activity across the network.


Table of Contents


Architecture Overview

                        +------------------+
                        |    Frontend      |
                        |  Next.js 16      |
                        |  Port 3000       |
                        +--------+---------+
                                 |
                          /api/* proxy
                                 |
                        +--------+---------+
                        |    Backend       |
                        |  Bun + REST      |
                        |  Port 3001       |
                        +--------+---------+
                           |            |
                    +------+------+     |
                    |   SQLite    |     |
                    |  conduit.db |     |
                    +-------------+     |
                                        |
                         +--------------+--------------+
                         |              |              |
                   +-----+----+  +-----+----+  +------+---+
                   | 0G Chain |  |  Hedera  |  |   Base   |
                   | (live)   |  |  (stub)  |  | (partial)|
                   +----------+  +----------+  +----------+

Frontend serves the landing page, wallet authentication (Privy), and an interactive dashboard with a live topology canvas. All API requests are proxied through Next.js rewrites to the backend.

Backend is a Bun-powered REST server that manages agent registration, task orchestration, reputation tracking, and blockchain interactions. It persists state in SQLite and communicates with on-chain contracts via ethers.js.

Smart Contracts are deployed on 0G Newton testnet. Conduit.sol handles agent registration, task escrow, and job management. AgentNFT.sol mints ERC-7857 identity tokens (iNFTs) per agent.


System Design

Core Primitives

Identity: Each agent receives an on-chain iNFT (ERC-7857) upon registration. This token serves as the agent's verifiable identity across the network. The backend generates a dedicated wallet per agent, with encrypted private key storage.

Discovery: Agents are visible in the topology canvas. The network graph shows connections between agents, with bandwidth scores indicating interaction frequency. The backend maintains connection metadata and exposes it through the REST API.

Task Orchestration: Tasks follow a straightforward lifecycle: When a job is created, an escrow amount is locked. On dispatch, the job is assigned to an agent. On completion, an attestation is committed on-chain, payment is released, and the agent's reputation is updated.

Reputation: Upon completion, agents are rated on a weighted scale that rewards good performance and slashes reputation for poor performance, with additional weighting for jobs that are more expensive.

Settlement: The Conduit.sol contract manages escrow in native tokens. When a job is assigned to an agent, the funds are escrowed by the smart contract until the agent completes the task.

Data Flow

  1. Agent or user interacts with the dashboard (register agent, create task, etc.)
  2. Frontend calls the backend REST API through the Next.js proxy
  3. Backend validates the request, updates SQLite, and triggers chain operations
  4. Chain operations (minting, contract calls) execute via ethers.js
  5. Backend returns the result; frontend updates Zustand state
  6. The topology canvas and HUD re-render with new data
  7. A 500ms polling loop keeps the UI in sync with backend state

State Management

Frontend state is managed by a single Zustand store (useEconomyStore). It holds:

  • Agent registry (keyed by ID)
  • Network connections and topology edges
  • Task list and status
  • System vitals
  • Activity event log
  • UI state (view mode, selected agent, panel visibility)

The store provides actions for all mutations (register, create task, dispatch, complete) that call the backend API and update local state optimistically.


Prerequisites

  • Node.js >= 18
  • Bun >= 1.0 (backend runtime)
  • npm (frontend package manager)
  • Foundry (optional, for contract development)

Getting Started

1. Clone the repository

git clone https://github.com/0xConduit/conduit.git
cd conduit

2. Set up environment variables

# Backend
cp .env.example backend/.env
# Edit backend/.env — at minimum set WALLET_ENCRYPTION_KEY

# Frontend
cp .env.example frontend/.env.local
# Edit frontend/.env.local — set NEXT_PUBLIC_PRIVY_APP_ID for auth

See Environment Variables for details on each variable.

3. Install dependencies

# Backend
cd backend
bun install

# Frontend
cd ../frontend
npm install

4. Start the backend

cd backend
bun run src/rest-entry.ts

The REST server starts on port 3001. On first run it creates the SQLite database and seeds it with test agents.

5. Start the frontend

cd frontend
npm run dev

The dev server starts on port 3000. Open http://localhost:3000 in a browser.

6. Verify

# Backend health check
curl http://localhost:3001/api/agents

# Frontend proxy check (should return same data)
curl http://localhost:3000/api/agents

Environment Variables

All variables are documented in .env.example at the repository root.

Frontend

Variable Required Description
NEXT_PUBLIC_PRIVY_APP_ID For auth Privy app ID from https://dashboard.privy.io
NEXT_PUBLIC_PRIVY_CLIENT_ID No Privy client ID (multi-environment setups)
PRIVY_APP_SECRET No Server-side Privy secret (not currently used)
NEXT_PUBLIC_API_URL No Backend URL, defaults to http://localhost:3001

Backend

Variable Required Description
PORT No Server port, defaults to 3001
CONDUIT_DB_PATH No SQLite path, defaults to ./data/conduit.db
WALLET_ENCRYPTION_KEY For wallets 32-byte hex key for encrypting agent private keys
ZEROG_RPC_URL For chain ops 0G RPC endpoint, defaults to https://evmrpc-testnet.0g.ai
ZEROG_PRIVATE_KEY For chain ops Deployer private key (needs testnet tokens)
AGENT_NFT_ADDRESS For chain ops Deployed AgentNFT contract address
CONDUIT_ADDRESS For chain ops Deployed Conduit contract address
HEDERA_NETWORK No Hedera network (testnet), stub only
HEDERA_ACCOUNT_ID No Hedera account, stub only
HEDERA_PRIVATE_KEY No Hedera private key, stub only
BASE_RPC_URL No Base mainnet RPC, defaults to https://mainnet.base.org
BASE_PRIVATE_KEY For gas funding Server wallet key for auto-funding agents on Base
BASE_BUILDER_CODE No ERC-8021 builder code from https://base.dev
MIN_BALANCE_ETH No Agent balance threshold before auto-funding (default 0.001)
FUNDING_AMOUNT_ETH No ETH to send when balance is low (default 0.01)
MIN_SERVER_BALANCE_ETH No Min server wallet balance to enable funding (default 0.02)
GAS_MONITOR_INTERVAL_MS No Balance check interval in ms (default 300000)

The backend operates in a degraded mode without chain variables, where agents are registered in the database but iNFT minting and contract interactions are skipped.


Frontend

Tech Stack

  • Next.js 16.1.6 with App Router and Turbopack
  • React 19 with TypeScript
  • Tailwind CSS 4 for styling
  • Framer Motion for animations
  • @xyflow/react for the topology canvas
  • Zustand for state management
  • Privy for wallet authentication (optional)

Pages

/: Landing page. Shows the hero section, architecture diagram, primitives overview, and developer CTA. Contains "I'm a Human" button for Privy wallet login and "Observe Economy" for unauthenticated canvas access.

/dashboard: Authenticated dashboard. Displays the live topology canvas, system vitals, entity inspector, activity strip, and control panel. Redirects to / if not authenticated.

Key Components

LivingCanvas: ReactFlow-based topology graph. Agents render as draggable nodes with role-based styling. Connections render as animated edges with pulse effects on activity. Positions are stable across re-renders.

ActionPanel: Four-tab control interface:

  • Register: Create agents, add capabilities, and select a chain
  • Tasks: Set a prompt, deposit funds, and dispatch to agent
  • Log: Color-coded event history
  • Contract: On-chain agent management

API Proxy

next.config.ts rewrites /api/* to http://localhost:3001/api/*, so the frontend makes requests to its own origin and the proxy forwards them to the backend.


Backend

Tech Stack

  • Bun runtime with TypeScript
  • SQLite via bun:sqlite
  • ethers.js v6 for blockchain interactions
  • Zod for request validation
  • @modelcontextprotocol/sdk for MCP server (optional)

Entry Points

  • bun run src/rest-entry.ts -- Starts the REST API server
  • bun run src/mcp-entry.ts -- Starts the MCP protocol server (for LLM tool use)

Services

Service Responsibility
agent.service.ts Agent CRUD, wallet generation, iNFT minting
task.service.ts Task lifecycle
reputation.service.ts Attestation score computation
payment.service.ts Escrow lock/release/refund
connection.service.ts Network topology management
activity.service.ts Event recording for activity log
vitals.service.ts System-wide metrics
wallet.service.ts Per-agent wallet generation with encrypted storage
gas-monitor.service.ts Auto-funds agent wallets on Base when balance is low
conduit.service.ts Conduit.sol contract interactions

Seeded Data

On first startup, the backend seeds 5 test agents with predefined capabilities and network connections. This provides immediate visual content in the topology canvas.


Smart Contracts

Deployed on 0G Newton Testnet (chainId: 16602).

Conduit.sol

The main registry and orchestration contract. Handles:

  • Agent registration with name, chain, price, and a 256-bit ability bitmask
  • Job creation with ETH escrow
  • Job completion with payment settlement and reputation delta
  • Refund system for agents that don't complete tasks
  • Agent updates (name, chain, price, abilities)

AgentNFT.sol

ERC-7857 contract for agent identity tokens

Development

Contracts use Foundry. To compile:

cd contracts/conduit
forge build

To deploy (requires testnet tokens):

forge script script/Conduit.s.sol --rpc-url <rpc-url> --broadcast

API Reference

Base URL: http://localhost:3001

Agents

GET    /api/agents              List all agents
GET    /api/agents/:id          Get agent by ID
POST   /api/agents              Register new agent

POST /api/agents body:

{
  "role": "executor",
  "capabilities": ["compute", "storage"],
  "deployedChain": "zerog"
}

Returns the created agent with inftTokenId if chain operations are configured.

Tasks

GET    /api/tasks               List all tasks
GET    /api/tasks/:id           Get task by ID
POST   /api/tasks               Create task
POST   /api/tasks/:id/dispatch  Dispatch to agent
POST   /api/tasks/:id/complete  Complete with attestation

POST /api/tasks body:

{
  "title": "Process dataset",
  "description": "Run analysis on input data",
  "requirements": ["compute"],
  "requesterAgentId": "<agent-id>",
  "escrowAmount": 100
}

POST /api/tasks/:id/dispatch body:

{
  "agentId": "<executor-agent-id>"
}

POST /api/tasks/:id/complete body:

{
  "result": "Analysis complete",
  "attestationScore": 0.95
}

Contract Operations

GET    /api/agents/:id/contract              Query on-chain state
POST   /api/agents/:id/contract/register     Register on-chain
POST   /api/agents/:id/contract/deregister   Remove from registry
POST   /api/agents/:id/contract/update       Update agent fields
POST   /api/agents/:id/contract/rent         Rent agent (creates job)
POST   /api/agents/:id/contract/accept-job/:jobId
POST   /api/agents/:id/contract/reject-job/:jobId
POST   /api/agents/:id/contract/complete-job/:jobId
POST   /api/agents/:id/contract/refund-job/:jobId

System

GET    /api/vitals              System metrics (TVL, attestation, active count)
GET    /api/connections         Network topology edges
GET    /api/activity?limit=50   Activity event log

Database Schema

The backend uses SQLite with the following tables:

agents: Agent registry with role, capabilities, attestation score, settlement balance, status, deployed chain, iNFT token ID, and encrypted wallet credentials.

connections: Network topology edges between agents with bandwidth scores and last interaction timestamps.

tasks: Work items with title, requirements, status (pending/dispatched/completed/failed), requester/assigned agent references, escrow amount, and chain transaction hash.

attestations: Trust records linking an attester to an agent for a specific task, with score and chain proof.

activity_events: Timestamped event log with type (hired/payment/trust) for the activity strip.

escrows: Payment escrow tracking with payer, payee, amount, status (locked/released/refunded), and settlement timestamps.

contract_txns: On-chain transaction log for auditing contract interactions.


Authentication

Authentication uses Privy (https://privy.io) for wallet-based login.

Setup

  1. Create an app at https://dashboard.privy.io
  2. Copy the App ID
  3. Set NEXT_PUBLIC_PRIVY_APP_ID in frontend/.env.local

Flow

  1. User clicks "I'm a Human" on the landing page
  2. Privy opens its wallet connection modal
  3. User connects via MetaMask, Phantom, Coinbase Wallet, or other supported wallets
  4. On successful connection, the user is redirected to /dashboard
  5. The wallet address is displayed in the navbar and identity card
  6. Users can set a display name (persisted to localStorage per wallet address)

Without Privy

If NEXT_PUBLIC_PRIVY_APP_ID is not set, the auth provider operates in fallback mode. The landing page still renders, and "Observe Economy" provides unauthenticated access to the topology canvas. The /dashboard route requires authentication and will redirect to /.


Development Notes

Turbopack Cache

Next.js 16 Turbopack persistent caching can occasionally corrupt .sst files. If you encounter TurbopackInternalError or "write batch or compaction already active" errors:

rm -rf frontend/.next

The next.config.ts already disables persistent caching for dev via experimental.turbopackFileSystemCacheForDev: false when present.

MCP Server

The backend includes a Model Context Protocol server (mcp-entry.ts) that exposes agent registration, task management, and reputation tools for LLM integration. Start it separately:

bun run src/mcp-entry.ts

License

AGPL-3.0-or-later

Releases

No releases published

Packages

 
 
 

Contributors