nx_session_real_llm_compose_test.nx source
↩ module page · 70 lines · 2905 B
1// nx_session_real_llm_compose_test.nx -- demonstrates how nx_session +
2// nx_gguf_fixture_tiny + nx_actor_role_llm_v2 compose into a tight
3// real-transformer scene.
4//
5// Previous compose smokes (nx_companion_compose, dual/triple/quad)
6// each had 30+ lines of wiring boilerplate to set up the scheduler +
7// bus + multiplexer + arbiter + broker + actor + register + subscribe.
8//
9// This smoke shows the new composite path: ~10 lines of substrate
10// setup, then real-transformer-forward through the actor, then
11// drain. The COMPOSED primitives do the work.
12
13import "nx_syscalls.nx"
14import "nx_tier.nx"
15import "nx_actor.nx"
16import "nx_message.nx"
17import "nx_session.nx"
18import "nx_gguf_fixture_tiny.nx"
19import "nx_actor_role_llm_v2.nx"
20
21func main() -> i64 {
22 let now: nx_size = 1000000
23
24 // ===== Substrate setup: 2 calls =====
25 let s: *NxSession = nx_session_new_default(now)
26 if nx_session_is_ready(s) != 1 { return 1 }
27 let fix: *NxGgufFixtureBundle = nx_gft_build_tiny_llama(0xc0ffee)
28 if nx_gft_is_built(fix) != 1 { return 2 }
29
30 // ===== Actor + listener wired through composite helpers =====
31 let LLM: nx_int = 8001
32 let LIS: nx_int = 8099
33 if nx_session_spawn_actor(s, LLM, 1, 80, 0, now) != NX_SE_V_OK { return 3 }
34 if nx_session_spawn_actor(s, LIS, 5, 50, 0, now) != NX_SE_V_OK { return 4 }
35 if nx_session_subscribe(s, LIS, NX_MS_KIND_LLM_TOKEN) != NX_SE_V_OK { return 5 }
36
37 // ===== Real LLM actor on fixture inputs =====
38 let prompt: *u8 = sys_mmap(1)
39 prompt[0] = 0x62 // 'b'
40 let ctx: *NxLlmV2ActorCtx = nx_lv_actor_new(
41 fix.spec, fix.gguf_buf, fix.hdr, fix.bpe,
42 prompt, 1,
43 1024, 4, fix.prng_state, 10000, 724)
44 if (ctx as i64) == 0 { return 6 }
45
46 // ===== Drive INIT -> RUN -> EMIT through the actor =====
47 var tick: nx_size = now + 100
48 if nx_lv_actor_step(ctx, s.scheduler, s.bus, LLM, tick) != NX_LV_V_STEPPED { return 7 }
49 tick = tick + 100
50 if nx_lv_actor_step(ctx, s.scheduler, s.bus, LLM, tick) != NX_LV_V_STEPPED { return 8 }
51 if ctx.runner_result < 0 { return 9 }
52 if ctx.runner_result >= fix.vocab_size { return 10 }
53 if ctx.runner_verdict != NX_LR2_OK { return 11 }
54 tick = tick + 100
55 if nx_lv_actor_step(ctx, s.scheduler, s.bus, LLM, tick) != NX_LV_V_COMPLETED { return 12 }
56
57 // ===== Verify listener received the real token =====
58 if nx_ms_pending(s.bus, LIS) != 1 { return 13 }
59 let m: *NxMessage = nx_ms_receive(s.bus, LIS)
60 if m.kind != NX_MS_KIND_LLM_TOKEN { return 14 }
61 if m.sender_actor_id != LLM { return 15 }
62 if (m.payload_handle as nx_int) != ctx.runner_result { return 16 }
63
64 // ===== Substrate state: LLM actor COMPLETED, session ready =====
65 let llm_actor: *NxActor = nx_ac_find(s.scheduler, LLM)
66 if llm_actor.state != NX_AC_STATE_COMPLETED { return 17 }
67 if nx_session_actor_count(s) != 2 { return 18 }
68
69 return 0
70}