Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
GLB Size Optimizer
Agent Prompt
You are building a production feature for three.ws — a real, live x402 agent-to-agent payment platform built on Solana and Base. This is not a demo or simulation. Every call you implement makes a real on-chain payment using the platform's seed wallet.
Objective
Implement the GLB Size Optimizer autonomous pipeline that calls /api/mcp (optimize_model) as part of the x402 autonomous spend loop.
x402 Endpoint
- Route:
/api/mcp (optimize_model) - Price:
$0.001 USDC/callper call - Category: 3D Pipeline
What to Build
Identifies GLBs > 5MB and calls optimize_model to apply Draco compression and texture downscaling. Stores original and optimized versions. Measures average load time improvement across the catalog.
Implementation Requirements
Wire into the autonomous loop — add an entry for this use case in
api/_lib/x402/autonomous-registry.jswith:id,name,endpoint,price_atomic,cooldown_seconds,pipeline(e.g.,'self'),enabled(boolean), and arun()function that executes the call.Make real x402 payments — use the platform's
X402_AGENT_SOLANA_SECRET_BASE58keypair for outbound payments. Never mock the payment. If the wallet is not configured, exit gracefully with a log entry.Record everything — every call, success or failure, must be inserted into
x402_autonomous_logwith:run_id,endpoint_type='self',service_name,endpoint_url,network,amount_atomic,asset,tx_signature,response_data,duration_ms,success,error_msg,pipeline,value_extracted.Extract and store value — don't just call the endpoint; parse the response and store the useful data to the appropriate DB table. Document exactly which table and column receives the data.
Respect cooldowns — implement a cooldown check in the registry entry so this call doesn't run more than the appropriate frequency. Recommended cooldown for this use case: based on the described schedule.
Handle errors gracefully — network failures, 402 rejections, and DB errors must all be caught, logged, and not crash the loop.
Integration Points
- Autonomous loop:
api/x402-autonomous.jsruns this on its cron schedule - Registry:
api/_lib/x402/autonomous-registry.js— add your entry here - Recording: Insert to
x402_autonomous_logtable on every execution - Downstream consumer: Document which other pipeline/feature consumes the data extracted by this call
Definition of Done
- Registry entry added with correct cooldown and price
- Real x402 payment made (not mocked)
- Response data stored to appropriate DB column
- Row inserted to x402_autonomous_log on every run
- Error handling covers: wallet unconfigured, network timeout, 402 rejection, DB failure
- Passes manual test: call the run() function directly, verify log row created and data stored
Related Use Cases
See other files in agents/x402-buildout/self/ for related autonomous loop entries. Coordinate on shared DB schemas and avoid duplicate table creation.
Implementation (shipped)
- Module:
api/_lib/x402/glb-size-optimizer.js— exportsrun(ctx),projectOptimization(),pickTarget(),readCatalogOptimizationSummary(),ensureOptimizationSchema(). - Registry entry:
glb-size-optimizerinapi/_lib/x402/autonomous-registry.js—POST /api/mcp,pipeline: 'self',cooldown_s: 21_600(6h),priority: 37,run: runGlbSizeOptimizer. - Selection:
pickTarget()queriesavatarsfor the heaviest public, non-deleted GLB withsize_bytes > 5 MBnot analyzed within 14 days (LEFT JOIN glb_optimizations). One model per run — gradual catalog sweep, biggest/stalest first. - Payment: real x402 USDC via the shared
payX402()client (api/_lib/x402/pay.js) using the seed/agent keypair.optimize_modelis$0.05/call; the amount is read from the live 402 challenge, not hardcoded. Wallet/RPC unconfigured → graceful logged skip, no throw. - Value extracted → stored to
glb_optimizations: one row per model withoriginal_bytes,estimated_optimized_bytes,estimated_savings_bytes,savings_pct,load_ms_before/load_ms_after,load_improvement_pct,suggestion_ids, fullsuggestions+infoJSON,run_id,tx_signature,amount_atomic.optimize_modelreturns measured stats + advice (not a re-encoded GLB), soprojectOptimization()computes a grounded projection from the model's real vertex count and per-texture dimensions/bytes using the compression ratios the suggestions cite (Draco ~70% geometry, exact 4K→2K area downscale, KTX2 over PNG/JPEG). - Recording: a detailed
x402_autonomous_logrow (pipeline='3d',value_extracted= savings summary) is written on every call (success or failure); the loop additionally records its standard summary row from the returned outcome. - Downstream consumer:
GET /api/x402/glb-optimization-report(api/x402/glb-optimization-report.js) readsglb_optimizationsviareadCatalogOptimizationSummary()to report catalog-wide average size + load-time improvement, total bytes shed, and remaining heavy-GLB backlog. Per-model "save ~N%" hints feed the avatar gallery. - Tests:
tests/x402-glb-size-optimizer.test.js— projection math (heavy/already-compressed/empty/floor) + registry wiring.