Typed orchestration for self-improving retrieval systems.
Three methods. One feedback loop. Deploy to any edge runtime.
const loop = createLoop({ store: "supabase", embedding: "openai" }); // 1. Seed content — embeddings are generated automatically await loop.seed([{ content: "Your hook here", tribe: "founders" }]); // 2. Select the best item for this context const pick = await loop.select("growth strategies"); // 3. Later: feed back what happened await loop.ingest(pick.candidate.item.id, "instagram", { views: 12400, likes: 340, shares: 89, }); // Next select() is smarter. Every loop compounds. // If the item scored well, the breeder generates variations automatically.
Configs
createLoop() wires stores, embeddings, critics, breeders, and tuning from a single declarative config.
const loop = createLoop({ store: "memory", });
const loop = createLoop({ store: "supabase", embedding: "openai", });
const loop = createLoop({ store: "supabase", embedding: "openai", breeder: myLlmBreeder, breeding: { scoreThreshold: 0.7 }, });
const loop = createLoop({ store: "supabase", embedding: "openai", selection: { epsilon: 0.25, weights: { similarity: 0.5, scoreAvg: 0.3, exploration: 0.15, freshness: 0.05, }, }, aggregation: { decayFactor: 0.9, }, });
How it works
Every selection teaches the system. Every outcome sharpens the next pick. The loop never stops learning.
Load content variants with embeddings. Hooks, prompts, copy, templates — anything you want to optimize.
Epsilon-greedy algorithm picks the best item, weighted by similarity, past performance, exploration, and freshness.
Real-world signals flow back via webhooks. Views, clicks, shares, ratings, conversions — any metric you track.
A critic scores the content. Start with keyword heuristics. Graduate to LLM-as-judge. Compose multiple critics.
Decay-weighted aggregation updates running scores. Recent performance matters more than ancient history.
When items cross a score threshold, the breeder generates variations. New candidates enter the pool. The loop compounds and expands.
What's possible
Each is a single edge function backed by one Supabase table. What used to need a data team is now a weekend project.
Seed 50 content hooks per audience tribe. Platform webhooks feed engagement signals. The loop surfaces which hooks land and retires the ones that don't.
attention economyRegister prompt variants per task type. Measure success rate, latency, user rating. Best prompt is selected per context, automatically.
agent economyLanding page headlines, CTAs, email subjects. Track clicks and conversions. The loop converges on what converts, even with low traffic.
conversion economyPersonal recommendations for books, tools, restaurants, music. Accept/reject/rate signals shape a taste profile that sharpens over time.
discovery economySelf-curating content feeds for newsletters, communities, or learning paths. Click and read-time signals rank what surfaces next.
discovery economyProposals, outreach emails, meeting agendas. Track win/loss and completion rates. Templates evolve toward what works for each segment.
process economyPrimitives
Swap any part. The core defines contracts. Adapters implement them.
Where items and scores live. Ship with InMemoryStore for testing, SupabaseRpcStore for production. Build your own.
How text becomes vectors. OpenAIEmbedding for production, NoopEmbedding for testing. Single and batch embed.
How content is judged. HeuristicCritic uses keywords. LlmCritic uses Claude or GPT as judge. Compose with MultiSignalCritic.
Observe the loop itself. NoopTelemetry by default. Plug in OpenTelemetry, Datadog, or any tracing provider.
How the pool grows. NoopBreeder by default (static pool). Plug in an LLM breeder to generate variations from winners.
Agent-aligned
AI coding assistants can discover and use this library natively.
Machine-readable project index. Every AI assistant can understand what this library does and how to use it.
Indexed on Context7 for real-time doc retrieval. Agents get version-specific API docs injected into their context.
Full TypeScript types with JSDoc. Agents generate correct code on the first try because the type surface is explicit.
Documentation
Everything you need to go from zero to a self-improving system.
Every doc page has three modes: Vibe Coder (just code), Beginner (explain everything), and Advanced (internals & tradeoffs).