Sync from GitHub: 87142a222fc1cc85c27aacef69860f9a8795ac97
Browse files
app.py
CHANGED
|
@@ -5,6 +5,20 @@ The organism. NeuroGraph substrate + KISS bucket + Pith bucket +
|
|
| 5 |
Splat-Lenia + BitNet model. On CPU. Gets smarter over time.
|
| 6 |
|
| 7 |
# ---- Changelog ----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# [2026-04-06] Claude Code (Opus 4.6) β Full NeuroGraph organism integration
|
| 9 |
# [2026-03-31] Claude Code (Opus 4.6) β Switch to BitNet 2B for CPU-native inference
|
| 10 |
# [2026-03-29] Claude Code (Opus 4.6) β ZeroGPU compatible, model at startup
|
|
@@ -806,18 +820,12 @@ def on_send(message, history):
|
|
| 806 |
# ββ 4. Pith bucket β extract relevant context from the River ββ
|
| 807 |
pith_context, pith_ids = organism.pith_extract_with_ids(message, max_context=5)
|
| 808 |
|
| 809 |
-
# Pith
|
| 810 |
-
#
|
| 811 |
-
#
|
| 812 |
-
#
|
| 813 |
-
|
| 814 |
-
substrate_ctx = "\n".join(pith_context)
|
| 815 |
-
if sys_ctx:
|
| 816 |
-
sys_ctx = substrate_ctx + "\n\n" + sys_ctx
|
| 817 |
-
else:
|
| 818 |
-
sys_ctx = substrate_ctx
|
| 819 |
|
| 820 |
-
# Build prompt β Pith context replaces old history
|
| 821 |
# Only send recent messages. The substrate carries the rest.
|
| 822 |
# Always trim to recent window. The substrate + KISS carry older context.
|
| 823 |
recent_window = 6 # 3 turns of user+assistant
|
|
@@ -826,6 +834,22 @@ def on_send(message, history):
|
|
| 826 |
else:
|
| 827 |
recent_msgs = messages_nw
|
| 828 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 829 |
prompt_msgs = []
|
| 830 |
if sys_ctx:
|
| 831 |
prompt_msgs.append({"role": "system", "content": sys_ctx})
|
|
@@ -1051,11 +1075,10 @@ def on_benchmark(num_turns):
|
|
| 1051 |
kiss_r = nw_kiss.filter_context(nw_msgs, system_prompt)
|
| 1052 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1053 |
|
| 1054 |
-
# Pith Born rule extraction from substrate
|
|
|
|
|
|
|
| 1055 |
pith_context = nw_organism.pith_extract(prompt_text, max_context=5)
|
| 1056 |
-
if pith_context:
|
| 1057 |
-
substrate_ctx = "\n".join(pith_context)
|
| 1058 |
-
sys_ctx = substrate_ctx + "\n\n" + sys_ctx if sys_ctx else substrate_ctx
|
| 1059 |
|
| 1060 |
# Trim old messages β always, not gated on Pith.
|
| 1061 |
# The substrate + KISS carry what the older messages contained.
|
|
@@ -1067,6 +1090,22 @@ def on_benchmark(num_turns):
|
|
| 1067 |
else:
|
| 1068 |
recent = nw_msgs
|
| 1069 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1070 |
prompt_nw = tokenizer.apply_chat_template(
|
| 1071 |
[{"role": "system", "content": sys_ctx}] + recent if sys_ctx else recent,
|
| 1072 |
tokenize=False, add_generation_prompt=True,
|
|
@@ -1430,12 +1469,27 @@ def on_interleaved_benchmark(
|
|
| 1430 |
|
| 1431 |
kiss_r = nw_kiss_inst.filter_context(nw_msgs, system_prompt)
|
| 1432 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1433 |
-
|
| 1434 |
-
|
| 1435 |
-
|
|
|
|
| 1436 |
|
| 1437 |
recent_window = 6
|
| 1438 |
recent = nw_msgs[-recent_window:] if len(nw_msgs) > recent_window else nw_msgs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1439 |
prompt_nw = tokenizer.apply_chat_template(
|
| 1440 |
[{"role": "system", "content": sys_ctx}] + recent if sys_ctx else recent,
|
| 1441 |
tokenize=False, add_generation_prompt=True,
|
|
|
|
| 5 |
Splat-Lenia + BitNet model. On CPU. Gets smarter over time.
|
| 6 |
|
| 7 |
# ---- Changelog ----
|
| 8 |
+
# [2026-05-16] Claude Opus 4.7 (1M ctx) β Pith β user-turn labeled context block (3 sites)
|
| 9 |
+
# Root cause of Run 48's 24/24 degenerate BitNet output: pith was being
|
| 10 |
+
# injected into the system role slot via sys_ctx = "\n".join(pith) + sys.
|
| 11 |
+
# Chat-tuned models are trained with the system slot carrying instructions,
|
| 12 |
+
# not lists of prior user questions. BitNet was treating retrieved pith
|
| 13 |
+
# as questions to respond to, echoing them back and leaking chat-template
|
| 14 |
+
# fragments. Fix: pith content now goes in a clearly-labeled context block
|
| 15 |
+
# inside the LAST user turn for THIS turn's prompt only; bare user query
|
| 16 |
+
# persists in nw_msgs/messages_nw so next turn's recent_window isn't
|
| 17 |
+
# polluted. System slot stays canonical (instructions only). Plain-text
|
| 18 |
+
# labels, no delimiter tokens (per feedback_pith_presentation_layer memory).
|
| 19 |
+
# Three call sites updated identically: on_send live chat, first benchmark
|
| 20 |
+
# loop, interleaved benchmark loop. Universal RAG pattern β applies to
|
| 21 |
+
# any future LLM consumer of substrate-surfaced content.
|
| 22 |
# [2026-04-06] Claude Code (Opus 4.6) β Full NeuroGraph organism integration
|
| 23 |
# [2026-03-31] Claude Code (Opus 4.6) β Switch to BitNet 2B for CPU-native inference
|
| 24 |
# [2026-03-29] Claude Code (Opus 4.6) β ZeroGPU compatible, model at startup
|
|
|
|
| 820 |
# ββ 4. Pith bucket β extract relevant context from the River ββ
|
| 821 |
pith_context, pith_ids = organism.pith_extract_with_ids(message, max_context=5)
|
| 822 |
|
| 823 |
+
# Pith does NOT go in the system slot. System slot is for the model's
|
| 824 |
+
# identity/instructions; chat-tuned models treat retrieved questions
|
| 825 |
+
# placed there as things to respond to (Run 48 root cause). Instead,
|
| 826 |
+
# pith goes in a labeled context block inside the LAST user turn for
|
| 827 |
+
# THIS turn's prompt only β see feedback_pith_presentation_layer memory.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 828 |
|
|
|
|
| 829 |
# Only send recent messages. The substrate carries the rest.
|
| 830 |
# Always trim to recent window. The substrate + KISS carry older context.
|
| 831 |
recent_window = 6 # 3 turns of user+assistant
|
|
|
|
| 834 |
else:
|
| 835 |
recent_msgs = messages_nw
|
| 836 |
|
| 837 |
+
# Enrich the LAST user message for THIS turn's prompt only.
|
| 838 |
+
# messages_nw stays clean (bare query persists in history) so next
|
| 839 |
+
# turn's recent_window isn't polluted with this turn's pith.
|
| 840 |
+
if pith_context:
|
| 841 |
+
pith_block = "\n".join(f" - {p}" for p in pith_context)
|
| 842 |
+
enriched_query = (
|
| 843 |
+
"Some context that may be relevant (recalled from earlier "
|
| 844 |
+
"related conversations; these are reference material, not "
|
| 845 |
+
"questions to answer):\n"
|
| 846 |
+
f"{pith_block}\n\n"
|
| 847 |
+
f"My actual question: {message}"
|
| 848 |
+
)
|
| 849 |
+
recent_msgs = list(recent_msgs[:-1]) + [
|
| 850 |
+
{"role": "user", "content": enriched_query}
|
| 851 |
+
]
|
| 852 |
+
|
| 853 |
prompt_msgs = []
|
| 854 |
if sys_ctx:
|
| 855 |
prompt_msgs.append({"role": "system", "content": sys_ctx})
|
|
|
|
| 1075 |
kiss_r = nw_kiss.filter_context(nw_msgs, system_prompt)
|
| 1076 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1077 |
|
| 1078 |
+
# Pith Born rule extraction from substrate. Pith does NOT go in
|
| 1079 |
+
# sys_ctx β it goes in a labeled context block in the last user
|
| 1080 |
+
# turn below (see feedback_pith_presentation_layer memory).
|
| 1081 |
pith_context = nw_organism.pith_extract(prompt_text, max_context=5)
|
|
|
|
|
|
|
|
|
|
| 1082 |
|
| 1083 |
# Trim old messages β always, not gated on Pith.
|
| 1084 |
# The substrate + KISS carry what the older messages contained.
|
|
|
|
| 1090 |
else:
|
| 1091 |
recent = nw_msgs
|
| 1092 |
|
| 1093 |
+
# Enrich the LAST user message for THIS turn's prompt only.
|
| 1094 |
+
# nw_msgs stays clean (bare query persists in history) so next
|
| 1095 |
+
# turn's recent_window isn't polluted with this turn's pith.
|
| 1096 |
+
if pith_context:
|
| 1097 |
+
pith_block = "\n".join(f" - {p}" for p in pith_context)
|
| 1098 |
+
enriched_query = (
|
| 1099 |
+
"Some context that may be relevant (recalled from earlier "
|
| 1100 |
+
"related conversations; these are reference material, not "
|
| 1101 |
+
"questions to answer):\n"
|
| 1102 |
+
f"{pith_block}\n\n"
|
| 1103 |
+
f"My actual question: {prompt_text}"
|
| 1104 |
+
)
|
| 1105 |
+
recent = list(recent[:-1]) + [
|
| 1106 |
+
{"role": "user", "content": enriched_query}
|
| 1107 |
+
]
|
| 1108 |
+
|
| 1109 |
prompt_nw = tokenizer.apply_chat_template(
|
| 1110 |
[{"role": "system", "content": sys_ctx}] + recent if sys_ctx else recent,
|
| 1111 |
tokenize=False, add_generation_prompt=True,
|
|
|
|
| 1469 |
|
| 1470 |
kiss_r = nw_kiss_inst.filter_context(nw_msgs, system_prompt)
|
| 1471 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1472 |
+
# Pith does NOT go in sys_ctx β see feedback_pith_presentation_layer
|
| 1473 |
+
# memory. It goes in a labeled context block in the last user turn
|
| 1474 |
+
# below for THIS turn's prompt only; nw_msgs stays clean so next
|
| 1475 |
+
# turn's recent_window isn't polluted with this turn's pith.
|
| 1476 |
|
| 1477 |
recent_window = 6
|
| 1478 |
recent = nw_msgs[-recent_window:] if len(nw_msgs) > recent_window else nw_msgs
|
| 1479 |
+
|
| 1480 |
+
if pith_context:
|
| 1481 |
+
pith_block = "\n".join(f" - {p}" for p in pith_context)
|
| 1482 |
+
enriched_query = (
|
| 1483 |
+
"Some context that may be relevant (recalled from earlier "
|
| 1484 |
+
"related conversations; these are reference material, not "
|
| 1485 |
+
"questions to answer):\n"
|
| 1486 |
+
f"{pith_block}\n\n"
|
| 1487 |
+
f"My actual question: {prompt_text}"
|
| 1488 |
+
)
|
| 1489 |
+
recent = list(recent[:-1]) + [
|
| 1490 |
+
{"role": "user", "content": enriched_query}
|
| 1491 |
+
]
|
| 1492 |
+
|
| 1493 |
prompt_nw = tokenizer.apply_chat_template(
|
| 1494 |
[{"role": "system", "content": sys_ctx}] + recent if sys_ctx else recent,
|
| 1495 |
tokenize=False, add_generation_prompt=True,
|