HIP-1345: Agent-Aware Model Serving and Cache Reuse. Status Draft. Hanzo architectural specification.
This specification defines architectural interfaces, multi-tenant KV isolation invariants, inference provenance fields, capability-aware Enso routing contracts, and acceptance benchmarks for Research Bounties #11 through #20 across hanzoai/engine, hanzoai/ml, hanzoai/cloud, and hanzoai/index.
Interactive agent loops exhibit execution patterns poorly served by generic throughput batching: non-prefix repetition of tool and system segments, large RAG KV caches that relocate in prompt position, multi-tenant LoRA customization, strict JSON-schema tool grammars, pause/resume GPU workloads, and stringent privacy/retention constraints across upstream models. At the same time, shared KV prefix caches and older third-party serving pools pose cross-tenant state-contamination hazards unless ownership boundaries and runtime provenance are enforced end to end.
The key words MUST, MUST NOT, SHOULD, SHOULD NOT, and MAY are to be interpreted as in RFC 2119.
Every shared KV tier in hanzoai/engine — GPU paged block hash (ExtraHashKey::CacheSalt), sequence prefix cache, disk KV spill files, and distributed hanzo-kv-fabric directories — MUST include the resolved tenant salt (cache_salt / org_id) in cache lookup and insertion keys when serving multi-tenant traffic.
Scheduler block caching MUST pass strictly the count of tokens whose K/V projections were actually computed (kv_computed_tokens), NEVER sequence.tokens.len() containing an uncomputed sampled token, and MUST NOT publish incomplete blocks from aborted, errored, or prefill-canceled sequences.
Every inference span and usage record emitted by hanzoai/engine, Enso, and hanzoai/cloud MUST carry runtime_digest (gen_ai.hanzo.runtime_digest) and cache_connector (gen_ai.hanzo.cache_connector) identifying the serving runtime image/digest and active KV cache connector. Pools earlier than fixed upstream baselines MUST NOT serve multi-tenant traffic.
hanzoai/engine MAY prototype coarse-grained SSD KV block offload with predictive prefetching for memory-constrained deployments, reporting decoded tokens/s, p99 stall latency, and accuracy delta against full GPU KV residence.
hanzoai/engine SHOULD evaluate position-independent KV reuse for unchanged system and tool segments when prompt offsets shift, measuring output equivalence, TTFT, and GPU memory footprint relative to strict prefix caching.
Single-node schedulers (hanzoai/engine, #13) and distributed Enso gateways (hanzoai/cloud, #18) MAY route requests using estimated KV load latency, cache residency, skew, and eviction pressure, measuring p95/p99 TTFT and goodput against least-loaded routing.
hanzoai/engine and hanzoai/ml MAY record weight-loading page access templates across NVMe, host RAM, and device memory (#14), and page multi-rank Zen adapters over shared base weights (#15), reporting cold-load latency, adapters per GPU, and adapter-switch overhead.
hanzoai/engine MAY prototype compiled grammar masks (such as Apache-2.0 XGrammar-2 approaches) to accelerate JSON-schema and tool-call constrained text generation in Zen models. Constrained grammar decoding MUST remain scoped to generative text output; structured non-generative decision heads belong exclusively to Kai (HIP-1332).
Enso (hanzoai/cloud) SHOULD evaluate learned cost-quality routers selecting the lowest-cost eligible model meeting a verified quality floor, subject to hard capability, plan-entitlement, and retention constraints:
zero_retention eligibility (filtering out 30-day-retention models when ZDR is enforced).thinking_family boundaries (pinning one model per generation turn and stripping incompatible reasoning blocks on explicit model switches).tool_choice and sampling parameter compatibility (returning HTTP 400 rather than silently corrupting mandatory-thinking calls).hanzoai/engine and hanzoai/index MAY fuse cached document KV blocks across non-prefix layouts with selective recomputation (#19, measuring TTFT and answer parity), and pause/resume inference or training state via incremental GPU checkpoints (#20 — Wave 1 #9, measuring pause/resume latency and checkpoint byte volume).
Unifying KV safety invariants (§1) with position-shifted reuse (§2.2) and capability-aware Enso routing (§2.6) prevents speculative serving optimizations from violating tenant isolation, zero-retention contracts, or Kai's non-generative separation.
Unsalted prefix caches or off-by-one uncomputed tail tokens can allow one tenant to attend to evicted KV projections from a prior tenant. Both cache_salt keying (§1.1) and kv_computed_tokens bounds (§1.2) MUST hold unconditionally across GPU, host, disk, and network KV fabrics. Retention-incompatible or account-bound thinking states MUST be rejected or reset before cross-model dispatch.
hanzoai/engine, hanzoai/ml, hanzoai/cloud, hanzoai/indexReleased under CC0 1.0 Universal Public Domain Dedication.