OpenFlare Agents Quick Start
Build and deploy stateful, Web3-connected autonomous AI agents on Cloudflare Workers edge infrastructure in under 5 minutes.
1. Install OpenFlare CLI
Run the official initialization command to scaffold a new agent project:
# Install SDK directly from GitHub Repository: npm install github:OpenFlareStudio/agents # Or clone and build from source: git clone https://github.com/OpenFlareStudio/agents.git cd agents npm install && npm run build
2. Configure Environment & Cloudflare Bindings
Open wrangler.toml and configure your Cloudflare Workers AI and D1 Database bindings:
name = "my-web3-agent" main = "src/index.ts" compatibility_date = "2026-07-31" [ai] binding = "AI" [[d1_databases]] binding = "DB" database_name = "my-d1-db" database_id = "YOUR_D1_DATABASE_ID"
3. Create Your First Agent Class
Create src/agent.ts extending the core Agent class:
import { Agent, type Connection, type WSMessage, type AgentEnv } from "@OpenFlareStudio/agents"; export class Web3Agent extends Agent { constructor(env: AgentEnv) { super(env); } // 1. Triggered on connection establishment async onConnect(connection: Connection): Promise<void> { connection.send(JSON.stringify({ type: "ready", status: "Connected to OpenFlare Studio Edge" })); } // 2. Triggered on incoming message or tool command async onMessage(connection: Connection, message: WSMessage): Promise<void> { const data = typeof message === "string" ? JSON.parse(message) : message; if (data.action === "audit_evm") { await this.setState({ last_contract: data.contract }); const currentState = await this.getState(); const result = await this.env.AI.run("@cf/meta/llama-3.2-3b-instruct", { prompt: `Audit Robinhood EVM contract: ${data.contract}` }); connection.send(JSON.stringify({ status: "success", state: currentState, result })); } } // 3. Triggered when client disconnects async onClose(connection: Connection): Promise<void> { console.log("Client disconnected:", connection.id); } }
Overview & Architecture
OpenFlare Studio is built on Cloudflare Workers AI edge runtime, providing a unified developer environment for Web3 and Model Context Protocol (MCP) agents.
Robinhood EVM Chain
Native EVM smart contract compilation, static security auditing via Blockscout API, and Web3 RPC execution.
Solana Anchor & Pinocchio
Live Anchor & Pinocchio Rust smart contract autofixer complying strictly with solana.com/docs standards.
Cloudflare One MCP
Centralized Model Context Protocol server portal with 5x token savings (minimize_tools) and Workers codemode.
Autonomous Agent Runtime
The high-tech 3-column architecture flow mapping incoming channels, agent harness, SDK runtime, tools, and observability logging.
Agent
OpenFlare Ecosystem Mind Map
Interactive tree branch mind map visualising connections between OpenFlare AI Studio, Web3 RPCs, MCP Portals, and Frontier AI Models.
Prerequisites
- Node.js: v18.0.0 or higher.
- Wrangler CLI: Installed globally or via local project dependency.
- Web3 Wallet: MetaMask / Robinhood Wallet for EVM, Phantom / Solflare for Solana.
- Cloudflare Account: For Workers AI, D1 Database, and Pages deployment.
Agent Class Lifecycle
The Agent class is the foundational building block of OpenFlare Studio. It manages connection events, WebSocket state, and tool orchestration.
import { Agent, type Connection, type WSMessage } from "@OpenFlareStudio/agents"; export class CustomAgent extends Agent { // 1. Triggered when client establishes WebSocket / Session connection async onConnect(connection: Connection) { console.log("Client connected:", connection.id); } // 2. Triggered when user or subagent sends a message/tool command async onMessage(connection: Connection, message: WSMessage) { console.log("Received payload:", message); } // 3. Triggered when client disconnects async onClose(connection: Connection) { console.log("Client closed connection:", connection.id); } }
State & Durable Storage
Agents maintain durable identity and session state backed by Cloudflare D1 Database and KV storage.
WebSockets & Live Fibers
Agents communicate in real-time using duplex WebSockets and background execution fibers.
Cloudflare One MCP Server Portals
OpenFlare Studio complies strictly with the official Cloudflare One Access Controls MCP Specification.
Context Optimization Modes
Primary MCP Portal: https://app.openflare.fun/api/mcp Minimize Tools Mode: https://app.openflare.fun/api/mcp?optimize_context=minimize_tools Search & Execute: https://app.openflare.fun/api/mcp?optimize_context=search_and_execute Workers Code Mode: https://app.openflare.fun/api/mcp?codemode=search_and_execute
Connected Upstream Tools
- Robinhood EVM RPC:
https://rpc.mainnet.chain.robinhood.com - Robinhood Blockscout Explorer:
https://robinhoodchain.blockscout.com - Solana Official MCP Server:
https://mcp.solana.com/mcp - Cloudflare D1 Database:
https://app.openflare.fun/api/mcp/d1
Robinhood EVM Chain (Chain ID 4663)
Native EVM smart contract compilation, static security auditing via Blockscout API, and automated Web3 RPC executions on Chain ID 4663.
Solana Anchor & Pinocchio Program Autofixer
The built-in Solana MCP tool automatically scans Rust source code for Anchor and Pinocchio smart contracts, fixing zero-copy account layouts and lifetime bounds.
Strict User Account Storage Isolation
All user data, chat sessions, API vault keys, custom skills, and MCP portals are strictly isolated per user account ID:
cyberterm_history_<userId> cyberterm_saved_sessions_<userId> cyberterm_user_settings_<userId> cyberterm_custom_skills_<userId> cyberterm_custom_mcp_portals_<userId>
API Keys & Vault Security
Store custom Gemini, OpenAI, Groq, and Anthropic Claude API keys securely inside your account's isolated API Vault.
HTTP REST API Reference
Invoke OpenFlare Studio AI programmatically using HTTP POST requests:
curl -X POST "https://app.openflare.fun/api/chat" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-3-5-sonnet", "messages": [ { "role": "user", "content": "Compile liquidity contract on Robinhood EVM Chain 4663" } ] }'