openkind-engine
DecisionEnginedispatch, mock inference, and immutable execution-profile contracts foropenkind.
openkind-engine decouples the HTTP and gRPC transport layers from model implementations. It defines the DecisionEngine trait every backend implements, the EngineRegistry that routes model aliases to engines, the shared dispatch() evaluation path, the deterministic MockEngine, and the immutable ModelExecutionProfile contract.
The crate depends on openkind-core and no transport stack: it imports no axum or tonic types. Model execution itself lives in openkind-backends, which implements DecisionEngine and consumes the profile contracts below.
Getting started
The transport layers call dispatch with any registered engine. The same path works in tests and tools:
use HashMap;
use Arc;
use ;
use ;
async
The example needs tokio (with the macros and rt-multi-thread features) and serde_json alongside this crate as a path dependency.
Key components
HTTP / gRPC (openkind-api)
│
▼
openkind_engine::dispatch(req, ®istry)
│
├── registry.get(&req.model) ──► Arc<dyn DecisionEngine>
├── ResponseContract::from_request(&req)
├── engine.estimate_input_tokens(&req)
├── engine.evaluate(req).await
└── contract.validate(&resp), fill missing Usage counts
DecisionEnginetrait:EngineRegistry: Maps public model aliases (e.g."jev-latest","mock") toArc<dyn DecisionEngine>.registerreplaces an alias, whileregister_if_absentandunregisterdrive load and unload. Lookups clone the engine handle, so accepted requests keep executing through an unload.list_models()overrides each engine'sModelInfo.namewith the registered alias.dispatch(): Resolves the alias, validates the request throughResponseContract::from_request, records request metrics, evaluates, and re-validates the engine response against the request's contract. A contract-violating response is anEngineError::Backendfault, not a client-facing validation error. Token counts fall back toestimate_input_tokensand a per-answer output estimator only when the backend leaves them unset.MockEngine: DeterministicNoul,Choice, andScoreanswers without loading weights. Each answer is seeded from the question ID and structurally hashed instructions, so repeated requests reproduce identical distributions. Probabilities sum to 1.0, and confidence stays within [0.0, 1.0].ModelExecutionProfile: Immutable contract binding a reference-bundle source (pinned repository revision and SHA-256), a backbone revision, execution semantics (renderer, fitted head, rejection method, and the declaredProbabilitySpace), and the numerical policy (calibration temperature, policy threshold, parity tolerances). Fields are validated at construction.openkind-backendsbuilds real engines from a selected profile; theDecisionEnginetrait itself carries no profile state.EngineError: Transport-neutral taxonomy ofInvalid,UnknownModel,Unsupported,Overloaded,DeadlineExceeded, andBackendvariants. The API layer maps each onto HTTP and gRPC statuses.
Testing
Unit tests cover registry ordering and lifecycle, dispatch validation and token fallbacks, mock determinism and distribution guarantees, and profile validation.
License
See the MIT license. Cargo metadata declares MIT OR Apache-2.0.