| Crates.io | tdln-brain |
| lib.rs | tdln-brain |
| version | 0.2.0 |
| created_at | 2026-01-10 17:50:08.443601+00 |
| updated_at | 2026-01-10 18:45:07.258225+00 |
| description | Deterministic cognitive layer for LogLine OS: context → strictly-parsed TDLN intent. |
| homepage | https://logline.foundation |
| repository | https://github.com/LogLine-Foundation/logline-workspace |
| max_upload_size | |
| id | 2034470 |
| size | 87,795 |
Deterministic Cognitive Layer for LogLine OS
Render a narrative frame → call an LLM → extract only JSON → validate into tdln_ast::SemanticUnit.
BrainError::Hallucinationuse tdln_brain::{Brain, CognitiveContext, GenerationConfig};
use tdln_brain::providers::local::LocalEcho;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let brain = Brain::new(LocalEcho);
let ctx = CognitiveContext {
system_directive: "You are a planner".into(),
..Default::default()
};
let decision = brain.reason(&ctx, &GenerationConfig::default()).await?;
println!("{:?}", decision.intent);
Ok(())
}
| 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 |
use tdln_brain::providers::openai::OpenAiDriver;
let driver = OpenAiDriver::new(api_key, "gpt-4o-mini");
let brain = Brain::new(driver);
use tdln_brain::providers::anthropic::AnthropicDriver;
let driver = AnthropicDriver::new(api_key, "claude-3-sonnet-20240229");
let brain = Brain::new(driver);
use tdln_brain::providers::local::{LocalEcho, MockBackend};
// Fixed noop response
let brain = Brain::new(LocalEcho);
// Custom response
let mock = MockBackend::with_intent("grant", serde_json::json!({"to": "alice"}));
let brain = Brain::new(mock);
The context controls what the model sees:
let ctx = CognitiveContext {
// Identity + role + boundaries
system_directive: "You are a finance agent.".into(),
// Long-term memory (RAG results, user facts)
recall: vec!["User balance: 420".into()],
// Recent conversation
history: vec![Message::user("Plan a budget")],
// Kernel constraints (violations → gate rejection)
constraints: vec!["No transfers > 500".into()],
};
| 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 |
#![forbid(unsafe_code)]BrainError::Hallucinationubl-mcp: feed Decision.intent into tool selection; preflight via Gate; audit via Ledgerubl-office: run Brain::reason in the OODA loop; persist to ledger; schedule Dreaming separatelyutil::clamp_budget to manage context windowsMIT — See LICENSE