Fix ELP topic selection and replace broken agentic LLM call

elp-input.el: walk frame_nodes to pick the first node whose content
contains the query topic (case-insensitive) rather than always taking
index 0 — prevents the always-high-salience CGI architecture memory
from hijacking every ELP response.

chat.el: rewrite handle_chat_agentic to run the tool loop natively in
El using http_post_with_headers + Map headers, bypassing the broken
llm_call_agentic(model, system, message, tools) C binding that cast a
JSON String as an ElList and never serialized tools. New impl supports
up to 8 tool-use iterations with read_file, write_file, web_get,
search_memory, and run_command dispatch.
This commit is contained in:
Will Anderson
2026-05-03 11:50:18 -05:00
parent 2622bb04bd
commit af2ce3ddf3
2 changed files with 146 additions and 7 deletions
+18 -3
View File
@@ -108,9 +108,24 @@ fn handle_elp_chat(body: String) -> String {
let frame_nodes: String = if str_eq(kept_json, "") { "[]" } else { "[" + kept_json + "]" }
// Reason
// Extract the patient from the top activated node's content.
// Trim to 200 chars so it fits cleanly in a generated sentence.
let top_node: String = json_array_get(frame_nodes, 0)
// Walk frame_nodes to find the first node whose content contains the topic.
// This prevents the always-high-salience CGI architecture node from
// dominating every response regardless of what was asked.
let fn_total: Int = json_array_len(frame_nodes)
let fn_i: Int = 0
let topic_lower: String = str_to_lower(topic)
let found_node: String = ""
while fn_i < fn_total {
let candidate: String = json_array_get(frame_nodes, fn_i)
let cand_content: String = json_get(candidate, "content")
let cand_lower: String = str_to_lower(cand_content)
let matches: Bool = str_contains(cand_lower, topic_lower)
if matches && str_eq(found_node, "") {
let found_node = candidate
}
let fn_i = fn_i + 1
}
let top_node: String = if str_eq(found_node, "") { json_array_get(frame_nodes, 0) } else { found_node }
let top_raw: String = json_get(top_node, "content")
let patient_raw: String = if str_eq(top_raw, "") { topic } else {
if str_len(top_raw) > 200 { str_slice(top_raw, 0, 200) } else { top_raw }