aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / svc / pi5_agent.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* pi5_agent.h -- the Pi 5 agent stage (PI5-6 final cut, CK_PI5_AGENT, QUALIFICATION ONLY while the recovery |
| 18 | * secret comes from the card request file). |
| 19 | * |
| 20 | * One fixed prompt, one bounded reply (at most CK_AGENT_MAX_NEW tokens), persisted in the sealed Store and |
| 21 | * recovered by a later boot. Runs right after the Store stage opened the Store through the Slot 1 recovery |
| 22 | * secret (PI5-4), BEFORE the model is touched: |
| 23 | * - Store not open (wrong secret): "NOTHING RECOVERED", no hashing, no session, nothing written. |
| 24 | * - Store holds an agent reply for the fixed prompt: RECOVER. The model is not used, even if MODEL.MAP is on |
| 25 | * the card. The object is read back through the sealed Store, parsed and checked against the golden |
| 26 | * tokens, the golden text and the golden model digest, and printed with the Store generation it was |
| 27 | * committed at. Writes nothing. |
| 28 | * - No reply yet: GENERATE. The resident model is ingested and hashed (core/infer.c ck_infer_run, the same |
| 29 | * path as the QEMU service image), one bounded prompt runs (ck_infer_prompt), the session is closed, and |
| 30 | * only a reply that passes every golden check is committed as one sealed Store object of the lifecycle's |
| 31 | * reply kind 'R1' (core/reply_obj.h, shared with core/lifecycle.c) plus a model/ids trailer. |
| 32 | * Both ways end with the same line: |
| 33 | * agent: reply store_gen=G object_sha256=H model_sha256=M tokens=N ids=... text="..." |
| 34 | * so a boot-2 log can be compared with the boot-1 log line for line. */ |
| 35 | #ifndef AIENOS_CK_PI5_AGENT_H |
| 36 | #define AIENOS_CK_PI5_AGENT_H |
| 37 | #include <stdint.h> |
| 38 | #include "store_sealed.h" |
| 39 | |
| 40 | #define CK_AGENT_PROMPT "What is the capital of France?" |
| 41 | #define CK_AGENT_MAX_NEW 16u /* the reply cap N (also the session's max_new in core/infer.c SESS_MAX_NEW) */ |
| 42 | /* Golden values: llama.cpp's greedy reply for CK_AGENT_PROMPT on Llama-3.2-1B-Instruct-Q4_K_M |
| 43 | * (crates/aienos-infer/tests/fixtures/ref_fr.txt, PROVENANCE.md) and its chat-template head. */ |
| 44 | #define CK_AGENT_GOLDEN_NIDS 8u |
| 45 | #define CK_AGENT_GOLDEN_TEXT "The capital of France is Paris." |
| 46 | #define CK_AGENT_GOLDEN_MODEL_SHA256 "3f5a22426976ab26cfe84dba63c1d08391717abb1af893e10f1b2968d862dcc1" |
| 47 | |
| 48 | enum { |
| 49 | CK_AGENT_MODE_NOSTORE = 1, /* Store not open: nothing recovered, nothing generated */ |
| 50 | CK_AGENT_MODE_RECOVER = 2, |
| 51 | CK_AGENT_MODE_GENERATE = 3, |
| 52 | CK_AGENT_MODE_NOMODEL = 4, /* no reply yet and no resident model: nothing written */ |
| 53 | }; |
| 54 | |
| 55 | struct ck_agent_result { |
| 56 | int mode; /* CK_AGENT_MODE_* */ |
| 57 | int ok; /* 1: the reply was recovered/committed and passed every check */ |
| 58 | uint64_t store_gen; /* Store generation the reply object was committed at */ |
| 59 | char object_sha256[65]; |
| 60 | }; |
| 61 | |
| 62 | /* The inference unit entry points the stage uses (core/infer.c in the image; a stub in the host test). */ |
| 63 | void ck_infer_run(void); |
| 64 | |
| 65 | /* s: the open writable Store, or NULL when it is not open. Returns 0 when the stage did what its mode says |
| 66 | * and every check passed (NOSTORE counts: it is a refusal, not a failure of this stage); <0 otherwise |
| 67 | * (printed). */ |
| 68 | int ck_pi5_agent_run(ss_store *s, struct ck_agent_result *out); |
| 69 | #endif |