Cohzen (`cz`) Documentation
Cohzen is a static architecture scanner, zero-egress runtime telemetry engine, and CI/CD governance suite for agentic workflows, built authoritatively for LangGraph (supporting 0.2.x through 1.2.x) under the Apache 2.0 license.
What's New in v0.3.4 & The v0.3 Release Series
The v0.3 series transforms Cohzen from an analysis tool into a complete zero-overhead local observability and CI governance engine:
- Slim `cz init` Output (v0.3.4): Streamlined onboarding displays only the detected graph topology and routing edges table, eliminating terminal clutter.
- Zero-Overhead `.pth` Startup Hook: Deprecated legacy
sitecustomize.pyinjection in favor of virtualenvcohzen_startup.pthhooks for completely non-invasive execution interception. - Full Capture Lifecycle Management: New
cz capture -- <cmd>for one-off runs,cz status,cz on,cz off, andcz deinit. - CI/CD Governance Gates:
cz audit --min-coverage <pct>and--fail-on-emptywith standardized exit codes (0, 1, 2) and PR comments via the composite GitHub Action. - Zero-Egress Local SQLite & Secret Redaction: High-performance asynchronous execution store (
.cohzen/executions.db) with automatic pattern-based secret redaction and retention pruning. - Apache 2.0 License: Officially relicensed from MIT to Apache-2.0 with Contributor Covenant and DCO sign-offs.
Statically parses Python AST to reconstruct state graphs, nodes, conditional edge routes, model invocations, tools, and checkpointer persistence. Emits terminal dashboards, Mermaid flowcharts, or canonical CohzenManifest JSON with zero runtime code execution.
Consumes AST facts to audit observability coverage. Flags uninstrumented LLM caller nodes, missing tracing decorators (@traceable, @observe), and enforces CI quality gates with --min-coverage and --fail-on-empty.
Installation & Setup
Cohzen is written in Python (compatible with Python 3.10, 3.11, and 3.12). Install it via PyPI or install from source in editable mode:
$ pip install cohzen$ git clone https://github.com/cohzenai/cohzen.git$ cd cohzen/cz$ pip install -e .
5-Minute Quickstart
You can scan architectures, record live executions, and debug individual graph nodes immediately. Navigate to your project directory and execute:
$ cz scan .Inspects Python files, builds ASTs, and renders an interactive Rich console report of graphs, nodes, conditional edges, tools, and LLM call sites.
$ cz audit .Checks package manifests, .env files, and function decorators to detect nodes and tools lacking telemetry.
$ cz initEnables transparent execution tracking in your directory. Run your workflow normally; executions and spans are stored in local SQLite (.cohzen/executions.db).
$ cz runs && cz waterfall <id>Inspect recorded executions, overall latency, and Gantt waterfall timelines detailing exact microsecond offsets of node handlers and LLM calls.
$ cz node run <node_name> --from-run <id>Replays captured state or custom JSON to execute a single node directly without compiling or running the entire graph.
cz init — Slim Project Initialization & Startup Hook
v0.3.4 UPDATEDcz init initializes Cohzen in your agent repository with a single command. In v0.3.4, cz init features a slim topology output by default, rendering discovered graph routing edges without noisy terminal logs, and installs a clean virtual environment startup hook:
Cohzen will: • create or modify .cohzen/config.toml • create or modify .cohzen/manifest.json • create or modify .cohzen/executions.db • create or modify .gitignore • create or modify .venv/lib/python3.11/site-packages/cohzen_startup.pth Graph Topology & Routing Edges ┏━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ ┃ Type ┃ Source ┃ Direction ┃ Target / Routing ┃ Location ┃ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩ │ DIRECT │ START │ ──> │ assistant │ agent_tools.py:35 │ │ CONDITIONAL │ assistant │ ─?─> │ fn: lambda state: │ agent_tools.py:36 │ │ │ │ │ 'tools' | 'finish' │ │ │ DIRECT │ tools │ ──> │ assistant │ agent_tools.py:41 │ └─────────────┴───────────┴───────────┴────────────────────┴───────────────────┘ ✔ Cohzen initialized at ./ • Manifest: .cohzen/manifest.json (1 graphs, 2 nodes, 2 tools) • Telemetry DB: .cohzen/executions.db • Startup hook: .venv/lib/python3.11/site-packages/cohzen_startup.pth • Added .cohzen/ to .gitignore Capture is enabled for eligible local LangGraph runs. One-off capture remains available: cz capture -- python app.py Then inspect recorded executions: cz runs
Statically scans all Python files in the target directory and outputs .cohzen/manifest.json with exact node handlers, routing edges, tools, and LLM call locations.
Initializes .cohzen/executions.db, a local high-performance SQLite store capturing run metadata, states, and span trees with zero network egress.
Installs cohzen_startup.pth into the virtual environment site-packages. Completely non-invasive: leaves project source code untouched and cleanly migrates legacy hooks.
Generates .cohzen/config.toml to govern capture toggles, retention pruning (max_runs, max_age_days), and regex secret redaction.
Python's standard library executes .pth files discovered in site-packages during interpreter startup. Cohzen places a guarded one-line hook that calls cz._startup.start() wrapped in a safe try/except. It cleanly wraps compiled LangGraph invocations (Pregel, CompiledStateGraph) with zero runtime dependencies if Cohzen is uninstalled.
cz capture & Lifecycle Controls (on / off / status / deinit)
v0.3.0 NEWCohzen gives you total control over when and how runtime capture runs. Whether you prefer one-off execution capture or non-destructive toggling:
$ cz capture -- python app.pyExecutes the supplied command with runtime interception active only for that specific process. No persistent startup hooks are required.
$ cz statusDisplays whether capture is enabled, startup hook file paths, telemetry DB record counts, and active secret redaction filters.
$ cz off && cz onSwitches the enabled flag in .cohzen/config.toml instantly without removing hooks or reinstalling packages.
$ cz deinit --keep-dataSafely unlinks the .pth hook, cleans legacy files, removes configuration, and optionally preserves executions.db.
cz scan — Architecture Discovery
COMMANDcz scan [PATH] reconstructs LangGraph workflows statically from Python AST without executing any runtime code or importing dependencies.
Command Options & Flags
| Flag | Type | Description |
|---|---|---|
| path | Argument (default: .) | Target directory or Python file to scan. |
| --json | Flag | Emit the official CohzenManifest v0.1.0 JSON format. |
| --mermaid | Flag | Translate graph topology into Mermaid flowchart markup. |
| -o, --output | Option [FILE] | Write manifest or diagram output to specified file path. |
| --view | Flag | Launch dark-mode interactive HTML browser visualizer. |
Terminal Output Walkthrough
Running cz scan . outputs high-signal Rich tables with exact file spans:
╭─────────────── Cohzen Architecture Scan (v0.1) ────────────────╮ │ Scanned Target: ./examples/langgraph-tools │ │ Frameworks: ✓ langgraph │ │ Files Examined: 2 total (1 Python files) │ │ Scan Duration: 1.69 ms │ │ Graphs: 1 • Nodes: 2 • Edges: 3 • Tools: 2 • Models: 1 │ ╰───────────────────────────────────────────────────────────────╯ Registered Nodes & Handlers: ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓ ┃ Node Name ┃ Handler / Location ┃ LLM Calls & Models ┃ Tools Bound ┃ ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩ │ 🤖 assistant │ assistant (app.py) │ langchain │ bound: search_docs │ │ 🤖 tools │ tool_node (app.py) │ Tool Execution │ ToolNode(search_docs│ │ │ │ │ calculate_metrics) │ └──────────────┴────────────────────┴────────────────────┴─────────────────────┘ 🛠️ Detected Tool Functions (@tool): ┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Tool Name ┃ Location ┃ Docstring / Purpose ┃ ┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ 🔧 search_docs │ agent_tools.py:8-10 │ Search internal documentation │ │ 🔧 calculate_metrics │ agent_tools.py:13-15 │ Compute aggregate score │ └──────────────────────┴──────────────────────┴────────────────────────────────┘
cz audit — Observability & CI/CD Governance Gates
v0.3.4 UPDATEDcz audit [PATH] evaluates observability instrumentation across your entire agentic codebase. It consumes the AST architectural model without executing user code and enforces strict CI/CD gate checks.
What `cz audit` Checks
Verifies that agent nodes performing LLM calls or tool execution are decorated with @traceable, @observe, or span hooks.
Cross-references .env files for critical flags like LANGCHAIN_TRACING_V2=true or LANGFUSE_PUBLIC_KEY.
Audits pyproject.toml and requirements.txt for telemetry packages (LangSmith, Langfuse, Phoenix, Traceloop, OTel).
CI/CD Quality Gate Options
| Flag | Type | Description |
|---|---|---|
| --min-coverage | Option [FLOAT] | Minimum required agent/node instrumentation percentage (0-100). Exits with code 1 if not met. Skipped with an INFO line on empty repos unless --fail-on-empty is passed. |
| --fail-on-empty | Flag | Exit with code 1 when no agent nodes are found in the scanned directory. Ensures governance checks run only on repos containing active workflows. |
| --fail-on-missing | Flag | Exit with code 1 if no telemetry packages or active environment configurations are detected. |
| --json | Flag | Output machine-readable JSON. In v0.3.4, agent_instrumentation_pct returns null for empty repos rather than a misleading 0.0 or 100.0%. |
Exit Code Specification
| Code | Status | Meaning |
|---|---|---|
| 0 | PASSED / SKIPPED | All requested checks passed, or checks skipped on an empty repository without --fail-on-empty. |
| 1 | GATE FAILED | A CI gate check failed (--min-coverage threshold unmet, --fail-on-missing triggered, or --fail-on-empty triggered on empty repo). |
| 2 | USAGE ERROR | Invalid CLI arguments or options. |
Audit Findings & Gaps Example
╭─────────────── Cohzen Observability & Telemetry Audit (v0.3) ────────────────╮ │ Scanned Target: ./examples/langgraph-tools │ │ Observability: LangSmith detected in package manifests │ │ Tracing Coverage: Nodes: 1/2 (50.0%) • Tools: 1/2 (50.0%) │ │ CI Gate Check: Required 80.0% coverage --> FAILED (50.0%) │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────── Node Instrumentation Status ───────────────────────────╮ │ Node Name │ Location │ Tracing Status │ Observability Tool │ │ 🤖 assistant │ agent_tools.py:20 │ ✖ Uninstrumented │ None │ │ 🤖 tools │ agent_tools.py:29 │ ✔ Instrumented │ LangSmith │ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────── Audit Findings & Gaps ─────────────────────────────────╮ │ │ │ ⚠ LangSmith tracing detected, but 'LANGCHAIN_TRACING_V2=true' missing in .env │ │ ⚠ Agent(s) 'assistant' perform LLM calls without @traceable or @observe │ │ ✖ CI Gate Failure: Codebase coverage 50.0% does not meet --min-coverage 80.0% │ │ │ ╰───────────────────────────────────────────────────────────────────────────────────╯
$ cz audit . --json > audit.jsoncz view — Interactive HTML Visualizer
Cohzen includes a standalone, zero-dependency browser visualizer that opens directly in your default web browser:
Generates a clean HTML/JS visualization bundle that renders Mermaid diagrams, node inspector modals, docstrings, and checkpointer metadata offline.
cz runs & cz run — Runtime Execution Telemetry
Inspect recorded runtime executions captured in SQLite. View completion statuses, overall duration, step-by-step node transitions, why reasoning tags, and granular token/tool metrics.
$ cz runsDisplays all captured runs from .cohzen/executions.db, with execution IDs, graph names, status icons (✓ completed, ✗ failed, ● running), durations, and start times.
Cohzen Executions ID Graph Status Duration Started ───────────────────────────────────────────────────────────────── 7f3b89e2 support_assistant ✓ 1.18s 14:22:10 ce2e6db9 customer_onboarding ✓ 892ms 14:20:02 a82f9104 isolated_node:planner ✓ 127ms 14:15:18
$ cz run <execution_id> [-v, --verbose] [--json]Renders the execution summary, goal/why reasons, the sequential transition flow from START to END, step durations, and aggregated LLM and tool call metrics. Pass --verbose to view untruncated payloads and error messages.
Execution 7f3b89e2
────────────────────────────
Graph support_assistant
Status ✓ completed
Duration 1.18s
Goal / Why Process user technical inquiry
START
│
▼
collect_info 310ms
why: retrieve ticket history
│
▼
ChatOpenAI.invoke 280ms
│
▼
tools 540ms
│
▼
END
LLM calls 1
Tool calls 1
Nodes 2Privacy, Secret Redaction & Run Retention
Cohzen is architected from day one for zero-trust environments. All captured telemetry remains strictly on your local machine with zero external network egress.
Both static scanning and runtime capture operate strictly offline. Rigorous privacy test suites continuously assert 0 socket calls and 0 egress bytes.
Built-in RedactionProcessor redacts OpenAI, Anthropic, Gemini, AWS, and GitHub tokens, Bearer headers, emails, and private keys before committing to disk.
Configurable in .cohzen/config.toml: automatically prunes excess runs (max_runs = 500) and expired runs (max_age_days = 30) to keep disk usage lean.
Mermaid Diagram Export
Generate native LangGraph-compatible Mermaid flowcharts directly from AST. Perfect for README documentation, architecture RFCs, and PR reviews:
flowchart TD
__start__([● START]):::sentinelNode
__end__([● END]):::sentinelNode
assistant["🤖 assistant<br/>🧠 LLM: langchain<br/>🛠️ Tools: [search_docs]"]:::instrumentedAgent
tools[["🛠️ tools (ToolNode)<br/>Tools: search_docs"]]:::toolNode
__start__ --> assistant
assistant -.->|route: tools| tools
assistant -.->|route: finish| __end__
tools --> assistantCohzenManifest v0.1.0 Specification
SPECIFICATIONThe CohzenManifest is the immutable, machine-readable contract produced by cz scan --json.
{
"version": "0.1.0",
"metadata": {
"target": ".",
"files_scanned": 14,
"files_skipped": 0,
"parse_errors": 0,
"unresolved_symbols": 0,
"dynamic_constructions": 0,
"scan_duration_ms": 1.82,
"created_at": "2024-09-19T12:00:00Z",
"warnings": []
},
"frameworks": ["langgraph"],
"graphs": [
{
"id": "graph.workflow",
"name": "workflow",
"framework": "langgraph",
"graph_class": "StateGraph",
"state_schema": "AgentState",
"source": { "file": "app.py", "line_start": 20, "line_end": 20 },
"node_ids": ["planner", "tools"],
"edges": [
{ "source": "START", "target": "planner", "edge_type": "direct" },
{ "source": "planner", "target": "tools", "edge_type": "conditional" }
],
"compilation": {
"compiled_var": "app",
"checkpointer": "MemorySaver",
"source": { "file": "app.py", "line_start": 35, "line_end": 35 }
}
}
],
"nodes": [
{
"id": "planner",
"name": "planner",
"kind": "node",
"handler": "planner_node",
"source": { "file": "app.py", "line_start": 10, "line_end": 18 },
"model_ids": ["model.openai.gpt-4o"],
"tool_ids": ["tool.search_web"],
"resolution": { "status": "resolved", "reason": null },
"classification": { "role": "agent", "confidence": "high", "evidence": ["llm_invocation", "tool_binding"] }
}
],
"tools": [
{
"id": "tool.search_web",
"name": "search_web",
"source": { "file": "tools.py", "line_start": 5, "line_end": 8 },
"docstring": "Searches the web",
"resolution": { "status": "resolved", "reason": null }
}
],
"models": [
{
"id": "model.openai.gpt-4o",
"provider": "openai",
"name": "gpt-4o",
"source": { "file": "app.py", "line_start": 12, "line_end": 12 }
}
]
}Supported Frameworks & Providers
Cohzen v0.1 features a comprehensive suite of static detectors across agent frameworks, LLM providers, and observability stacks:
1. Agent Framework: LangGraph (v0.1 Scope)
| Construct | Pattern | Detection Status |
|---|---|---|
| Graph Types | StateGraph, MessageGraph, Graph | ✔ Full Static Support |
| Nodes & Handlers | add_node(name, fn), lambdas | ✔ Full Static Support |
| Direct & Conditional Edges | add_edge, add_conditional_edges | ✔ Full Static Support |
| ToolNode | ToolNode(tools), @tool functions | ✔ Full Static Support |
| Compilation & Persistence | .compile(checkpointer=MemorySaver) | ✔ Full Static Support |
2. LLM Providers & Invocations
3. Observability Audit Detectors
CI/CD & GitHub Actions Automation
Integrate cz scan and cz audit directly into GitHub Actions with our composite action to enforce architectural governance, verify minimum telemetry coverage, and post collapsible Mermaid diagrams on pull requests:
name: Cohzen Architecture & Telemetry Gate
on: [push, pull_request]
jobs:
cohzen-audit:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run Cohzen Governance Action
uses: cohzenai/cohzen@v0.3.4
with:
min-coverage: '80'
fail-on-empty: 'true'name: Cohzen Architecture & Telemetry Gate
on: [push, pull_request]
jobs:
cohzen-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Cohzen
run: pip install cohzen
- name: Verify Architecture Graph
run: cz scan . --json -o manifest.json
- name: Audit Telemetry Gate (Min 80% coverage)
run: cz audit . --min-coverage 80 --fail-on-emptyTroubleshooting & FAQ
Q: Why does Cohzen use 100% static analysis instead of runtime imports?
Runtime imports require all heavy dependencies installed, valid credentials in .env, and can trigger unwanted side-effects (database initialization, model pings). Static AST parsing works in milliseconds in any sandbox or CI runner without credentials.
Q: What license is Cohzen distributed under?
Cohzen is released as free and open-source software under the Apache 2.0 license (Apache-2.0) with an explicit NOTICE file. All contributions adhere to the Developer Certificate of Origin (DCO).
Q: Which LangGraph versions are supported?
Cohzen v0.3.4 contains a multi-version contract verification suite tested against LangGraph 0.2.76, 1.0.10, 1.1.10, and 1.2.16. Both pre-1.0 and 1.x Pregel compiled graphs are seamlessly intercepted without dropped runs.
Q: What happens if a node handler is imported from another package?
Cohzen uses graceful degradation. External library handlers are resolved as external_import with package attribution (e.g. package="external_agent_pkg") and highlighted in analysis limitations rather than failing as errors.
Q: How do I report a new pattern or framework?
Please open an issue or pull request on the official GitHub repository at github.com/cohzenai/cohzen.