torg-core
Core runtime for TØR-G (Token-Only Reasoner - Graph) — a zero-parser, boolean-circuit IR for AI agent policy synthesis.
Overview
TØR-G enables LLMs to generate formally verifiable boolean circuits by emitting a constrained token vocabulary. The deterministic state machine guarantees syntactically correct output through logit masking.
Key Properties:
- No text parsing — token stream only
- Deterministic construction — state machine compilation
- Pure boolean combinatorics — no arithmetic, state, or loops
- DAG structure — formally verifiable
- Sub-microsecond evaluation — ~139 ns for typical policies
Usage
use ;
use HashMap;
// Build: "Allow if Admin OR (Owner XOR Public)"
let mut builder = new;
// Declare inputs
builder.push?;
builder.push?; // is_admin
builder.push?;
builder.push?; // is_owner
builder.push?;
builder.push?; // is_public
// Node 3: owner XOR public
builder.push?;
builder.push?;
builder.push?;
builder.push?;
builder.push?;
builder.push?;
// Node 4: admin OR node(3)
builder.push?;
builder.push?;
builder.push?;
builder.push?;
builder.push?;
builder.push?;
// Declare output
builder.push?;
builder.push?;
let graph = builder.finish?;
// Evaluate
let inputs: = .into;
let outputs = evaluate?;
assert!; // owner XOR !public = true
LLM Integration
The valid_next_tokens() method enables constrained decoding:
use ;
let mut builder = new;
builder.push.unwrap;
builder.push.unwrap;
builder.push.unwrap;
builder.push.unwrap;
// Only operators are valid here
let valid = builder.valid_next_tokens;
assert!;
assert!;
assert!;
Use these tokens to mask LLM logits during inference, guaranteeing valid circuit generation.
Token Vocabulary
| Token | Symbol | Purpose |
|---|---|---|
Or |
∨ | Logical OR |
Nor |
⊽ | Logical NOR |
Xor |
⊻ | Logical XOR |
NodeStart |
● | Begin node definition |
NodeEnd |
○ | End node definition |
InputDecl |
◎IN | Declare input |
OutputDecl |
◎OUT | Declare output |
True |
◎T | Constant true |
False |
◎F | Constant false |
Id(n) |
— | Identifier (0..65535) |
Derived Operations
NOT(a) = NOR(a, a)
AND(a, b) = NOR(NOR(a,a), NOR(b,b))
IMPLIES(a,b) = OR(NOR(a,a), b)
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.