Reliable, Rust-Powered Agentic AI Framework with Transactional Memory.
Project description
Theus Framework
"Safe architecture for AI-assisted development. Powered by Rust."
🧭 Where do I start?
Theus is vast. Use our Interactive Documentation Map to find your path:
- 🚀 I want to build an Agent now: Go to Quickstart
- 🤖 I am an AI Assistant: Go to AI Tutorials
- 🏗️ I want to check architecture: Go to Specs
- 🎓 I want to learn from scratch: Go to Tutorials
� Why Theus?
"Build with confidence. Your AI assistant writes the code—Theus makes sure it's safe."
Whether you're vibe coding with an AI assistant, building a complex agent, or crafting production software that needs to last for years—Theus has your back.
For Vibe Coders & AI-Assisted Development
You focus on what you want to build. Let your AI write the logic. Theus automatically ensures:
- Every function declares exactly what data it reads and writes
- No hidden side effects or surprise mutations
- If something goes wrong, it rolls back cleanly
For Teams Who Care About Maintainability
Come back to your code in 2 years. You'll thank yourself:
- Explicit Contracts: Every
@processis self-documenting - Transparent State: Know exactly where your data lives and who can touch it
- Built-in Audit: Validate business rules at the boundary, not scattered in code
For Safety-Critical Applications
When bugs aren't just annoying—they're costly:
- Transaction Safety: Automatic rollback on failure
- Explicit Access: Processes must declare every data point they touch via
@processcontracts - Industrial Audit: Block, warn, or stop based on configurable rules
- Concurrency Safety: Advanced Conflict Manager with Backoff & VIP Locking
📦 Installation
Theus v3.0 requires Python 3.14+ to leverage Sub-interpreter support.
pip install theus
⚡ Quick Start
Option 1: Use a Template (Recommended)
# Create a new project with the E-Commerce demo (full-featured)
py -m theus.cli init my_app --template ecommerce
cd my_app
python main.py
This creates a complete runnable demo with: Orders, Payments, Heavy Zone, Audit Rules, and Workflow.
Option 2: Manual Setup
from theus import TheusEngine, process
from theus.structures import StateUpdate
# 1. Define a Process with Contract
@process(
inputs=['domain_ctx.accounts'],
outputs=['domain_ctx.accounts'],
errors=['ValueError']
)
def transfer(ctx, from_user: str, to_user: str, amount: int):
if amount <= 0:
raise ValueError("Amount must be positive")
# V3 Pattern: Copy -> Modify -> Return
# ctx.domain_ctx.accounts is Immutable (FrozenDict)
accounts = dict(ctx.domain_ctx.accounts)
if accounts.get(from_user, 0) < amount:
raise ValueError("Insufficient funds")
accounts[from_user] -= amount
accounts[to_user] = accounts.get(to_user, 0) + amount
# Return explicit update (Engine handles the commit)
return StateUpdate(domain={'accounts': accounts})
# 2. Initialize Engine
from src.context import DemoSystemContext
engine = TheusEngine(DemoSystemContext(), strict_mode=True)
engine.register(transfer)
# 3. Execute with Transaction Safety
result = engine.execute(transfer, from_user="Alice", to_user="Bob", amount=500)
💡 Available Templates:
standard,ecommerce,hybrid,agent,minimalRunpy -m theus.cli init --helpto see all options.
🔄 Workflow: Flux DSL
v3.0 introduces Flux DSL - a declarative YAML language for workflow control.
# workflows/main.yaml
steps:
- process: "initialize"
- flux: if
condition: "domain['is_valid'] == True"
then:
- process: "process_data"
- process: "save_result"
else:
- process: "handle_error"
- flux: while
condition: "domain['items_left'] > 0"
do:
- process: "process_next_item"
Execute with:
engine.execute_workflow("workflows/main.yaml")
🛠️ CLI Tools
Theus provides a powerful CLI suite to accelerate development and maintain architectural integrity.
py -m theus.cli init <project_name>: Scaffolds a new project with the standard V3 structure.py -m theus.cli audit gen-spec: Scans your@processfunctions and automatically populatesspecs/audit_recipe.yaml.py -m theus.cli audit inspect <process_name>: Inspects the effective audit rules for a process.py -m theus.cli schema gen: Generatesspecs/context_schema.yamlfrom your Python Dataclass definitions.py -m theus.cli check: Runs the POP Linter to enforce architectural purity.
🧠 Advanced Architecture
The Transaction Engine (v3.0)
Theus prioritizes Performance (Zero-Copy) while providing Safety Tools:
- Zero-Copy Reads: Reading data is O(1) direct memory access.
- Copy-on-Write: To modify data, you MUST create a copy (
new = list(old)). - Atomic Commit: The Engine swaps the pointer to the new data only if the transaction succeeds.
⚠️ Warning: In-place mutation (e.g.,
list.append) bypasses the safety lawyer. Always use the Copy-on-Write pattern.
The Heavy Zone & Zero-Copy Parallelism (Strategy V3)
Current Status (v3.0.2): True Parallelism is now available via
ProcessPool.
For AI workload/Tensors > 1MB, ctx.heavy acts as a Shared Memory Gateway:
- Zero-Copy: leverages shared memory to pass large datasets between processes without serialization overhead.
- True Parallelism: CPU-bound tasks can bypass the GIL using
ProcessPool. - Conflict Safety: Integrated Exponential Backoff and VIP Locking ensure that high-concurrency workloads do not starve or livelock.
Research & Debugging Mode
For rapid experimentation where you need to bypass architectural constraints:
engine = TheusEngine(sys_ctx, strict_mode=False)
Effect: Disables strict architectural guards (ContextGuard), allowing access to private attributes (_hidden) and restricted zones.
Note: Transaction safety (CAS) is still enforced to ensure consistency.
📚 Documentation & Debugging
- DEBUGGING.md: Read this first! Common pitfalls, Type Checking errors, and Pickling issues.
- Spec: Full Architecture Specification.
- POP Manifesto: The philosophy behind Process-Oriented Programming.
⚖️ License
- Software: MIT License.
- Whitepaper: CC-BY 4.0.
Maintained by: Hoàng Đỗ Huy
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 Distributions
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 theus-3.0.21.tar.gz.
File metadata
- Download URL: theus-3.0.21.tar.gz
- Upload date:
- Size: 412.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa9ff306df477922c5c3d5bc3e151d5677731fd2078fb4f7c12ab42fe9ff16ec
|
|
| MD5 |
87c2a8e91bab4e5b04b78583093f0c94
|
|
| BLAKE2b-256 |
e7e74db516725645099d27d09e5081b8a7c0c2d5cda061e3d63d95d2edeccf0b
|
File details
Details for the file theus-3.0.21-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: theus-3.0.21-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 775.6 kB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a5fb3683405b607ea9f7da364adfd7e5f678ea042b553ae9e79f8007b4c8ea3
|
|
| MD5 |
557f119b245701e7dc7e7485d5d248ee
|
|
| BLAKE2b-256 |
6d42529a62183589a1e950002c7ab0d0efa5a062a1f9b5c804903748a8961edf
|
File details
Details for the file theus-3.0.21-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: theus-3.0.21-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
534e9911e2619d7fb5fe32fde80d5ba05fcb49c8e87cf951e0ca6afd8186b3ab
|
|
| MD5 |
0ad5dd207cb887bcfd1ae749515c7096
|
|
| BLAKE2b-256 |
5c456fea8457326013e1877476356517140edae823d39e7969cb6f58efeb35ed
|
File details
Details for the file theus-3.0.21-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: theus-3.0.21-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23a65438375976dbae3cd1903fa3a8d1affa32285fff3de73086e474f5d33621
|
|
| MD5 |
87744cfaa0f0c53d36d07d80b3250335
|
|
| BLAKE2b-256 |
66b56e5250779d59f57cc2ac41830021dcba9e7457c2d8759fbf496bac439796
|
File details
Details for the file theus-3.0.21-cp312-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: theus-3.0.21-cp312-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 900.7 kB
- Tags: CPython 3.12+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3a2655f7395335d519937331f4863fc380b0c51c0ebe084614f94aee03be4fa
|
|
| MD5 |
3bc77d6f6dede43840bf38083ca4c04e
|
|
| BLAKE2b-256 |
28305ef14dbc07c5ef63c981bd38e3a9d1d91241c712b0a5a82171d65a6b1198
|
File details
Details for the file theus-3.0.21-cp312-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: theus-3.0.21-cp312-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 923.1 kB
- Tags: CPython 3.12+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5308793a2ddeb20f47b404c6e0c835a2b27c17f56e75707e65b3aca109ede2b
|
|
| MD5 |
914dc25f41b8e0bc18e252508ce31042
|
|
| BLAKE2b-256 |
cf6186bf5e8816165a1dec72e141139fd533dd054c4dc08c6310ece334bccdef
|