tdln-brain
Deterministic Cognitive Layer for LogLine OS
Render a narrative frame → call an LLM → extract only JSON → validate into tdln_ast::SemanticUnit.
Why
- Prevent tool-call hallucinations: strict JSON-only outputs
- Enforce determinism: temperature 0, JSON mode when available
- Separate reasoning: optional thinking goes before JSON, not mixed
- Machine-legible failures: invalid output →
BrainError::Hallucination
Quickstart
use ;
use LocalEcho;
async
Features
| Feature | Default | Description |
|---|---|---|
parsing |
✅ | JSON extraction and validation |
render |
✅ | Narrative prompt rendering |
providers-openai |
✅ | OpenAI GPT driver |
providers-anthropic |
❌ | Anthropic Claude driver |
providers-local |
❌ | Local/mock backends |
Providers
OpenAI
use OpenAiDriver;
let driver = new;
let brain = new;
Anthropic
use AnthropicDriver;
let driver = new;
let brain = new;
Local/Mock
use ;
// Fixed noop response
let brain = new;
// Custom response
let mock = with_intent;
let brain = new;
CognitiveContext
The context controls what the model sees:
let ctx = CognitiveContext ;
Error Model
| Error | Meaning |
|---|---|
Provider(msg) |
Transport/API error |
Hallucination(msg) |
Output not valid TDLN JSON |
ContextOverflow |
Context window exceeded |
Parsing(msg) |
Malformed JSON |
Render(msg) |
Prompt rendering error |
Guarantees
- ✅
#![forbid(unsafe_code)] - ✅ Strict parse: invalid JSON →
BrainError::Hallucination - ✅ Optional reasoning: model can think, but JSON wins
- ✅ Usage metadata: token counts for budgeting
OS Integration
- With
ubl-mcp: feedDecision.intentinto tool selection; preflight via Gate; audit via Ledger - With
ubl-office: runBrain::reasonin the OODA loop; persist to ledger; schedule Dreaming separately - Token budget: use
util::clamp_budgetto manage context windows
License
MIT — See LICENSE