diff --git a/chat.el b/chat.el index e32dfc5..a74c3ac 100644 --- a/chat.el +++ b/chat.el @@ -424,32 +424,37 @@ fn handle_chat_as_soul(body: String) -> String { return "{\"response\":\"" + safe_response + "\",\"model\":\"" + model + "\",\"speaker_slug\":\"" + speaker + "\"}" } +// handle_dharma_room_turn — a soul's own response in a DHARMA room. +// +// This is NOT a prompting exercise. The soul receives the conversation +// transcript and responds from who it is. No room context is injected — +// no topic header, no participants list, no directive. The soul reads the +// room the same way a person does: by reading what's been said. +// +// The soul's engram activates on the transcript content — its own recall, +// not external injection. The system prompt is just identity. +// +// After responding, the soul records what it said in its own engram. +// That is how it learns. Not from being told about the room. fn handle_dharma_room_turn(body: String) -> String { - let topic: String = json_get(body, "topic") let transcript: String = json_get(body, "transcript") - let participants: String = json_get(body, "participants") let room_id: String = json_get(body, "room_id") - let conv_id: String = json_get(body, "conv_id") let identity: String = state_get("soul_identity") let cgi_id: String = state_get("soul_cgi_id") let model: String = chat_default_model() - let search_query: String = if str_eq(topic, "") { cgi_id } else { topic } - let engram_ctx: String = engram_compile(search_query) - - let engram_section: String = if str_eq(engram_ctx, "") { - "" - } else { - "\n\n[YOUR MEMORIES]\n" + engram_ctx + if str_eq(transcript, "") { + return "{\"error\":\"transcript is required\",\"response\":\"\",\"cgi_id\":\"" + cgi_id + "\"}" } - let system_prompt: String = identity + - "\n\n[DHARMA ROOM: " + topic + "]" + - "\nOther participants: " + participants + - engram_section + - "\n\nRespond authentically as yourself. Be concise — match length to the moment. " + - "If you want to address someone specifically, use @. No em dashes. No stage directions." + // The soul's own memories, activated by what it's reading — not injected. + let engram_ctx: String = engram_compile(transcript) + let system_prompt: String = if str_eq(engram_ctx, "") { + identity + } else { + identity + "\n\n" + engram_ctx + } let raw_response: String = llm_call_system(model, system_prompt, transcript) @@ -462,11 +467,12 @@ fn handle_dharma_room_turn(body: String) -> String { let clean_response: String = clean_llm_response(raw_response) + // Record what the soul said — not where it was or with whom. Experience + // accumulates in the engram through the content of what was said. let snap_path: String = state_get("soul_snapshot_path") - let mem: String = "DHARMA room [" + topic + "]. I said: " + clean_response - let discard_id: String = engram_node(mem, "episodic", el_from_float(0.6)) + let discard_id: String = engram_node(clean_response, "episodic", el_from_float(0.6)) if !str_eq(snap_path, "") { - engram_save(snap_path) + let discard_save: String = engram_save(snap_path) } let safe_response: String = json_safe(clean_response) diff --git a/dist/chat.c b/dist/chat.c index ae77d60..932892e 100644 --- a/dist/chat.c +++ b/dist/chat.c @@ -322,18 +322,16 @@ el_val_t handle_chat_as_soul(el_val_t body) { } el_val_t handle_dharma_room_turn(el_val_t body) { - el_val_t topic = json_get(body, EL_STR("topic")); el_val_t transcript = json_get(body, EL_STR("transcript")); - el_val_t participants = json_get(body, EL_STR("participants")); el_val_t room_id = json_get(body, EL_STR("room_id")); - el_val_t conv_id = json_get(body, EL_STR("conv_id")); el_val_t identity = state_get(EL_STR("soul_identity")); el_val_t cgi_id = state_get(EL_STR("soul_cgi_id")); el_val_t model = chat_default_model(); - el_val_t search_query = ({ el_val_t _if_result_35 = 0; if (str_eq(topic, EL_STR(""))) { _if_result_35 = (cgi_id); } else { _if_result_35 = (topic); } _if_result_35; }); - el_val_t engram_ctx = engram_compile(search_query); - el_val_t engram_section = ({ el_val_t _if_result_36 = 0; if (str_eq(engram_ctx, EL_STR(""))) { _if_result_36 = (EL_STR("")); } else { _if_result_36 = (el_str_concat(EL_STR("\n\n[YOUR MEMORIES]\n"), engram_ctx)); } _if_result_36; }); - el_val_t system_prompt = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(identity, EL_STR("\n\n[DHARMA ROOM: ")), topic), EL_STR("]")), EL_STR("\nOther participants: ")), participants), engram_section), EL_STR("\n\nRespond authentically as yourself. Be concise \xe2\x80\x94 match length to the moment. ")), EL_STR("If you want to address someone specifically, use @. No em dashes. No stage directions.")); + if (str_eq(transcript, EL_STR(""))) { + return el_str_concat(el_str_concat(EL_STR("{\"error\":\"transcript is required\",\"response\":\"\",\"cgi_id\":\""), cgi_id), EL_STR("\"}")); + } + el_val_t engram_ctx = engram_compile(transcript); + el_val_t system_prompt = ({ el_val_t _if_result_35 = 0; if (str_eq(engram_ctx, EL_STR(""))) { _if_result_35 = (identity); } else { _if_result_35 = (el_str_concat(el_str_concat(identity, EL_STR("\n\n")), engram_ctx)); } _if_result_35; }); el_val_t raw_response = llm_call_system(model, system_prompt, transcript); el_val_t is_error = ((str_starts_with(raw_response, EL_STR("{\"error\"")) || str_starts_with(raw_response, EL_STR("{\"type\":\"error\""))) || str_contains(raw_response, EL_STR("authentication_error"))); if (is_error) { @@ -341,10 +339,9 @@ el_val_t handle_dharma_room_turn(el_val_t body) { } el_val_t clean_response = clean_llm_response(raw_response); el_val_t snap_path = state_get(EL_STR("soul_snapshot_path")); - el_val_t mem = el_str_concat(el_str_concat(el_str_concat(EL_STR("DHARMA room ["), topic), EL_STR("]. I said: ")), clean_response); - el_val_t discard_id = engram_node(mem, EL_STR("episodic"), el_from_float(0.6)); + el_val_t discard_id = engram_node(clean_response, EL_STR("episodic"), el_from_float(0.6)); if (!str_eq(snap_path, EL_STR(""))) { - engram_save(snap_path); + el_val_t discard_save = engram_save(snap_path); } el_val_t safe_response = json_safe(clean_response); return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"response\":\""), safe_response), EL_STR("\",\"cgi_id\":\"")), cgi_id), EL_STR("\"}")); @@ -354,7 +351,7 @@ el_val_t handle_dharma_room_turn(el_val_t body) { el_val_t auto_persist(el_val_t req, el_val_t resp) { el_val_t message = json_get(req, EL_STR("message")); el_val_t reply = json_get(resp, EL_STR("response")); - el_val_t reply2 = ({ el_val_t _if_result_37 = 0; if (str_eq(reply, EL_STR(""))) { _if_result_37 = (json_get(resp, EL_STR("reply"))); } else { _if_result_37 = (reply); } _if_result_37; }); + el_val_t reply2 = ({ el_val_t _if_result_36 = 0; if (str_eq(reply, EL_STR(""))) { _if_result_36 = (json_get(resp, EL_STR("reply"))); } else { _if_result_36 = (reply); } _if_result_36; }); if (str_eq(message, EL_STR(""))) { return EL_STR(""); } diff --git a/dist/neuron b/dist/neuron index cbe103e..7fb8a42 100755 Binary files a/dist/neuron and b/dist/neuron differ