Add GUI agent mode: the model acts via a universal shell_exec tool
- agent:🐚 native shell_exec (bash -lc, cwd, timeout, 64 KiB output cap)
behind a ShellRunner seam — base/host mode now; an isolated Docker-MCP runner
plugs in later without touching the loop. OpenAI function declaration included.
- agent::run_loop: bounded model<->tool orchestration, generic over the model
step so it is unit-testable without the engine. Persists the full trajectory
(assistant tool-call turns + role:tool results + final answer) and emits
tool_call / tool_result / final / error progress events.
- api::sessions: POST .../chat with agent:true drives the loop and streams the
events as SSE; the GUI shows commands + output inline (observability, no gate).
- store: messages gains tool_call_id; an idempotent migration adds the column to
pre-existing databases (CREATE TABLE IF NOT EXISTS does not alter them).
- web: robot agent toggle, tool-call/output blocks, history rendering of tool
turns; inline favicon to silence the favicon 404.
Validated LIVE on engine 0.1.67: the model called shell_exec('uname -a'), the
host executed it, and the model reported the output; trajectory persisted; GUI
verified by browser (toggle, tool block, output, final answer). 106 tests +
2 ignored green, clippy/fmt clean. Isolated mode (user-provided Docker container)
is the next step.
This commit is contained in:
1 parent
e29878bb3d
commit
8979201139
10 files changed
+994
-43
No files matched your search
@@ -265,3 +265,37 @@ async fn unknown_session_is_404() {
|
||||
.await;
|
||||
assert_eq!(st, StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn agent_mode_streams_events_and_persists() {
|
||||
let (app, store) = build_app().await;
|
||||
let id = create_session(&app).await;
|
||||
// The mock answers directly (no tool calls), exercising the agent final path.
|
||||
let (st, text) = req(
|
||||
&app,
|
||||
Method::POST,
|
||||
&format!("/api/sessions/{id}/chat"),
|
||||
Some(serde_json::json!({"content": "hi", "agent": true})),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(st, StatusCode::OK, "{text}");
|
||||
let data: Vec<&str> = text
|
||||
.lines()
|
||||
.filter(|l| l.starts_with("data: "))
|
||||
.map(|l| &l["data: ".len()..])
|
||||
.collect();
|
||||
assert_eq!(data.last().copied(), Some("[DONE]"));
|
||||
let mut saw_final = false;
|
||||
for line in &data[..data.len() - 1] {
|
||||
let v: serde_json::Value = serde_json::from_str(line).unwrap();
|
||||
if v["type"] == "final" {
|
||||
saw_final = true;
|
||||
assert_eq!(v["response"]["choices"][0]["message"]["content"], "efghi");
|
||||
}
|
||||
}
|
||||
assert!(saw_final, "no final agent event: {text}");
|
||||
// The final assistant turn is persisted.
|
||||
let msgs = store.messages(&id).unwrap();
|
||||
assert_eq!(msgs.last().unwrap().role, "assistant");
|
||||
assert_eq!(msgs.last().unwrap().content, "efghi");
|
||||
}
|
||||
Reference in new issue
Block a user