Self-improving DeFi strategy agent with on-chain provable reasoning, Trust layer for Keeperhub
StrategyForge is the trust layer for KeeperHub's strategy marketplace — a self-improving DeFi agent that doesn't just generate workflows, but proves why it generated them, proves they worked, and proves each new version learned from the last one's failures.
Here's the problem: KeeperHub already lets anyone create, publish, and sell DeFi automation workflows. But there's zero trust infrastructure. If someone publishes a "High Yield USDC Strategy," you have no way to verify whether the reasoning behind it was sound, whether it's ever been executed successfully, or whether version 3 is actually smarter than version 1.
StrategyForge answers all three questions with on-chain proof:
Verifiable Reasoning. Every strategy is generated through a 3-step adversarial LLM pipeline: a Researcher analyzes market conditions, a Strategist designs 2-3 candidate workflow graphs, and a Critic adversarially attacks all candidates and selects the best one. Each step carries an OpenRouter attestation ID — cryptographic proof that the reasoning actually happened and wasn't fabricated. The full evidence bundle (inputs, outputs, attestation IDs) is stored in MongoDB for any auditor to inspect.
On-Chain Reputation. We deployed two custom smart contracts on 0G Chain (Galileo Testnet) — both source-verified on the block explorer. The AgentRegistry assigns each strategy family a unique on-chain INFT identity (like a DeFi agent's passport). The ReputationLedger records execution outcomes after every run — success rate in basis points, linked to the MongoDB evidence bundle. Anyone can query these contracts to verify a strategy's track record without trusting the publisher.
Evolving Memory. When a strategy executes and the outcome is suboptimal, StrategyForge doesn't just retry — it evolves. The system loads the failure reason, feeds it into the Researcher as a hard constraint (priorLessons), reruns the full pipeline, and creates a new version. Each version is a separate immutable document linked by familyId — like git commits for DeFi intelligence. v3 demonstrably loaded v1's execution failure before generating its strategy. You can click into any version on the dashboard and see exactly which prior failures informed the current strategy.
The end result: a DeFi agent that generates KeeperHub workflows with a complete chain of evidence — from the LLM's reasoning, through deterministic compilation into KeeperHub-native workflow JSON, to the final on-chain execution receipts. Every transaction links to the 0G Galileo explorer. Every inference step has an attestation ID. Every version remembers why the last one failed.
StrategyForge is a full-stack Next.js 16 application (App Router + Turbopack) with two custom Solidity contracts deployed on 0G Chain.
The LLM Pipeline is the core engine. It's built as four sequential modules in TypeScript: Researcher → Strategist → Critic → Compiler. The first three are LLM-powered (via a unified inference layer that can swap between OpenRouter and 0G Compute Network with a single env var — USE_OG_INFERENCE=true). The Compiler is fully deterministic — it takes the Critic's selected candidate and maps it to exact KeeperHub workflow JSON (nodes + edges DAG). We built robust JSON repair and retry logic because smaller models (especially Qwen 2.5 7B on 0G Compute) frequently return truncated or malformed JSON — the repair counts open/close braces, closes dangling strings, and retries up to 3x with exponential backoff.
The On-Chain Layer uses two purpose-built Solidity contracts (~80 lines total) deployed on 0G Chain Galileo Testnet via ethers.js v6. AgentRegistry.sol assigns sequential INFT IDs to strategy families and stores metadata CIDs. ReputationLedger.sol records execution outcomes (success rate in basis points + evidence CID linking back to MongoDB). Both contracts are source-verified on the 0G block explorer via the Blockscout API. Every API route that generates, executes, or evolves a strategy calls these contracts — the on-chain writes are wired directly into the application logic, not bolted on after the fact.
KeeperHub Integration handles workflow creation and execution. When a strategy is compiled, the resulting JSON is sent to KeeperHub's API to create a workflow. Execution triggers the Turnkey wallet (KeeperHub's secure enclave) to auto-sign transactions. We poll for execution results and feed outcomes back into the ReputationLedger.
The Evolution Loop is what makes this more than a one-shot generator. The /api/strategy/[id]/evolve endpoint loads the strategy's execution history, extracts failure reasons, and pipes them into the Researcher as priorLessons — a hard constraint array that forces the LLM to avoid the exact protocols/configurations that failed. The result is a new version linked by familyId with an evidenceOfLearning field from the Critic explaining what changed and why. MongoDB stores the full version chain; 0G Chain anchors the identity and reputation.
Notable hacks: The dashboard polls 0G Chain every 12 seconds for live block height and contract stats (agent count, reputation records) via a /api/live/chain endpoint — this powers the ChainPulse component that pulses amber on every new block. We also built a backfill script that retroactively registers legacy strategies on-chain, and a contract verification script that submits source code to the Blockscout API for on-explorer verification.
Tech stack: Next.js 16, React 19, MongoDB Atlas (Mongoose), ethers.js v6, Solidity 0.8.20, Framer Motion, CSS custom properties (no Tailwind — hand-crafted dark glass design system), OpenRouter / 0G Compute Network for inference, KeeperHub API for workflow execution.

