Skip to main content

MOL — The Cognitive Programming Language with auto-tracing pipelines

Project description

MOL — The IntraMind Programming Language

version license python tests stdlib docs intramind

The first programming language with native pipeline operators and auto-tracing — built for AI/RAG pipelines.


Why MOL Exists

Every AI pipeline today is glue code — Python scripts stitching together LangChain, LlamaIndex, vector DBs, and LLMs with no visibility into what happens between steps. MOL fixes this.

Problem How Python/JS Handle It How MOL Handles It
Pipeline Debugging Add print() everywhere, use logging libs Auto-tracing built into |> — every step timed & typed automatically
Data Flow Visibility No native pipe operator |> operator — data flows left-to-right, traced at every stage
Type Safety for AI Generic dicts, no domain types First-class types: Thought, Memory, Node, Document, Chunk, Embedding
RAG Boilerplate 50+ lines of setup code One expression: doc |> chunk(512) |> embed |> store("index")
Safety Rails Hope for the best guard assertions + access control at the language level
Portability Rewrite in each language Transpiles to Python and JavaScript from single .mol source

The Killer Feature: |> with Auto-Tracing

No other language has this combination:

Language Pipe Operator Auto-Tracing AI Domain Types RAG Built-in
Python No No No No
Elixir |> No No No
F# |> No No No
Rust No No No No
MOL |> Yes Yes Yes

Quick Start

Install

git clone <this-repo>
cd MOL
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Hello World

show "Hello from MOL!"
mol run hello.mol

Your First Pipeline

-- A full RAG ingestion pipeline in ONE expression
let doc be Document("notes.txt", "MOL is built for IntraMind pipelines.")

let index be doc |> chunk(30) |> embed |> store("my_index")

show index

Output:

  ┌─ Pipeline Trace ──────────────────────────────────────
  │ 0.  input                   ─  <Document:a3f2 "notes.txt" 39B>
  │ 1.  chunk(..)           0.1ms  → List<2 Chunks>
  │ 2.  embed               0.2ms  → List<2 Embeddings>
  │ 3.  store(..)           0.0ms  → <VectorStore:b7c1 "my_index" 2 vectors>
  └─ 3 steps · 0.3ms total ───────────────────────────
<VectorStore:b7c1 "my_index" 2 vectors>

Zero configuration. Every step timed, typed, and traced automatically.


Language Overview

Variables & Types

-- Inferred type
let name be "IntraMind"
let count be 42

-- Explicit type annotation (mismatch = compile error)
let x : Number be 10
let msg : Text be "hello"
let flag : Bool be true

-- Reassignment
set count to count + 1

Control Flow

if score > 90 then
  show "excellent"
elif score > 70 then
  show "good"
else
  show "needs work"
end

while count < 10 do
  set count to count + 1
end

for item in range(5) do
  show to_text(item)
end

Functions

define greet(name)
  return "Hello, " + name + "!"
end

show greet("Mounesh")

Comments

-- This is a comment
show "code"  -- inline comment

Pipeline Operator |>

The core of MOL. Data flows left → right through functions:

-- Single stage
"hello world" |> upper              -- "HELLO WORLD"

-- With arguments
"a,b,c" |> split(",")              -- ["a", "b", "c"]

-- Multi-stage chain (auto-traced when 3+ stages)
"  HELLO  " |> trim |> lower |> split(" ")

-- With custom functions
define double(x)
  return x * 2
end

5 |> double |> add_ten |> double    -- 40

Pipeline Definitions

Named, reusable pipelines:

pipeline preprocess(data)
  return data |> trim |> lower
end

let clean be "  RAW INPUT  " |> preprocess
show clean   -- "raw input"

Auto-Tracing

Any pipe chain with 3+ stages automatically prints a trace:

  ┌─ Pipeline Trace ──────────────────────────────────────
  │ 0.  input                   ─  Text("  HELLO  ")
  │ 1.  trim                0.0ms  → Text("HELLO")
  │ 2.  lower               0.0ms  → Text("hello")
  │ 3.  split(..)           0.0ms  → List<1 strs>
  └─ 3 steps · 0.0ms total ───────────────────────────

Disable tracing with --no-trace:

mol run program.mol --no-trace

Domain Types

Core Types (v0.1.0)

Type Purpose Constructor
Thought Cognitive unit with confidence score Thought("idea", 0.9)
Memory Persistent key-value with decay Memory("key", value)
Node Neural graph vertex with weight Node("label", 0.5)
Stream Real-time data buffer Stream("feed")

RAG Types (v0.2.0)

Type Purpose Constructor
Document Text document with source metadata Document("file.txt", "content...")
Chunk Text fragment from a document Chunk("text", 0, "source")
Embedding Vector embedding (64-dim, deterministic) Embedding("text", "model")
VectorStore In-memory vector index with similarity search Created via store()

Domain Commands

trigger "event_name"           -- Fire an event
listen "event_name" do ... end -- Listen for events
link nodeA to nodeB            -- Connect nodes
process node with 0.3          -- Activate & adjust
evolve node                    -- Next generation
access "mind_core"             -- Request resource (checked!)
sync stream                    -- Synchronize data
emit "data"                    -- Emit to stream

Guard Assertions

Inline safety checks that halt execution on failure:

guard confidence > 0.8 : "Confidence too low for production"
guard len(data) > 0 : "Empty dataset"
guard answer |> assert_not_null

RAG Pipeline (Full Example)

-- 1. Create a document
let doc be Document("kb.txt", "Machine learning enables computers to learn. Deep learning uses neural networks.")

-- 2. Ingest: chunk → embed → store (ONE expression)
doc |> chunk(50) |> embed |> store("knowledge")

-- 3. Query
let results be retrieve("What is deep learning?", "knowledge", 3)

-- 4. Synthesize answer
let answer be results |> think("answer the question")

-- 5. Validate quality
guard answer.confidence > 0.5 : "Low confidence"

show answer.content

Safety Rails

Access Control

access "mind_core"      -- ✅ Allowed
access "memory_bank"    -- ✅ Allowed
access "secret_vault"   -- 🔒 DENIED — MOLSecurityError

Default allowed: mind_core, memory_bank, node_graph, data_stream, thought_pool.

Type Enforcement

let x : Number be "hello"   -- 🚫 MOLTypeError at declaration

Standard Library (90+ functions)

Category Functions
General len, type_of, to_text, to_number, range, abs, round, sqrt, max, min, sum, print
Functional map, filter, reduce, flatten, unique, zip, enumerate, count, find, find_index, take, drop, group_by, chunk_list, every, some
Math floor, ceil, log, sin, cos, tan, pi, e, pow, clamp, lerp
Statistics mean, median, stdev, variance, percentile
Collections sort, sort_by, sort_desc, binary_search, reverse, push, pop, keys, values, contains, join, slice
Strings split, upper, lower, trim, replace, starts_with, ends_with, pad_left, pad_right, repeat, char_at, index_of, format
Hashing & Encoding hash, uuid, base64_encode, base64_decode
Random random, random_int, shuffle, sample, choice
Map Utilities merge, pick, omit
Type Checks is_null, is_number, is_text, is_list, is_map
Serialization to_json, from_json, inspect
Time clock, wait
RAG Pipeline load_text, chunk, embed, store, retrieve, cosine_sim
Cognitive think, recall, classify, summarize
Debug display, tap, assert_min, assert_not_null

CLI

mol run <file.mol>                    # Run a program
mol run <file.mol> --no-trace         # Run without pipeline tracing
mol parse <file.mol>                  # Show AST tree
mol transpile <file.mol>              # Transpile to Python
mol transpile <file.mol> -t js        # Transpile to JavaScript
mol repl                              # Interactive REPL
mol version                           # Show version

Transpilation

mol transpile pipeline.mol --target python > output.py
mol transpile pipeline.mol --target js > output.js

Pipe chains are desugared into nested function calls:

-- MOL
"hello" |> upper |> split(" ")
# Python output
split(upper("hello"), " ")
// JavaScript output
split(upper("hello"), " ")

VS Code Extension

Included in mol-vscode/. Features:

  • Syntax highlighting (TextMate grammar)
  • Auto-closing brackets and quotes
  • Code folding (if...end, define...end, pipeline...end)
  • 20+ code snippets

Install

cp -r mol-vscode/ ~/.vscode/extensions/mol-language-0.3.0
# Restart VS Code

Project Structure

MOL/
├── mol/                        # Language implementation
│   ├── __init__.py             # Package metadata (v0.3.0)
│   ├── grammar.lark            # Lark EBNF grammar specification
│   ├── parser.py               # LALR parser + AST transformer
│   ├── ast_nodes.py            # 35+ AST node dataclasses
│   ├── interpreter.py          # Visitor-pattern interpreter with auto-tracing
│   ├── types.py                # Domain types (8 types)
│   ├── stdlib.py               # 90+ built-in functions
│   ├── transpiler.py           # Python & JavaScript transpiler
│   └── cli.py                  # CLI interface
├── docs/                       # MkDocs Material documentation source
├── examples/                   # 8 example programs
├── tutorial/                   # 6 tutorial files + cheatsheet
├── tests/test_mol.py           # 68 tests (all passing)
├── mol-vscode/                 # VS Code extension
├── mkdocs.yml                  # MkDocs configuration
├── pyproject.toml              # Python project config
├── LANGUAGE_SPEC.md            # Formal language specification
├── CHANGELOG.md                # Version history
├── ROADMAP.md                  # Development roadmap
└── LICENSE                     # License

Architecture

┌─────────────┐     ┌──────────────┐     ┌─────────────┐     ┌──────────────┐
│  .mol file  │ ──▶ │  Lark LALR   │ ──▶ │     AST     │ ──▶ │ Interpreter  │
│  (source)   │     │  Parser      │     │  (35+ node  │     │  (Visitor +  │
│             │     │              │     │   types)    │     │  Auto-Trace) │
└─────────────┘     └──────────────┘     └──────┬──────┘     └──────────────┘
                                                │
                                    ┌───────────┼───────────┐
                                    ▼           ▼           ▼
                              ┌──────────┐ ┌──────────┐ ┌──────────┐
                              │  Python  │ │   JS     │ │  (more)  │
                              │  Output  │ │  Output  │ │          │
                              └──────────┘ └──────────┘ └──────────┘

Testing

source .venv/bin/activate
python tests/test_mol.py

68 tests covering: variables, arithmetic, control flow, functions, recursion, lists, maps, strings, domain types, typed declarations, access control, events, pipes, guards, pipelines, chunking, embedding, vector search, full RAG integration, functional programming (map/filter/reduce), math functions, statistics, string algorithms, hashing, sorting, and type checks.


Roadmap

See ROADMAP.md for the full plan:

  • v0.3.0 (current) — 42 universal algorithms, 90+ stdlib functions, MkDocs documentation site
  • v0.4.0 — Sovereign AI, agent blocks, local model registry
  • v0.5.0 — Production runtime, async pipelines, HTTP server
  • v1.0.0 — Full ecosystem, package manager, cloud deployment

📖 Documentation

Full documentation available at: https://crux-ecosystem.github.io/MOL/


Authors

Built for IntraMind by CruxLabx.

Creator: Mounesh Kodi

License

Proprietary — CruxLabx / IntraMind. All rights reserved.

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

mol_lang-0.5.0.tar.gz (68.9 kB view details)

Uploaded Source

Built Distribution

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

mol_lang-0.5.0-py3-none-any.whl (63.4 kB view details)

Uploaded Python 3

File details

Details for the file mol_lang-0.5.0.tar.gz.

File metadata

  • Download URL: mol_lang-0.5.0.tar.gz
  • Upload date:
  • Size: 68.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mol_lang-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2e0beefed3cdcdbc43a5f0816b838eb6a10d5faa6a14c07241021d770dde50d4
MD5 84762cb336f64a1a6d52aadfd9cf97d9
BLAKE2b-256 6250a977711c6c669205ec52863ca2c393ea9832b9816a123b99aa8d7b288986

See more details on using hashes here.

File details

Details for the file mol_lang-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: mol_lang-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 63.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mol_lang-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76f296857046b27f249b97989bceabe32ff0e080b1ae8dcd661cf8df6932c6d8
MD5 1c6793d025fa38ed08be1a31c9fe9f30
BLAKE2b-256 13b8e9385e94013c09c7d8d30326d39cb40479cb392f11b64f4e6f1f1d19c6da

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