Structured LLM task runner with schema validation, confidence scoring, and subagent orchestration
Project description
Cognitive Modules
Verifiable Structured AI Task Specification
English | 中文
Cognitive Modules is a specification and runtime for verifiable, structured AI tasks with strong contracts, auditability, and deterministic validation.
Status
- Primary runtime: Node.js CLI (
cognitive-modules-cli, commandcog) - Python runtime: legacy / not actively maintained
Version
- Runtime (npm):
2.2.5 - Spec: v2.2
Installation (Node.js)
# Zero-install quick start
npx cogn@2.2.5 --help
# Or use the full package name
npx cognitive-modules-cli@2.2.5 --help
# Global installation
npm install -g cogn@2.2.5
# or: npm install -g cognitive-modules-cli@2.2.5
cognis an alias package forcognitive-modules-cli. Both provide the samecogcommand.
Quick Start
# Configure provider (example: OpenAI)
export OPENAI_API_KEY=sk-xxx
# Run code review
cog run code-reviewer --args "def login(u,p): return db.query(f'SELECT * FROM users WHERE name={u}')" --pretty
# Run task prioritization
cog run task-prioritizer --args "fix bug(urgent), write docs, optimize performance" --pretty
# Run API design
cog run api-designer --args "order system CRUD API" --pretty
# Start HTTP service (API integration)
cog serve --port 8000
# Start MCP server (Claude Code / Cursor integration)
cog mcp
v2.2 Response Format
All modules return the unified v2.2 envelope format:
{
"ok": true,
"meta": {
"confidence": 0.92,
"risk": "low",
"explain": "Brief summary for quick routing decisions (≤280 chars)"
},
"data": {
"...business fields...",
"rationale": "Detailed reasoning for audit and human review",
"extensions": {
"insights": [
{
"text": "Additional insight",
"suggested_mapping": "Suggested field to add to schema"
}
]
}
}
}
Core Features
- Strong type contracts - JSON Schema validation for input/output
- Control/Data separation -
metafor routing,datafor business payloads - Module tiers -
exec | decision | explorationwith strictness/overflow rules - Subagent orchestration -
@call:modulefor inter-module calls - Composition - sequential/parallel/conditional/iterative workflows
- HTTP API & MCP - first-class integrations for workflows and AI tools
- Repair pass - auto-fix common envelope format issues
CLI Commands
# Module management
cog list
cog add <url> --module <path>
cog update <module>
cog remove <module>
cog versions <url>
# Run modules
cog run <module> --args "..."
cog run <module> --input '{"query":"..."}'
# Composition
cog compose <module> --args "..."
cog compose-info <module>
# Validation & migration
cog validate <module> --v22
cog validate --all
cog migrate <module> --dry-run
cog migrate --all --no-backup
# Other
cog pipe --module <name>
cog init [name]
cog doctor
cog serve --port 8000
cog mcp
Built-in Modules (Repository)
| Module | Tier | Function | Example |
|---|---|---|---|
code-reviewer |
decision | Code review | cog run code-reviewer --args "your code" |
code-simplifier |
decision | Code simplification | cog run code-simplifier --args "complex code" |
task-prioritizer |
decision | Task priority sorting | cog run task-prioritizer --args "task1,task2" |
api-designer |
decision | REST API design | cog run api-designer --args "order system" |
ui-spec-generator |
exploration | UI spec generation | cog run ui-spec-generator --args "e-commerce homepage" |
ui-component-generator |
exploration | UI component spec | cog run ui-component-generator --args "button component" |
product-analyzer |
exploration | Product analysis | cog run product-analyzer --args "health product" |
Module Format (v2.2)
my-module/
├── module.yaml # Machine-readable manifest
├── prompt.md # Human-readable prompt
├── schema.json # meta + input + data + error schemas
└── tests/ # Golden test cases
Minimal module.yaml:
name: my-module
version: 2.2.0
responsibility: One-line description
tier: decision # exec | decision | exploration
schema_strictness: medium # high | medium | low
excludes:
- things not to do
policies:
network: deny
filesystem_write: deny
side_effects: deny
overflow:
enabled: true
recoverable: true
max_items: 5
require_suggested_mapping: true
enums:
strategy: extensible # strict | extensible
failure:
contract: error_union
partial_allowed: true
compat:
accepts_v21_payload: true
runtime_auto_wrap: true
LLM Configuration
Cognitive Modules auto-selects a provider based on which API key is present. You can override with --provider and --model.
Environment variables:
OPENAI_API_KEYANTHROPIC_API_KEYGEMINI_API_KEYDEEPSEEK_API_KEYMINIMAX_API_KEYMOONSHOT_API_KEYDASHSCOPE_API_KEYorQWEN_API_KEYOLLAMA_HOST(for Ollama local)COG_MODEL(override default model)
Check config:
cog doctor
Development (Node.js)
# Clone
git clone https://github.com/ziel-io/cognitive-modules.git
cd cognitive-modules
# Install
cd packages/cli-node
npm install
# Build
npm run build
# Test
npm test
Documentation
Specifications
| Document | Description |
|---|---|
| SPEC-v2.2.md | v2.2 full specification |
| SPEC-v2.2_zh.md | v2.2 规范中文版 |
Implementers
| Document | Description |
|---|---|
| IMPLEMENTERS-GUIDE.md | How to build a runtime |
| CONFORMANCE.md | Conformance levels |
| ERROR-CODES.md | Standard error codes |
| templates/runtime-starter/ | Runtime starter template |
Advanced
| Document | Description |
|---|---|
| COMPOSITION.md | Composition and dataflow |
| CONTEXT-PROTOCOL.md | Context protocol |
| COGNITIVE-PROTOCOL.md | Protocol details |
| INTEGRATION.md | Integration guide |
Schemas & Test Vectors
| Resource | Description |
|---|---|
| spec/response-envelope.schema.json | v2.2 envelope schema |
| spec/module.yaml.schema.json | module.yaml schema |
| spec/test-vectors/ | Compliance test vectors |
Registry (Spec Only)
| Resource | Description |
|---|---|
| REGISTRY-PROTOCOL.md | Registry protocol specification |
| spec/registry-entry.schema.json | Registry entry schema |
License
MIT
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 cognitive_modules-2.2.3.tar.gz.
File metadata
- Download URL: cognitive_modules-2.2.3.tar.gz
- Upload date:
- Size: 66.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
355306529603bb01d50384802d2c21170ee75a41e768f831759eb90e9dd20e7c
|
|
| MD5 |
c72e6a39966e9d96947b4b48c6069bc1
|
|
| BLAKE2b-256 |
febc054169e724599a3612656f907d5704559c5190bf5a3d40bd9ba2a9583be6
|
File details
Details for the file cognitive_modules-2.2.3-py3-none-any.whl.
File metadata
- Download URL: cognitive_modules-2.2.3-py3-none-any.whl
- Upload date:
- Size: 52.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6953995edc8d2ece94cb9b343701a813645d18425fc9a324ee46c0d768a12412
|
|
| MD5 |
6081b87766d2fafbd993b67a848b6b5d
|
|
| BLAKE2b-256 |
7f75eaaa0cf69145d3d16cc90de355122b3c5e32350fcf4415438701fb690651
|