Skip to main content

qualia_core_db/inference/inference_agent/
mod.rs

1// qualia-llm-agent: LLM Sub-Agent Layer for the Intentional Computing Ecosystem
2//
3// This crate implements the AgentRuntime trait and the Webizen-gated message
4// protocol that governs every LLM interaction under the Principal-Agent Duty of Care.
5//
6// Intended normal-runtime authority:
7//   Acting subject (currently Human, SoftwareAgent, or Organization), with
8//   independently admitted identifier associations and controller authority
9//     └── qualiaDB Webizen VM — human-centric policy and token acceptance
10//           └── LlmAgent (AgentRuntime impl)
11//                 ├── Backend::Local  (llama.cpp / WebLLM / ONNX)
12//                 ├── Backend::Remote (Nym-tunnelled, ILP-metered, user-consented)
13//                 └── Backend::Hybrid (local first, remote fallback with consent)
14//
15// Required runtime constraints (the governed foundation is implemented; legacy
16// decoder/browser acceptance paths still require the tracked G3 integration):
17//   - Zero outbound telemetry
18//   - All outputs must be cited to a NQuin provenance chain
19//   - Webizen validates I/O before touching the semantic graph
20//   - Memory budget hard-capped; default 128MB within 512MB floor
21//
22// ─── Module layout (library-ized from the former `inference_agent.rs` monolith) ─
23//   config          — constants + the effective-timeout helper
24//   types           — AgentBackend / AgentIntent / WebizenVerdict / AgentOutput /
25//                     AgentError / the AgentRuntime trait / rule-ID constants
26//   sticky_infer    — the native sticky 1-thread infer pool (thread_local engine)
27//   decode_helpers  — embedding dispatch, topology-draft accept, sieve, prefix KV
28//   local_agent     — the LocalLlmAgent struct + constructors + LoRA / sieve wiring
29//   decode          — Phase-8 bifurcated-compute decode path (impl LocalLlmAgent)
30//   validation      — pre-flight intent validation (impl LocalLlmAgent)
31//   runtime         — the AgentRuntime impl for LocalLlmAgent
32// The full public surface is re-exported below, so every external path
33// (`crate::inference::inference_agent::*` and the `llm_agent` alias) resolves
34// exactly as before.
35
36// ─── AgentIntent (re-exported hot-path frame types) ──────────────────────────
37pub use crate::modalities::logic::n3_compiler::{
38    AgentIntentFrame, N3OutputMode, MAX_CONTEXT_NAMESPACE_SLOTS, MAX_INTENT_SCOPE_SLOTS,
39};
40
41#[cfg(not(target_arch = "wasm32"))]
42pub mod sticky_infer;
43
44mod config;
45mod control;
46pub mod governed;
47#[cfg(not(target_arch = "wasm32"))]
48pub mod governed_cpu;
49mod decode;
50#[cfg(any(not(target_arch = "wasm32"), feature = "gpu-runtime"))]
51mod decode_helpers;
52mod local_agent;
53#[cfg(not(target_arch = "wasm32"))]
54pub mod native_request;
55#[cfg(not(target_arch = "wasm32"))]
56pub mod prefill_executor;
57pub mod prefix_cache;
58mod runtime;
59mod types;
60mod validation;
61
62pub use config::*;
63pub use control::*;
64pub use local_agent::*;
65#[cfg(not(target_arch = "wasm32"))]
66pub use native_request::{NativeDecodeRequest, NativePreparedReceipt};
67pub use types::*;
68
69#[cfg(test)]
70mod tests;