A TypeScript engine for cyclic LLM agent workflows with durable execution and cross-run memory.
π Documentation Β Β·Β π Compound Learning Benchmark Β Β·Β π§ͺ Examples Β Β·Β π Issues
cycgraph is a TypeScript orchestration engine for cyclic LLM agent workflows β loops, conditional routing, parallel fan-out, and nested subgraphs are native operations. Runs are durable (event-sourced replay, atomic state snapshots) and bounded by production-safety primitives: per-node budgets, zero-trust state slicing, taint tracking, and human-in-the-loop gates. Optional cross-run memory lets a reflection node distill lessons from one run that later runs retrieve automatically.
First-class node/graph configuration for running agents with guardrails, not middleware:
- Per-node budgets β
budget: { max_tokens, max_cost_usd }on every node. A runaway agent can't drain the workflow. - Zero-trust state slicing β
read_keys/write_keysdefault to[]; every node sees only what it declares. The engine rejects undeclared writes. - Taint tracking β every string from an external MCP tool is flagged in an append-only registry and propagates through derived values; strict mode rejects tainted data in routing conditions.
- Fact sanitization β a
factSanitizerhook screens every reflection fact before it persists (PII redaction, policy filtering); fails closed by default. - Eval-gated retention (verified lessons) β lessons enter on trial and are kept only if runs that used them verifiably scored better; harmful ones are evicted on outcome evidence alone. In the adversarial demo, three deliberately poisoned lessons cratered a run and the gate evicted all three two runs later β no human touched the store.
- Human-in-the-loop gates β pause for approval and resume hours later from the exact checkpoint, surviving process restarts.
- MCP server registry β stdio transports restricted to an allowlist, http/sse URLs SSRF-guarded, schemas re-validated on every read/write.
Each pattern is a node type. Declarative, composable, and traced through OpenTelemetry.
| Pattern | Use it when |
|---|---|
| Reflection | Distill run output into atomic facts that future runs retrieve |
| Evolution (DGM) | Generate N candidates per generation, score fitness, breed the winners |
| Supervisor | An LLM decides which specialist worker should run next, iteratively |
| Swarm | Peer agents hand off work to each other based on competence |
| Map-Reduce | Fan out an array of items to parallel workers, then merge |
| Self-Annealing | Iteratively refine a single output, dropping temperature each pass |
| Human-in-the-Loop | Pause for a human reviewer; resume hours later from the exact checkpoint |
Plus deterministic primitives: verifier (LLM-judge / filtrex expression / JSONPath assertion), voting (consensus across N voter agents), subgraph (nested workflows with isolated state).
- Cyclic graph engine β loops, retries, conditional routing via filtrex, nested subgraphs, parallel fan-out/fan-in. 12 node types β see the Nodes reference.
- Durable execution β event-sourced replay, atomic state snapshots, saga compensation, auto-compaction.
- Production-safety primitives β per-node
budget,factSanitizerfor PII redaction, taint tracking, zero-trustread_keys/write_keys, prompt-injection guards. - Distributed execution β
WorkflowWorker+ durable job queue for multi-process deployments, with crash recovery and run fencing (a reclaimed worker can't clobber the new owner). - Streaming β
stream()async generator with real-time token deltas, tool-call events, and typed lifecycle events. - MCP tools β built-in default servers (web search, fetch), tool manifest caching, per-tool circuit breakers.
- Observability β 17 lifecycle events, OpenTelemetry spans, Prometheus metrics, per-agent + per-workflow token/cost tracking.
- Cross-run memory β
reflectionnode distills run output into atomic facts; future runs retrieve them viamemory_queryon any agent node. Backed by a temporal knowledge graph in@cycgraph/memory.
In your project:
npm install @cycgraph/orchestratorTry a runnable example first (no project needed):
git clone https://github.com/wmcmahan/cycgraph.git && cd cycgraph && npm install
ANTHROPIC_API_KEY=sk-ant-... npx tsx packages/orchestrator/examples/research-and-write/research-and-write.tsSee the Quick Start guide for a complete walkthrough. The examples/ directory has runnable scripts for every built-in pattern plus infrastructure setups (Postgres, Ollama, MCP) β the table below points at the most commonly searched-for ones.
- Proof the learning loop works (with charts) β
compound-learning-benchmark - A research agent that learns over runs β
learning-research-agent - Multi-specialist routing β
supervisor-routing - Quality loop until score β₯ N β
eval-loop - Parallel research workers + merge β
map-reduce - Verify-and-fix with deterministic gates β
verifier-fix-loop - Voting / consensus across N agents β
voting - Evolutionary candidate breeding β
evolution - Pause for human review + resume β
human-in-the-loop - MCP tools (web search, fetch) β
mcp-integration - Local Ollama models β
ollama-local - Postgres durable execution β
postgres-persistence
| Package | What it does |
|---|---|
@cycgraph/orchestrator |
Core graph engine. Zero infrastructure dependencies. |
@cycgraph/memory |
Temporal knowledge graph + xMemory-inspired hierarchical retrieval (messages β episodes β facts β themes). |
@cycgraph/context-engine |
Optional prompt compression pipeline β strips redundant facts, verbose serialisation, and stale reasoning traces from memory payloads. |
@cycgraph/orchestrator-postgres |
Postgres + pgvector adapter for durable state, event log, agent registry, and memory store. |
@cycgraph/evals |
Regression-test harness for agent workflows with deterministic + LLM-as-judge assertions. |
The full documentation site lives at flattop.io:
- Quick Start β your first workflow in 5 minutes
- Core Concepts β graphs, nodes, agents, state
- Patterns β runnable guides for each built-in pattern
- Troubleshooting β common errors, fixes, and the gotchas that fail silently
Issues and PRs welcome. See CONTRIBUTING.md for development setup, coding standards, and the architecture decisions worth knowing before opening a PR. Security disclosures go through SECURITY.md.