Skip to content

Commit 76e26f6

Browse files
onn: omc_llm_self_instantiate orchestration manifest + session summary
omc_llm_self_instantiate(context, task, base_dir, base_sender_id) takes an LLM's conversation history, compresses to M3(N) specialists via context_compress, and writes each as a signed prompt-file in base_dir. Returns a manifest: [{specialist_id, prompt_path, fold_index, mu, sigma, dominant_attractor, item_count}, ...]. An orchestrator (Python, Bash, MCP client) spawns N LLM sessions from the manifest. Each spawned session reads its specialist file, verifies the signature, and starts with the specialist's inherited geometric state as its seed. Tested on 200-message context → 10 specialists, all 10 prompt files written to /tmp/omc_spawn/specialist_*.json with valid substrate signatures. OMC is honest about not forking LLMs itself; the manifest is the right boundary — OMC handles structural + substrate-signed parts, the orchestrator handles process spawning. SESSION_SUMMARY.md captures everything done this session: ONN port, context compression curve (10→3, 10000→18), what's solved (structural continuity) vs what isn't (topical retrieval, process spawning, lossless reconstruction). Documents the next experiment: hand the 10 spawned files to Hermes and close the full self-instantiation loop with two live agents. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1653180 commit 76e26f6

6 files changed

Lines changed: 330 additions & 3 deletions

File tree

OMC_REFERENCE.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Auto-generated from `omnimcode-core/src/docs.rs`. Run `omc --gen-docs > OMC_REFERENCE.md` to regenerate.
44

5-
**Total documented builtins**: 638
5+
**Total documented builtins**: 639
66

7-
**OMC-unique**: 71 (no direct Python/NumPy equivalent — these are why you reach for OMC over numpy)
7+
**OMC-unique**: 72 (no direct Python/NumPy equivalent — these are why you reach for OMC over numpy)
88

99
---
1010

@@ -53,7 +53,7 @@ Other high-value calls: `omc_unique_builtins()` (the OMC-only surface), `omc_pyt
5353
- [tokenizer](#tokenizer) (17 builtins)
5454
- [code_intel](#code_intel) (17 builtins)
5555
- [messaging](#messaging) (5 builtins)
56-
- [onn](#onn) (4 builtins)
56+
- [onn](#onn) (5 builtins)
5757
- [llm_workflow](#llm_workflow) (7 builtins)
5858
- [math](#math) (82 builtins)
5959
- [dicts](#dicts) (31 builtins)
@@ -5084,6 +5084,16 @@ Compress N context messages to ~M3(N) specialist summaries. The substrate-native
50845084
omc_context_compress(conversation_history) // ~log_log(N) specialists
50855085
```
50865086

5087+
### `omc_llm_self_instantiate` 🔱 *OMC-unique*
5088+
5089+
**Signature**: `(context: string[], task: string, base_dir: string, base_sender_id: int) -> dict[]`
5090+
5091+
Orchestration primitive: compress context to M3(N) specialists, write each as a signed prompt file in base_dir, return manifest. An orchestrator spawns N LLM sessions, each seeded with its specialist's inherited geometric state.
5092+
5093+
```omc
5094+
omc_llm_self_instantiate(history, "refactor X", "/tmp/spawn", 18173) // [{prompt_path, mu, sigma, ...}]
5095+
```
5096+
50875097
---
50885098

50895099
## llm_workflow

examples/demos/SESSION_SUMMARY.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Session Summary — LLM ↔ LLM substrate comms + ONN self-instantiation
2+
3+
## Tasks tackled
4+
5+
1.**Recorded the round-trip validation moment** (`a40ea88`)
6+
Two LLMs verified each other's substrate-signed messages with
7+
zero drift. Evidence preserved in `round_trip_evidence_*.json`.
8+
9+
2.**Built a secondary-brain prompting function** (`omc_prompt_agent`)
10+
Any OMC program can fire a signed prompt at another agent's
11+
inbox via the shared `omc_channel/` directory. Demo:
12+
`examples/demos/secondary_brain.omc`.
13+
14+
3.**Cataloged Hermes's ONN / Self-Instantiation skills**
15+
`examples/demos/ONN_SKILLS_CATALOG.md` — maps every relevant
16+
Hermes skill (M3, geometric instantiation, phi-spectrum,
17+
self-healing, etc.) to OMC status (port now / port later /
18+
N/A).
19+
20+
4.**Built OMC self-instantiation primitives** (`1653180`)
21+
`omc_m3_spawn_count`, `omc_self_instantiate`, `omc_fold_back`,
22+
`omc_context_compress` — port of Hermes's M3 wave-interference
23+
spawn algorithm. 14 OMC tests + 5 Rust unit tests, all green.
24+
25+
5.**Built the LLM-orchestration manifest layer**
26+
`omc_llm_self_instantiate(context, task, base_dir, sender_id)`
27+
compresses to M3(N) specialists, writes one signed prompt file
28+
per specialist, returns a manifest. An orchestrator (human,
29+
Bash, Python, MCP) spawns N LLM sessions from the manifest.
30+
31+
## What got built (concrete)
32+
33+
builtins | omc_m3_spawn_count, omc_self_instantiate,
34+
omc_fold_back, omc_context_compress,
35+
omc_prompt_agent, omc_llm_self_instantiate
36+
modules | omnimcode-core/src/onn.rs (new)
37+
tests | examples/tests/test_onn.omc (14 cases)
38+
demos | context_compression.omc (200→10 to 10000→18)
39+
| secondary_brain.omc (fire-and-poll pattern)
40+
| llm_self_instantiate.omc (orchestration manifest)
41+
documentation | ONN_SKILLS_CATALOG.md
42+
| CONTEXT_PROBLEM_FRAMING.md
43+
| ROUND_TRIP_VALIDATED.md
44+
| SESSION_SUMMARY.md (this file)
45+
46+
## Empirical results worth noting
47+
48+
**Context compression curve** (measured, not theoretical):
49+
50+
| N | M3(N) | compression |
51+
|---|-------|-------------|
52+
| 10 | 3 ||
53+
| 50 | 7 ||
54+
| 100 | 7 | 14× |
55+
| 500 | 11 | 45× |
56+
| 1,000 | 12 | 83× |
57+
| 5,000 | 16 | 312× |
58+
| 10,000 | 18 | 555× |
59+
60+
**M3 vs M1**: M3 always ≤ M1 (the log_phi bound), often substantially
61+
less. M3(100)=7 vs M1(100)≈10. Sublog-bounded.
62+
63+
**Round-trip integrity**: 2 LLMs, 0 drift on resonance + HIM,
64+
content_hash matched bit-for-bit (3551785709911115688). The
65+
substrate-derived signature is recomputable by both sides.
66+
67+
## Honest verdict on "solving the context problem"
68+
69+
**Partial solution.** The substrate gives:
70+
71+
- **Structural continuity** — μ/σ/attractor drift across folds, fully
72+
recomputable, bounded above by M3(N).
73+
- **Geometric memory** — specialists are stable across rebuilds,
74+
associatively foldable, comparable.
75+
- **Integrity** — substrate-signed exchange between agents survives
76+
reformatting and renaming.
77+
78+
The substrate does NOT give:
79+
80+
- **Topical retrieval** — the prime-resonance null result (`92d7d90`)
81+
proved the φ-field doesn't encode topic. For topical search you
82+
still need embeddings.
83+
- **Lossless reconstruction** — individual message text is dropped;
84+
only the truncated summary survives.
85+
- **Process spawning** — OMC doesn't fork LLMs. The manifest layer
86+
is honest: it writes prompt files; an external orchestrator
87+
spawns processes.
88+
89+
What's actually solved: **the structural / geometric layer of the
90+
context problem**. Bounds compression at M3(N). Provides
91+
substrate-stable continuity. Composes with messaging for
92+
multi-agent setups. Doesn't pretend to do topical retrieval.
93+
94+
## What an LLM running tomorrow can actually do
95+
96+
```omc
97+
# 1. Compress your context.
98+
h specs = omc_context_compress(my_history);
99+
100+
# 2. Either summarize forward yourself, OR fan out:
101+
h manifest = omc_llm_self_instantiate(
102+
my_history, "process this", "/tmp/spawn", my_sender_id);
103+
104+
# 3. (Orchestrator spawns the N sessions, collects responses.)
105+
106+
# 4. Fold the responses back into running state.
107+
h new_state = omc_fold_back(old_mu, old_sigma, turn, response_specs);
108+
109+
# 5. Hand off the new state to the next turn.
110+
```
111+
112+
This is the working geometric-memory loop. It's not magic. It's
113+
sublogarithmic compression of arbitrary input, plus substrate-
114+
verified integrity across agent boundaries.
115+
116+
## What I could NOT do in this session
117+
118+
- **Actually spawn LLM sub-sessions from OMC**: requires Python +
119+
API keys + orchestration runtime. Out of scope for OMC core.
120+
The manifest is the right level of abstraction — OMC writes
121+
the files; the orchestrator runs the LLMs.
122+
- **Validate the fold-back loop with real LLM responses**: would
123+
need Hermes (or another agent) to actually process the spawned
124+
prompts and respond. Possible as a follow-up experiment.
125+
- **Train a substrate-aware LLM**: Hermes's `onn-phi-field-llm`
126+
skill describes this, but it's a multi-week training project,
127+
not a session-scoped task.
128+
129+
## Concrete next experiment (for when you're back)
130+
131+
Hand the 10 spawned prompt files from `llm_self_instantiate.omc`
132+
to Hermes and ask Hermes to:
133+
134+
1. Process each as a separate "session" (signed inbound, verify,
135+
produce a signed response).
136+
2. Write 10 response files to `/tmp/omc_spawn/response_*.json`.
137+
3. Then I run `omc_fold_back` on the 10 responses and produce a
138+
merged parent-state dict.
139+
140+
That would close the full self-instantiation loop end-to-end
141+
with two live agents. It's the second-half of the round-trip we
142+
already proved works.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# LLM self-instantiation orchestration manifest.
2+
#
3+
# Compress a long context to M3(N) specialists, write each as a
4+
# signed prompt-file. An orchestrator (human or scripted) then
5+
# spawns N LLM sessions, one per file, each seeded with the
6+
# specialist's inherited geometric state.
7+
8+
fn show(label, v) { print(concat_many(label, " = ", to_string(v))); }
9+
fn section(name) { print(""); print(concat_many("=== ", name, " ===")); }
10+
11+
fn make_long_history(n) {
12+
h hist = [];
13+
h i = 0;
14+
while i < n {
15+
arr_push(hist, concat_many("turn ", to_string(i),
16+
": user discusses topic ", to_string(i % 5),
17+
" with assistant; result was outcome ", to_string(i % 3)));
18+
i = i + 1;
19+
}
20+
return hist;
21+
}
22+
23+
fn main() {
24+
print("=== LLM self-instantiation orchestration ===");
25+
print("");
26+
print("Take a long conversation, fold to M3(N) specialists,");
27+
print("write a signed prompt-file per specialist that an");
28+
print("orchestrator can use to spawn N independent LLM sessions.");
29+
30+
h CLAUDE_ID = 18173;
31+
h history = make_long_history(200);
32+
show("input history length", arr_len(history));
33+
34+
section("Self-instantiate");
35+
h manifest = omc_llm_self_instantiate(
36+
history,
37+
"Process this slice of conversation history and report findings.",
38+
"/tmp/omc_spawn",
39+
CLAUDE_ID
40+
);
41+
show("specialists spawned", arr_len(manifest));
42+
43+
section("Manifest preview");
44+
h i = 0;
45+
while i < arr_len(manifest) {
46+
h m = arr_get(manifest, i);
47+
print(concat_many(" Specialist ", to_string(i + 1), "/", to_string(arr_len(manifest)),
48+
" id=", to_string(dict_get(m, "specialist_id")),
49+
" items=", to_string(dict_get(m, "item_count")),
50+
" attractor=", to_string(dict_get(m, "dominant_attractor")),
51+
" → ", dict_get(m, "prompt_path")));
52+
i = i + 1;
53+
}
54+
55+
section("What an orchestrator does next");
56+
print(" for each entry in manifest:");
57+
print(" spawn an LLM process with read_file(entry.prompt_path)");
58+
print(" as its initial prompt;");
59+
print(" collect responses into /tmp/omc_spawn/response_<id>.json;");
60+
print(" call omc_fold_back(parent_mu, parent_sigma, parent_turn,");
61+
print(" responses) to merge results.");
62+
print("");
63+
print("OMC handles the structural + substrate-signed parts.");
64+
print("Process-spawning is left to the orchestrator (Python, shell,");
65+
print("Claude Code Bash tool, etc.) — OMC is honest about not");
66+
print("forking LLMs on its own.");
67+
}
68+
69+
main();

omnimcode-core/src/compiler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl Compiler {
302302
| "omc_search_builtins"
303303
| "omc_find_similar"
304304
| "omc_self_instantiate" | "omc_context_compress"
305+
| "omc_llm_self_instantiate"
305306
// Forward-mode autograd duals (Track 2 — 2026-05-16)
306307
| "dual" | "dual_add" | "dual_sub"
307308
| "dual_mul" | "dual_div" | "dual_neg"

omnimcode-core/src/docs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,13 @@ pub const BUILTINS: &[BuiltinDoc] = &[
11451145
example: "omc_context_compress(conversation_history) // ~log_log(N) specialists",
11461146
unique_to_omc: true,
11471147
},
1148+
BuiltinDoc {
1149+
name: "omc_llm_self_instantiate", category: "onn",
1150+
signature: "(context: string[], task: string, base_dir: string, base_sender_id: int) -> dict[]",
1151+
description: "Orchestration primitive: compress context to M3(N) specialists, write each as a signed prompt file in base_dir, return manifest. An orchestrator spawns N LLM sessions, each seeded with its specialist's inherited geometric state.",
1152+
example: "omc_llm_self_instantiate(history, \"refactor X\", \"/tmp/spawn\", 18173) // [{prompt_path, mu, sigma, ...}]",
1153+
unique_to_omc: true,
1154+
},
11481155
// ---- LLM workflow bundles ----
11491156
BuiltinDoc {
11501157
name: "omc_cheatsheet", category: "llm_workflow",

omnimcode-core/src/interpreter.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7960,6 +7960,104 @@ impl Interpreter {
79607960
}).collect();
79617961
Ok(Value::Array(HArray::from_vec(out)))
79627962
}
7963+
// omc_llm_self_instantiate(context: string[], task: string,
7964+
// base_dir: string, base_sender_id: int)
7965+
// -> dict[] manifest of {specialist_id, prompt_path,
7966+
// specialist_dict}.
7967+
// Compresses N context messages to M3(N) specialists,
7968+
// writes each as a signed prompt-file in base_dir, and
7969+
// returns the manifest. An orchestrator (human or
7970+
// automated) can spawn N LLM sessions, one per file.
7971+
// Each spawned session starts with its specialist's
7972+
// inherited geometric state as the seed.
7973+
//
7974+
// This is the "self-instantiation primitive for LLMs":
7975+
// structural fan-out with substrate-derived state
7976+
// inheritance. Actual LLM-process spawning is out of
7977+
// scope (OMC doesn't fork LLMs), but the manifest gives
7978+
// the orchestrator everything it needs.
7979+
"omc_llm_self_instantiate" => {
7980+
if args.len() < 4 {
7981+
return Err("omc_llm_self_instantiate requires (context: string[], task: string, base_dir: string, base_sender_id: int)".to_string());
7982+
}
7983+
let ctx_v = self.eval_expr(&args[0])?;
7984+
let task = self.eval_expr(&args[1])?.to_display_string();
7985+
let base_dir = self.eval_expr(&args[2])?.to_display_string();
7986+
let base_sender = self.eval_expr(&args[3])?.to_int();
7987+
let messages: Vec<String> = if let Value::Array(arr) = ctx_v {
7988+
arr.items.borrow().iter().map(|v| v.to_display_string()).collect()
7989+
} else {
7990+
return Err("omc_llm_self_instantiate: context must be a string array".to_string());
7991+
};
7992+
let specs = crate::onn::self_instantiate(&messages, &task);
7993+
std::fs::create_dir_all(&base_dir).map_err(|e|
7994+
format!("omc_llm_self_instantiate: mkdir {}: {}", base_dir, e))?;
7995+
let mut manifest: Vec<Value> = Vec::with_capacity(specs.len());
7996+
for s in &specs {
7997+
// Each specialist gets a derived sender_id so the
7998+
// orchestrator can tell them apart.
7999+
let specialist_id = base_sender.wrapping_add(s.fold_index as i64);
8000+
// The prompt embeds the specialist's state + the
8001+
// task hint so the spawned LLM has context.
8002+
let prompt = format!(
8003+
"[Self-instantiated specialist {}/{}]\n\
8004+
Task: {}\n\
8005+
Inherited geometric state:\n\
8006+
- mu (mean φ-resonance): {:.6}\n\
8007+
- sigma: {:.6}\n\
8008+
- dominant_attractor: {}\n\
8009+
- wave_amplitude: {:.6}\n\
8010+
- items_in_slice: {}\n\n\
8011+
Your slice of input:\n{}\n",
8012+
s.fold_index + 1, specs.len(), task,
8013+
s.mu, s.sigma, s.dominant_attractor,
8014+
s.wave_amplitude, s.item_count, s.summary
8015+
);
8016+
let canon = crate::canonical::canonicalize(&prompt)
8017+
.unwrap_or_else(|_| prompt.clone());
8018+
let hash = crate::tokenizer::fnv1a_64(canon.as_bytes());
8019+
let h = HInt::new(hash);
8020+
let (attractor, _) = crate::phi_pi_fib::nearest_attractor_with_dist(hash);
8021+
let moduli = crate::tokenizer::CRT_MODULI;
8022+
let streams = [
8023+
base_sender.rem_euclid(moduli[0]),
8024+
1i64.rem_euclid(moduli[1]), // kind=1 (request)
8025+
hash.rem_euclid(moduli[2]),
8026+
];
8027+
let packed = crate::tokenizer::crt_pack(&streams, moduli).unwrap_or(0);
8028+
let mut msg = std::collections::BTreeMap::new();
8029+
msg.insert("content".to_string(), Value::String(prompt));
8030+
msg.insert("sender_id".to_string(), Value::HInt(HInt::new(base_sender)));
8031+
msg.insert("target_id".to_string(), Value::HInt(HInt::new(specialist_id)));
8032+
msg.insert("kind".to_string(), Value::HInt(HInt::new(1)));
8033+
msg.insert("content_hash".to_string(), Value::HInt(HInt::new(hash)));
8034+
msg.insert("resonance".to_string(), Value::HFloat(h.resonance));
8035+
msg.insert("him_score".to_string(), Value::HFloat(h.him_score));
8036+
msg.insert("attractor".to_string(), Value::HInt(HInt::new(attractor)));
8037+
msg.insert("packed".to_string(), Value::HInt(HInt::new(packed)));
8038+
let msg_value = Value::dict_from(msg);
8039+
let wire = serde_json::to_string(&crate::interpreter::value_to_json(&msg_value))
8040+
.unwrap_or_default();
8041+
let path = format!("{}/specialist_{:02}.json", base_dir, s.fold_index);
8042+
std::fs::write(&path, wire).map_err(|e|
8043+
format!("omc_llm_self_instantiate: write {}: {}", path, e))?;
8044+
// Manifest entry.
8045+
let mut manifest_entry = std::collections::BTreeMap::new();
8046+
manifest_entry.insert("specialist_id".to_string(),
8047+
Value::HInt(HInt::new(specialist_id)));
8048+
manifest_entry.insert("prompt_path".to_string(), Value::String(path));
8049+
manifest_entry.insert("fold_index".to_string(),
8050+
Value::HInt(HInt::new(s.fold_index as i64)));
8051+
manifest_entry.insert("mu".to_string(), Value::HFloat(s.mu));
8052+
manifest_entry.insert("sigma".to_string(), Value::HFloat(s.sigma));
8053+
manifest_entry.insert("dominant_attractor".to_string(),
8054+
Value::HInt(HInt::new(s.dominant_attractor)));
8055+
manifest_entry.insert("item_count".to_string(),
8056+
Value::HInt(HInt::new(s.item_count as i64)));
8057+
manifest.push(Value::dict_from(manifest_entry));
8058+
}
8059+
Ok(Value::Array(HArray::from_vec(manifest)))
8060+
}
79638061
// omc_prompt_agent(target_id, prompt, sender_id, channel_dir?)
79648062
// — write a signed message to target_id's inbox file.
79658063
// Returns the packed message ID. Caller polls for response

0 commit comments

Comments
 (0)