Skip to main content

Generic Workflow Conservation Engine — analyze any workflow for cost efficiency and detect waste

Project description

Conservation Guardian

A generic Workflow Conservation Engine — analyze any workflow for cost efficiency and detect waste.

Your workflow costs $12/day. Two nodes account for 78% of tokens. They both call GPT-4 for tasks GPT-4o-mini handles.

Conservation Guardian is a framework-agnostic Python library that analyzes workflow execution for cost efficiency and detects waste. It doesn't change your workflows — it tells you what to change and why. Works with any workflow engine (Dify, n8n, LangGraph, Temporal, custom DAGs, etc.).

What It Does

Budget tracking — Set hard limits on tokens per run, cost per day, and node count. Know immediately when a workflow crosses a threshold.

DAG analysis — Parse any workflow JSON and surface:

  • Redundant LLM calls (same model, same upstream, same job)
  • Dead branches (conditional paths that never execute)

Per-node profiling — Track tokens in/out, latency, and cost for every node across runs. Spot degradation before it hurts.

Waste detection — Find the expensive stuff nobody notices:

  • Overprompted nodes — 4,200 tokens in, 180 out. You're paying for context the model ignores.
  • Idle nodes — Running every time, contributing 0.1% of value.
  • Model mismatch — Using GPT-4 for classification that GPT-4o-mini handles in 12ms.

Reports — Markdown summaries you can paste into Slack, Notion, or a PR comment.

Install

pip install conservation-guardian

Quick Start

from conservation_guardian.budget import WorkflowBudget
from conservation_guardian.analyzer import WorkflowDAG
from conservation_guardian.profiler import Profiler, NodeSample
from conservation_guardian.detector import WasteDetector
from conservation_guardian.report import render_report

# 1. Load a workflow (generic — works with any engine's JSON)
dag = WorkflowDAG.from_dict(workflow_json)
print(f"{len(dag.llm_nodes())} LLM nodes, {len(dag.redundant_llm_calls())} redundant")

# 2. Profile some runs
profiler = Profiler()
profiler.record(NodeSample(
    node_id="summarizer",
    input_tokens=4200,
    output_tokens=180,
    latency_ms=820.0,
    cost_usd=0.015,
))

# 3. Detect waste
detector = WasteDetector(profiler)
findings = detector.detect()
for f in findings:
    print(f"[{f.severity}] {f.message}")
    print(f"  → {f.suggestion}")

# 4. Generate report
budget = WorkflowBudget()
report = render_report(budget=budget, dag=dag, profiler=profiler, findings=findings)
print(report)

Differences from dify-workflow-guardian

  • Framework-agnostic: No Dify-specific assumptions in the analyzer
  • Extended node types: Recognizes llm, llm-chain, chat-model, switch, conditional, and more
  • Same API: Drop-in replacement — just change the import package name

Module Structure

File Purpose
budget.py WorkflowBudget — token/cost/node limits and daily tracking
analyzer.py WorkflowDAG — parse workflow JSON, find redundancies and dead branches
profiler.py Profiler, NodeProfile, NodeSample — per-node stats and trends
detector.py WasteDetector, WasteFinding — surface actionable waste
report.py render_report() — Markdown conservation reports

Tests

python -m pytest tests/ -v

Philosophy

Conservation Guardian doesn't optimize your workflows. It tells you where the money goes and what to do about it. The fixes are yours to make — but at least you'll know where to look.

Built for SuperInstance.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conservation_guardian-0.2.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conservation_guardian-0.2.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file conservation_guardian-0.2.0.tar.gz.

File metadata

  • Download URL: conservation_guardian-0.2.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for conservation_guardian-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3d766bcd725411683c8863acc922d9d281aed46323e1d17857d5f2f021dbb7e4
MD5 687474084a73d662d71299929d76e871
BLAKE2b-256 3b0f71f5211ab9462762f8e29863c6abb81104ce19eab647e16d74926e99a5c1

See more details on using hashes here.

File details

Details for the file conservation_guardian-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for conservation_guardian-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db4061626163dee21d16880e59c3dddd7d151cd1892a2e2af2a7fb06dd29d5a4
MD5 382d0ae66a089e36078324d9e54a0779
BLAKE2b-256 c52ea882517e6d441d7563ddcdf3dd33b0f6b9c9935585d10a8648162f7709af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page