NormCode — concept-based normative planning and agent execution engine
Project description
NormCode: Structured AI Planning That You Can Audit
NormCode is a language for building multi-step AI workflows where you can see exactly what each step receives and produces—no hidden context, no debugging in the dark.
From Chat to Workflows
Single prompts are easy
You: "Summarize this document about Q3 earnings"
AI: [reads document, produces summary]
This works well for one-shot tasks.
Multi-step tasks get trickier
For more complex work, you might chain several steps:
Step 1: "Extract all financial figures from this document"
Step 2: "Cross-reference these figures with our database"
Step 3: "Flag any discrepancies"
Step 4: "Generate an executive summary"
This is a workflow—and it can get messy.
What can go wrong
By Step 4, your AI might be juggling:
- The entire original document (50+ pages)
- All extracted figures (hundreds of numbers)
- Raw database query results
- Notes from earlier steps
Sometimes the AI confuses a number from page 47 with a database entry, or references something that doesn't exist. When things go wrong, it's hard to tell which input caused the issue.
Some people call this "debugging in the dark."
How NormCode helps
In NormCode, each step only sees what you explicitly pass to it:
<- executive summary
<= generate summary from flagged items
<- discrepancy flags
<= check for mismatches
<- extracted figures
<= extract financial data
<- raw document
<- database results
Reading bottom-up:
- The extraction step sees only the
raw document - The mismatch check sees only
extracted figures+database results - The summary step sees only
discrepancy flags
If something goes wrong at a step, you can see exactly what that step received.
Bigger Picture: The Alignment Stack
NormCode fits into a three-layer approach for building AI systems that stay aligned with what users actually want:
flowchart TB
A["🧭 NormCode<br/>Authority Layer<br/>Semi-formal contracts<br/>between humans and AI"]
B["🛠 Shared Workspace<br/>Execution Layer<br/>Data, tools, and<br/>task constraints"]
C["🧠 Foundation Models<br/>Understanding Layer<br/>General-purpose reasoning<br/>and generation"]
A --> B --> C
By making data flow and steps explicit, NormCode helps users stay in control of what their AI agents are doing.
Key Ideas
Data isolation
<- risk assessment
<= evaluate legal exposure based on the extracted clauses
<- relevant clauses
<= extract clauses related to liability
<- full contract
Here, the risk assessment step only sees the extracted clauses—not the full contract. This keeps things focused and easier to audit.
Semantic vs. syntactic steps
| Type | LLM? | Cost | Determinism | Examples |
|---|---|---|---|---|
| Semantic | ✅ Yes | Tokens | Non-deterministic | Reasoning, generating, analyzing |
| Syntactic | ❌ No | Free | 100% Deterministic | Collecting, selecting, routing |
In a typical plan, many steps are just data routing—no LLM needed. Only the "thinking" steps cost tokens.
Three Principles of Design
| Property | What it means |
|---|---|
| Automatable | AI can directly derive plan from your natural language instructions |
| Executable | The AI can follow the plan reliably |
| Accountable | You can understand what each step does for tracing |
The Ecosystem
graph TD
A["Natural Language Task"] --> B["Compiler"]
B --> C["NormCode Plan (.ncd)"]
C <--> D["Canvas App (Visual Debugger)"]
C --> E["Orchestrator"]
E --> F["Execution"]
F --> G["🧠 Foundation Models"]
F --> H["⚙️ Tools & Data"]
F --> I["Final Result + Audit Trail"]
Main components
| Component | What it does |
|---|---|
infra/ |
The execution engine (Orchestrator, Blackboard, Agent Sequences) |
canvas_app/ |
Visual debugger with graph view, breakpoints, and real-time execution |
cli_orchestrator.py |
Command-line tool for running orchestrations |
documentation/ |
Guides and reference docs |
Quick Start
1. Installation
git clone https://github.com/your-username/normCode.git
cd normCode
pip install -e .
2. Launch the Canvas App (Recommended)
The Canvas App is a visual debugger for executing and inspecting NormCode plans:
python launch_canvas.py
This automatically:
- Checks and installs Python dependencies (FastAPI, uvicorn, etc.)
- Checks and installs Node.js dependencies (React, Vite, etc.)
- Starts backend (port 8000) and frontend (port 5173)
Options:
python launch_canvas.py --prod # Production mode (no auto-reload)
python launch_canvas.py --skip-deps # Skip dependency checks (faster startup)
python launch_canvas.py --help # Show all options
Prerequisites: Python 3.11+, Node.js 18+
3. Run from Command Line
For headless execution, use the CLI orchestrator:
# Start a new run
python cli_orchestrator.py run --concepts path/to/concepts.json --inferences path/to/inferences.json
# Resume from checkpoint
python cli_orchestrator.py resume --run-id <UUID>
# Fork from a past state
python cli_orchestrator.py fork --from-run <UUID> --concepts new_concepts.json
# List all runs
python cli_orchestrator.py list-runs
4. Run a Basic Example
See NormCode in action with the base-X addition algorithm (achieves 100% accuracy on arbitrary-length inputs):
python infra/examples/add_examples/ex_add_complete.py
How It Works
A Simple Plan
<- document summary
<= summarize this text
<- clean text
<= extract main content, removing headers
<- raw document
Read bottom-up:
- Start with
raw document - Run
extract main content...→ producesclean text - Run
summarize this text→ producesdocument summary
Key insight: The summarization step literally cannot see the raw document.
The Compilation Pipeline
Natural Language → .ncds (draft) → .ncd (formal) → .concept.json + .inference.json → Execution
| Phase | Output | Purpose |
|---|---|---|
| Derivation | .ncds |
Extract structure from natural language |
| Formalization | .ncd |
Add flow indices, sequence types, bindings |
| Post-Formalization | .ncd (enriched) |
Add paradigms, resources, axis annotations |
| Activation | JSON repositories | Generate executable format for orchestrator |
Execution Model
The Orchestrator runs plans with:
- Dependency-driven scheduling — inferences run only when inputs are ready
- SQLite checkpointing — pause, resume, or fork from any cycle
- Full state tracking — inspect what each step saw and produced
When to Use NormCode
| Scenario | Use NormCode? | Rationale |
|---|---|---|
| Multi-step workflow (5+ LLM calls) | ✅ Yes | Isolation and debuggability pay off |
| Auditable AI (legal, medical, finance) | ✅ Yes | You must prove what each step saw |
| Long-running, resumable workflows | ✅ Yes | Built-in checkpointing |
| Quick prototype (1-2 LLM calls) | ❌ No | Overhead exceeds benefit |
| Simple Q&A chatbot | ❌ No | Just prompt the model directly |
Sweet spot: Complex, multi-step workflows where you need to know exactly what happened at each step—and where a failure at step 7 shouldn't corrupt reasoning at step 12.
Project Structure
normCode/
├── infra/ # Core execution engine
│ ├── _agent/ # Agent framework and sequences
│ ├── _orchest/ # Orchestrator and blackboard
│ ├── _states/ # Reference system and tensors
│ └── examples/ # Working examples
├── canvas_app/ # Visual debugger (React + FastAPI)
│ ├── frontend/ # React Flow graph visualization
│ └── backend/ # Execution controller API
├── documentation/ # Comprehensive documentation
│ ├── current/ # Latest guides
│ └── paper/ # Academic paper draft
├── cli_orchestrator.py # Command-line interface
├── launch_canvas.py # One-command Canvas App launcher
└── settings.yaml # LLM API configuration
Configuration
Create settings.yaml in the project root (see canvas_app/settings.yaml.example):
llm:
provider: openai # or: anthropic, dashscope
api_key: your-api-key-here
model: gpt-4o # or: claude-3-opus, qwen-plus
Documentation
| Guide | Description |
|---|---|
| Overview | What NormCode is and why it exists |
| NCD Format | The formal syntax reference |
| Execution | How plans run at runtime |
| Compilation | The transformation pipeline |
| Canvas App | Visual debugger guide |
Research
NormCode is described in the paper:
NormCode: A Semi-Formal Language for Context-Isolated AI Planning
Multi-step workflows that chain LLM calls suffer from context pollution. NormCode enforces explicit data isolation as a language-level constraint, making AI workflows auditable by construction.
See Arxiv for the full draft.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file normcode-1.3.8a0.tar.gz.
File metadata
- Download URL: normcode-1.3.8a0.tar.gz
- Upload date:
- Size: 436.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc5daf6f2e8aba2d9aa3d3ea9d75147eef3fa30f0807f1182620aa59c0da733a
|
|
| MD5 |
e19e3b19fb9e13eb4e3ec965d07f52d5
|
|
| BLAKE2b-256 |
927c35d9eb01b4e08f6be6e92dd857d76dab431bcd045e977df30b716dabcd8f
|
File details
Details for the file normcode-1.3.8a0-py3-none-any.whl.
File metadata
- Download URL: normcode-1.3.8a0-py3-none-any.whl
- Upload date:
- Size: 604.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b664e7462291cf259997d11bec909716c64dcb46fba9470764a552e773018c9e
|
|
| MD5 |
451249f3333301668cfd73857d9d83e2
|
|
| BLAKE2b-256 |
67e59328f0d91ade6c44075ae1190644680d8b9cbf3992baaef967ebde1685fa
|