An AI agent that optimizes your AI agents, and pays for its own compute on 0G.
Business processes are turning into AI agents, but most agents are written the obvious way: every step waits for the one before it, every call uses the biggest model, and the bill grows with every run. Synapse0g is a compiler and optimizer for AI agents that runs as a paid agent on 0G.
A developer pastes or uploads a LangGraph agent with one sample input, or picks an example agent, and gets an itemised quote: the agent's steps, the price of a model call measured on 0G, the compute the job needs, and the optimizer's fee. They pay with one wallet transaction, depositFor on 0G's own Payment Layer, straight into the optimizer's 0G compute account, with no contract of ours in between. The server checks the payment on chain and starts the job by itself.
Synapse0g traces the agent and lifts it into SIR, an effect-typed graph. Its edges are what each step really reads, and each step is labelled pure, read, write, external or irreversible. Twelve passes rewrite the graph, each only where its safety rule holds: independent steps run in parallel, pure steps are cached, unused context is dropped. Per-step model changes (hidden reasoning off, a cheaper model) are kept only if a firewall finds no task broken on held-out tasks. Irreversible steps, like placing an order, are flagged and never run.
The optimized agent then runs on the customer's input. Every model call is paid from the optimizer's own balance, through its capped 0G Router key, with 0G's request id and exact charge shown live. The customer gets back the answer, the measured cost and time, and a zip with optimized_agent.py, generated from the optimized graph by the compiler (not an LLM), beside their original code.
Spending is safe by design. Every call reserves its worst-case cost first, there are caps per job and per key, and when funds run low the job slows down or pauses, then resumes without paying twice. Measured on held-out tasks: the supplier-check agent ran 3.48× faster and 72% cheaper on 0G's bill, still 20/20 right. Changes that broke answers were blocked.
The backend is Python 3.11. The compiler lifts LangGraph StateGraphs and plain Python functions into SIR, our effect-typed intermediate representation. For LangGraph it traces each step once on a sample input and records which state keys it really reads and writes, so the edges come from data flow rather than code order. Twelve passes (parallelize, memoize, cse, downgrade, context_prune and more) each declare a precondition checked against the effect lattice, and a runtime executes the optimized graph with parallel steps, a content-addressed cache, and irreversible steps stubbed.
Every model call goes through our OpenAI-compatible proxy, which applies a per-step policy (reasoning off, routing to a cheaper model) and records tokens, latency, 0G's request id and the billed charge from the Router's x_0g_trace field. The policy is found by a search on tuning tasks and approved by a firewall: paired comparisons against an unchanged control run at the same moment, with 95% bootstrap confidence intervals, measured on held-out tasks.
0G is the payment and compute layer. Customers pay with depositFor on 0G's Payment Layer contract; we read its verified source to find the call, since the docs only show the dashboard. A payment desk matches each Deposited event to its quote by payer, amount and expiry, from the transaction receipt or a watcher scanning the chain, with an RPC fallback to dRPC because the public RPC rate-limits. Inference runs on the 0G Router (qwen3.8-flash, qwen3.7-flash) with the agent's own capped key, never the team's.
A spend guard reserves each call's worst-case cost (request bytes × input price + max tokens × output price, in 0G wei) atomically in SQLite, against the job's cap, the key's cap and 0G's admission rule (0.01 0G minimum, 80% of the vault counted). It settles at 0G's billed charge and holds uncertain charges after timeouts.
Hacky parts we're proud of: optimized agents are returned as real code by lowering the optimized SIR back into a LangGraph file, with parallel edges, cached steps, step-specific model settings and protected irreversible steps. Paused jobs replay the calls they already paid for, so they never pay twice.
The frontend is React 19, Vite, Tailwind 4, React Flow for the live SIR graphs, and a three.js landing page tuned for Apple silicon. It's deployed as one Docker service on Render, with a persistent disk for jobs and payments.

