Leangetic docs
Leangetic turns your AI agent into a cheaper hybrid: it maps each model step, replaces the ones that can be deterministic code with code, and tunes the rest, then proves the result is cheaper with equal-or-better quality on your own traffic before you switch over. Your original is never modified; rollback is instant.
Introduction
Most agents call a large language model for steps that do not need one - extraction, classification, formatting, routing, validation - and resend the same context on every call. Leangetic finds those steps from your agent's real behavior, replaces the ones that are safe to make deterministic with code, and makes the remaining model calls cheaper (exact caching, prompt compaction, model routing). The result is a hybrid agent: deterministic code where it is provably safe, tuned AI everywhere else.
The guarantee that makes this usable in production:
- We never change your agent's output without proof of equivalence on your own traffic.
- Every served step falls back to your original model on any doubt.
- Your original agent is never modified, and rollback is one command.
How it works
The flow has four moves. The heavy lifting happens on our servers; proof and switch-over happen on yours.
- Listen (local, free) -
leangetic startinstalls a zero-touch listener. Your agent runs exactly as before while the engine records each model step in SHADOW (hashes only, nothing changed). - Profile (local, free) -
leangetic profileshows where your agent spends time and money: cost and latency per step, which calls repeat, and which steps fail/retry. See the waste first. - Optimize (our servers, uses credits) -
leangetic optimizesends a redacted bundle of evidence; our servers map your steps, synthesize deterministic code for the safe ones, tune the rest, and return the assembled hybrid. The transforms are imported into your local engine, disarmed. - Judge (local) -
leangetic judgeruns the hybrid against your real traffic. A code step is kept only after it reproduces the model's output on every observed call with zero mismatches; the hybrid ships only when it is cheaper with equal-or-better quality. - Switch over (local) -
leangetic promoteactivates the proven hybrid in one command;leangetic rollbackreverts instantly.
Quickstart
Install the CLI, then run four commands on one agent.
curl -fsSL https://leangetic.com/downloads/leangetic.py -o ~/.local/bin/leangetic
chmod +x ~/.local/bin/leangetic
# or: npx @leangetic-ai/cli --help
leangetic login --api-url https://api.leangetic.com --email you@example.com
leangetic start ./your-agent # listen (nothing changes); run your real workload, then:
leangetic optimize ./your-agent # our servers map + build the hybrid (uses credits)
leangetic judge # prove cheaper + equal-or-better on your traffic
leangetic promote # switch over (leangetic rollback to revert)
A non-technical user can have their own AI assistant run the whole flow through the bundled MCP server - see MCP server.
The per-call engine
The engine is a small, local library that intercepts your agent's model calls. It supports Anthropic, OpenAI, Gemini, and any OpenAI-compatible endpoint, with no change to your agent code. There are three ways to attach it, all reversible:
- Zero-touch -
leangetic startwrites a helper your interpreter loads automatically (no code edit). - One line - add
import leangetic_engine as e; e.install()to a Python agent. - Reverse proxy - run
python leangetic_proxy.pyand pointANTHROPIC_BASE_URL/OPENAI_BASE_URLat it (any language). Streaming and tool calls are relayed byte-for-byte.
In SHADOW mode (the default) the engine only
measures - it records each call to a local .leangetic/calls.jsonl
and changes nothing. In ACTIVE mode (after you
promote) it serves only the proven optimizations and falls back to
your model otherwise. Kill switch: LEANGETIC_ENGINE=off.
Optimize (the server)
optimize is where the analysis happens. You send a
redacted bundle (and, with --share-examples, redacted
input/output examples). Our servers map each step into
"deterministic-code candidate" vs "stays AI", synthesize the code for
the safe ones, and assemble the hybrid. You receive the result - the
transforms and a plain-language process-map summary - not the method.
This is the paid step and what your credits cover.
Nothing is served at this point. Every transform comes back disarmed and must earn promotion through your own SHADOW evidence (see Judge).
Judge & promote
judge decides what ships, using your own real traffic as
the arbiter:
- A synthesized code step is approved only after it reproduces your model's output on every observed call with zero mismatches and a real cost win.
- The AI-refinement wins (exact cache, prompt compaction) are measured directly and are equivalent by construction.
- If the result is not cheaper, or any step regresses, it is not promoted; a step that ever diverges stays AI.
promote arms only the approved parts and switches the
engine to ACTIVE. Every served step still falls back to your model on
any doubt; a single later mismatch demotes it. rollback
returns to SHADOW instantly. Your original agent is never touched.
What you receive
An optimize produces a pack placed beside your agent (your original is never modified), containing:
- RESULT.md - a plain-language, AI-readable summary: what changed, the honest savings (measured vs clearly-labeled estimate), the exact one-line run command, and how to roll back.
- map_summary.json - the process map: which steps became code vs stay AI, with per-step call counts and observed cost.
- transforms.json - the synthesized deterministic transforms (loaded by your engine, disarmed until proven).
- The runnable wrapper and a measurement harness for
verify --measure.
Install
curl
mkdir -p ~/.local/bin
curl -fsSL https://leangetic.com/downloads/leangetic.py -o ~/.local/bin/leangetic
chmod +x ~/.local/bin/leangetic
leangetic --help
npm
npx @leangetic-ai/cli --help
# or: npm install -g @leangetic-ai/cli
Requires Python 3.9+. The CLI uses your own model credentials (the same keys your agent already uses); Leangetic never needs its own provider account.
CLI reference
Account
leangetic login --api-url <url> --email <you> or --api-key ac_... - authenticate the CLI.
leangetic whoami - show the logged-in account and credit balance.
leangetic logout - clear the local session.
Build a hybrid
leangetic start <agent_dir> - install the zero-touch listener for each detected agent and print how to run it. Nothing is changed; data accumulates as your agent runs.
leangetic status [--all|<agent>] - measured-only listening status (calls recorded, exact-duplicate calls, observed tokens). No projections.
leangetic profile [<agent>] - free local profiler: cost + latency per step, exact-repeat rate, and which steps fail/retry, ranked by cost. Shows the waste before you spend a credit.
leangetic optimize <agent_dir> [--share-examples] [--max-credits N] - send the redacted bundle; our servers map and build the hybrid; the transforms and map summary are imported locally. Uses credits.
leangetic map [<agent>] - show the server-computed process map (code vs AI) from the latest optimize.
leangetic judge [--min-samples N] - approve the transforms proven equal to your model on every real call plus the measured cache/compaction wins; writes the verdict.
leangetic promote [--force] - switch over to the proven hybrid (arm the approved parts, go ACTIVE). Refuses without an approved verdict unless --force.
leangetic rollback - disarm everything and return to SHADOW. The original is never modified.
Packaging & verification
leangetic apply <pack> --target <dir> - place an optimized package beside your original (validated and written atomically).
leangetic verify --measure --against <orig> --package <dir> --tasks <tasks.json> - run original vs optimized on your tasks and prove better-or-equal.
leangetic artifact fetch <job_id> - re-download a paid compile artifact (recovery, e.g. after a network drop).
Credits
leangetic credits - show your balance. leangetic request-credits <amount> - request alpha credits (the operator approves).
MCP server
Leangetic ships a self-contained MCP (Model Context Protocol) server so your own AI assistant (Claude Desktop, Cursor, Codex, any MCP client) can drive the whole flow in plain language. Register it as a stdio server:
# register as an MCP stdio server in your client's config:
# command: python
# args: ["/path/to/leangetic_mcp.py"]
# (leangetic_mcp.py ships beside the CLI and needs no extra install)
It exposes leangetic_start, leangetic_status,
leangetic_map, leangetic_optimize,
leangetic_judge, leangetic_promote,
leangetic_rollback, and leangetic_whoami as
tools. Credit-spending tools (optimize) require an explicit confirm so
your AI cannot spend credits without your say-so.
Environment variables
LEANGETIC_ENGINE=off- kill switch; disables interception entirely.LEANGETIC_ENGINE_MODE=shadow|active- measure only, or serve proven optimizations.promote/rollbackset this for you.LEANGETIC_ENGINE_EXEMPLARS=on- opt in to capturing redacted input/output examples locally (needed if you later useoptimize --share-examples).LEANGETIC_ENGINE_COMPACTION=off,LEANGETIC_ENGINE_ROUTING=on- per-optimization toggles.ANTHROPIC_BASE_URL/OPENAI_BASE_URL- point at the local proxy for any-language interception.
Privacy & data
By default only hashes and aggregate metrics are recorded locally;
nothing is uploaded until optimize, and even then only a
redacted bundle (secrets stripped, credential files omitted). Real
input/output examples are sent only with --share-examples,
after a privacy preview. See the full
Security and GitHub
Privacy
pages.
Credits & alpha
Leangetic is in an assisted alpha. Listening, mapping summaries,
judge, promote, and verify --measure
are free; the optimize step (the server-side build) uses
credits. During alpha, credits are granted on request: ask in the
portal or with leangetic request-credits <amount> and
the operator approves.
FAQ
Will this change my agent's answers?
No - not without proof. A change is served only after it reproduces your model on your own traffic with zero mismatches, and every step falls back to your model on any doubt.
Do you see my code or data?
Only a redacted bundle, and only when you run optimize and approve the preview. Secrets and private files are stripped/omitted; raw keys and databases are never uploaded.
Can I undo it?
Yes, instantly: leangetic rollback returns to SHADOW. Your original agent was never modified.
Which providers and frameworks are supported?
Anthropic, OpenAI, Gemini, and any OpenAI-compatible endpoint, at the model-call layer - so LangGraph, CrewAI, AutoGen, OpenAI Agents, DSPy and others work with no adapter.
Do I need my own model key?
Your agent runs with your own credentials. The server-side synthesis uses Leangetic's own model access, so you do not need to share a key for that step.