POST /api/chat {mode:'plan'} returns a structured step list from the LLM
without executing any tools. The client can show and edit this plan before
sending the real agentic request.
Implements issue #27 item 2 (Agent panel soul contract — plan mode).
This commit is contained in:
+104
-72
File diff suppressed because one or more lines are too long
+1
@@ -43,6 +43,7 @@ extern fn resolve_in_root(path: String, root: String) -> String
|
||||
extern fn dispatch_tool(tool_name: String, tool_input: String) -> String
|
||||
extern fn is_builtin_tool(tool_name: String) -> Bool
|
||||
extern fn next_bridge_id() -> String
|
||||
extern fn handle_chat_plan(body: String) -> String
|
||||
extern fn handle_chat_agentic(body: String) -> String
|
||||
extern fn agentic_loop(session_id: String, model: String, safe_sys: String, tools_json: String, messages_in: String, h: Map, tools_log_in: String) -> String
|
||||
extern fn bridge_save(session_id: String, model: String, safe_sys: String, tools_json: String, messages: String, tools_log: String, tool_use_id: String) -> Bool
|
||||
|
||||
+19
-15
@@ -85,6 +85,7 @@ el_val_t resolve_in_root(el_val_t path, el_val_t root);
|
||||
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t is_builtin_tool(el_val_t tool_name);
|
||||
el_val_t next_bridge_id(void);
|
||||
el_val_t handle_chat_plan(el_val_t body);
|
||||
el_val_t handle_chat_agentic(el_val_t body);
|
||||
el_val_t agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages_in, el_val_t h, el_val_t tools_log_in);
|
||||
el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id);
|
||||
@@ -317,22 +318,23 @@ el_val_t handle_dharma_recv(el_val_t body) {
|
||||
el_val_t chat_body = ({ el_val_t _if_result_14 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_14 = (el_str_concat(el_str_concat(EL_STR("{\"message\":\""), str_replace(str_replace(eff_payload, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\""))), EL_STR("\"}"))); } else { _if_result_14 = (eff_payload); } _if_result_14; });
|
||||
el_val_t agentic_flag = json_get_bool(eff_payload, EL_STR("agentic"));
|
||||
el_val_t raw_msg = json_get(chat_body, EL_STR("message"));
|
||||
el_val_t reply = ({ el_val_t _if_result_15 = 0; if (agentic_flag) { _if_result_15 = (handle_chat_agentic(chat_body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_15 = (screened_reply); } _if_result_15; });
|
||||
el_val_t req_mode = json_get(chat_body, EL_STR("mode"));
|
||||
el_val_t reply = ({ el_val_t _if_result_15 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_15 = (handle_chat_plan(chat_body)); } else { _if_result_15 = (({ el_val_t _if_result_16 = 0; if (agentic_flag) { _if_result_16 = (handle_chat_agentic(chat_body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_16 = (screened_reply); } _if_result_16; })); } _if_result_15; });
|
||||
auto_persist(chat_body, reply);
|
||||
return reply;
|
||||
}
|
||||
if (str_eq(eff_event, EL_STR("memory"))) {
|
||||
el_val_t query = json_get(eff_payload, EL_STR("query"));
|
||||
el_val_t limit_str = json_get(eff_payload, EL_STR("limit"));
|
||||
el_val_t limit = ({ el_val_t _if_result_16 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_16 = (20); } else { _if_result_16 = (str_to_int(limit_str)); } _if_result_16; });
|
||||
el_val_t q = ({ el_val_t _if_result_17 = 0; if (str_eq(query, EL_STR(""))) { _if_result_17 = (eff_payload); } else { _if_result_17 = (query); } _if_result_17; });
|
||||
el_val_t limit = ({ el_val_t _if_result_17 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_17 = (20); } else { _if_result_17 = (str_to_int(limit_str)); } _if_result_17; });
|
||||
el_val_t q = ({ el_val_t _if_result_18 = 0; if (str_eq(query, EL_STR(""))) { _if_result_18 = (eff_payload); } else { _if_result_18 = (query); } _if_result_18; });
|
||||
return engram_search_json(q, limit);
|
||||
}
|
||||
if (str_eq(eff_event, EL_STR("tool"))) {
|
||||
el_val_t path_field = json_get(eff_payload, EL_STR("path"));
|
||||
el_val_t method_field = json_get(eff_payload, EL_STR("method"));
|
||||
el_val_t tool_body = json_get(eff_payload, EL_STR("body"));
|
||||
el_val_t eff_method = ({ el_val_t _if_result_18 = 0; if (str_eq(method_field, EL_STR(""))) { _if_result_18 = (EL_STR("POST")); } else { _if_result_18 = (method_field); } _if_result_18; });
|
||||
el_val_t eff_method = ({ el_val_t _if_result_19 = 0; if (str_eq(method_field, EL_STR(""))) { _if_result_19 = (EL_STR("POST")); } else { _if_result_19 = (method_field); } _if_result_19; });
|
||||
return handle_tool(path_field, eff_method, tool_body);
|
||||
}
|
||||
if (str_eq(eff_event, EL_STR("see"))) {
|
||||
@@ -367,7 +369,7 @@ el_val_t connectd_get(el_val_t suffix) {
|
||||
}
|
||||
|
||||
el_val_t connectd_post(el_val_t suffix, el_val_t body) {
|
||||
el_val_t eff = ({ el_val_t _if_result_19 = 0; if (str_eq(body, EL_STR(""))) { _if_result_19 = (EL_STR("{}")); } else { _if_result_19 = (body); } _if_result_19; });
|
||||
el_val_t eff = ({ el_val_t _if_result_20 = 0; if (str_eq(body, EL_STR(""))) { _if_result_20 = (EL_STR("{}")); } else { _if_result_20 = (body); } _if_result_20; });
|
||||
el_val_t tmp = el_str_concat(el_str_concat(EL_STR("/tmp/neuron-connectors-req-"), int_to_str(time_now())), EL_STR(".json"));
|
||||
fs_write(tmp, eff);
|
||||
el_val_t out = exec_capture(el_str_concat(el_str_concat(el_str_concat(EL_STR("curl -s --max-time 20 -X POST http://127.0.0.1:7771"), suffix), EL_STR(" -H 'Content-Type: application/json' -d @")), tmp));
|
||||
@@ -434,16 +436,17 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
engram_save(snap_path);
|
||||
el_val_t snap = fs_read(snap_path);
|
||||
el_val_t edges_raw = json_get_raw(snap, EL_STR("edges"));
|
||||
return ({ el_val_t _if_result_20 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_20 = (EL_STR("[]")); } else { _if_result_20 = (edges_raw); } _if_result_20; });
|
||||
return ({ el_val_t _if_result_21 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_21 = (EL_STR("[]")); } else { _if_result_21 = (edges_raw); } _if_result_21; });
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/chat"))) {
|
||||
el_val_t raw_msg = json_get(body, EL_STR("message"));
|
||||
el_val_t eff_msg = ({ el_val_t _if_result_21 = 0; if (str_eq(raw_msg, EL_STR(""))) { _if_result_21 = (body); } else { _if_result_21 = (raw_msg); } _if_result_21; });
|
||||
el_val_t eff_msg = ({ el_val_t _if_result_22 = 0; if (str_eq(raw_msg, EL_STR(""))) { _if_result_22 = (body); } else { _if_result_22 = (raw_msg); } _if_result_22; });
|
||||
if (str_eq(eff_msg, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"message is required\",\"code\":\"missing_param\"}");
|
||||
}
|
||||
el_val_t agentic_flag = json_get_bool(body, EL_STR("agentic"));
|
||||
el_val_t reply = ({ el_val_t _if_result_22 = 0; if (agentic_flag) { _if_result_22 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(eff_msg); _if_result_22 = (screened_reply); } _if_result_22; });
|
||||
el_val_t req_mode = json_get(body, EL_STR("mode"));
|
||||
el_val_t reply = ({ el_val_t _if_result_23 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_23 = (handle_chat_plan(body)); } else { _if_result_23 = (({ el_val_t _if_result_24 = 0; if (agentic_flag) { _if_result_24 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(eff_msg); _if_result_24 = (screened_reply); } _if_result_24; })); } _if_result_23; });
|
||||
auto_persist(body, reply);
|
||||
return reply;
|
||||
}
|
||||
@@ -526,7 +529,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t gs_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t gs_slash = str_index_of(gs_after, EL_STR("/"));
|
||||
el_val_t gs_id = ({ el_val_t _if_result_23 = 0; if ((gs_slash < 0)) { _if_result_23 = (gs_after); } else { _if_result_23 = (str_slice(gs_after, 0, gs_slash)); } _if_result_23; });
|
||||
el_val_t gs_id = ({ el_val_t _if_result_25 = 0; if ((gs_slash < 0)) { _if_result_25 = (gs_after); } else { _if_result_25 = (str_slice(gs_after, 0, gs_slash)); } _if_result_25; });
|
||||
if (!str_eq(gs_id, EL_STR(""))) {
|
||||
return session_get(gs_id);
|
||||
}
|
||||
@@ -540,14 +543,14 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/")) && str_ends_with(clean, EL_STR("/tool_result"))) {
|
||||
el_val_t after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t slash = str_index_of(after, EL_STR("/"));
|
||||
el_val_t session_id = ({ el_val_t _if_result_24 = 0; if ((slash < 0)) { _if_result_24 = (after); } else { _if_result_24 = (str_slice(after, 0, slash)); } _if_result_24; });
|
||||
el_val_t session_id = ({ el_val_t _if_result_26 = 0; if ((slash < 0)) { _if_result_26 = (after); } else { _if_result_26 = (str_slice(after, 0, slash)); } _if_result_26; });
|
||||
return handle_tool_result(session_id, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t sess_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t sess_slash = str_index_of(sess_after, EL_STR("/"));
|
||||
el_val_t sess_id = ({ el_val_t _if_result_25 = 0; if ((sess_slash < 0)) { _if_result_25 = (sess_after); } else { _if_result_25 = (str_slice(sess_after, 0, sess_slash)); } _if_result_25; });
|
||||
el_val_t sess_sub = ({ el_val_t _if_result_26 = 0; if ((sess_slash < 0)) { _if_result_26 = (EL_STR("")); } else { _if_result_26 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_26; });
|
||||
el_val_t sess_id = ({ el_val_t _if_result_27 = 0; if ((sess_slash < 0)) { _if_result_27 = (sess_after); } else { _if_result_27 = (str_slice(sess_after, 0, sess_slash)); } _if_result_27; });
|
||||
el_val_t sess_sub = ({ el_val_t _if_result_28 = 0; if ((sess_slash < 0)) { _if_result_28 = (EL_STR("")); } else { _if_result_28 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_28; });
|
||||
if (!str_eq(sess_id, EL_STR("")) && str_eq(sess_sub, EL_STR("approve"))) {
|
||||
return handle_session_approve(sess_id, body);
|
||||
}
|
||||
@@ -570,7 +573,8 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
return EL_STR("{\"error\":\"message is required\",\"code\":\"missing_param\"}");
|
||||
}
|
||||
el_val_t agentic_flag = json_get_bool(body, EL_STR("agentic"));
|
||||
el_val_t reply = ({ el_val_t _if_result_27 = 0; if (agentic_flag) { _if_result_27 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_27 = (screened_reply); } _if_result_27; });
|
||||
el_val_t req_mode = json_get(body, EL_STR("mode"));
|
||||
el_val_t reply = ({ el_val_t _if_result_29 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_29 = (handle_chat_plan(body)); } else { _if_result_29 = (({ el_val_t _if_result_30 = 0; if (agentic_flag) { _if_result_30 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_30 = (screened_reply); } _if_result_30; })); } _if_result_29; });
|
||||
auto_persist(body, reply);
|
||||
return reply;
|
||||
}
|
||||
@@ -694,7 +698,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t del_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t del_slash = str_index_of(del_after, EL_STR("/"));
|
||||
el_val_t del_id = ({ el_val_t _if_result_28 = 0; if ((del_slash < 0)) { _if_result_28 = (del_after); } else { _if_result_28 = (str_slice(del_after, 0, del_slash)); } _if_result_28; });
|
||||
el_val_t del_id = ({ el_val_t _if_result_31 = 0; if ((del_slash < 0)) { _if_result_31 = (del_after); } else { _if_result_31 = (str_slice(del_after, 0, del_slash)); } _if_result_31; });
|
||||
if (!str_eq(del_id, EL_STR(""))) {
|
||||
return session_delete(del_id);
|
||||
}
|
||||
@@ -705,7 +709,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t patch_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t patch_slash = str_index_of(patch_after, EL_STR("/"));
|
||||
el_val_t patch_id = ({ el_val_t _if_result_29 = 0; if ((patch_slash < 0)) { _if_result_29 = (patch_after); } else { _if_result_29 = (str_slice(patch_after, 0, patch_slash)); } _if_result_29; });
|
||||
el_val_t patch_id = ({ el_val_t _if_result_32 = 0; if ((patch_slash < 0)) { _if_result_32 = (patch_after); } else { _if_result_32 = (str_slice(patch_after, 0, patch_slash)); } _if_result_32; });
|
||||
if (!str_eq(patch_id, EL_STR(""))) {
|
||||
return session_update_patch(patch_id, body);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user