feat: Runner und SQLite-Speicher

runner.rs: Plan in Reihenfolge Modell/Aufgabe/Wiederholung, Aufwärmen je
Modell, frische Sandbox pro Lauf, check.sh im selben Container, Abbruch
und Fortsetzen über die Datenbank. store.rs: Schema nach SPEC 8, Lauf und
Schritte in einer Transaktion. Agent-Loop bekommt Abbruchflag.
Ende-zu-Ende gegen srv04 mit qwen3:0.6b grün; Fortsetzen überspringt
fertige Läufe. 38 Unit-Tests grün.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 19:35:02 +01:00
parent e69f3be35b
commit c8290aeb94
8 changed files with 872 additions and 4 deletions

View File

@ -13,6 +13,7 @@ use crate::sandbox::Sandbox;
use base64::Engine;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant};
pub const WORK_DIR: &str = "/work";
@ -119,6 +120,8 @@ pub struct RunOutcome {
pub duration_ms: u128,
pub time_to_first_tool_ms: Option<u128>,
pub transcript: Vec<Message>,
/// Gesetzt, wenn der Lauf von außen abgebrochen wurde. Dann ist das Ergebnis nicht gültig.
pub cancelled: bool,
}
/// Werkzeug-Schema für Ollama.
@ -288,6 +291,17 @@ pub fn run_agent(
ws: &dyn Workspace,
prompt: &str,
limits: &AgentLimits,
) -> RunOutcome {
run_agent_cancellable(model, ws, prompt, limits, &AtomicBool::new(false))
}
/// Wie `run_agent`, bricht aber ab, sobald `cancel` gesetzt ist. Der Lauf gilt dann als `cancelled`.
pub fn run_agent_cancellable(
model: &dyn ModelClient,
ws: &dyn Workspace,
prompt: &str,
limits: &AgentLimits,
cancel: &AtomicBool,
) -> RunOutcome {
let started = Instant::now();
let tools = tool_schemas();
@ -302,6 +316,7 @@ pub fn run_agent(
duration_ms: 0,
time_to_first_tool_ms: None,
transcript: vec![],
cancelled: false,
};
// Letzter Tool-Call und Anzahl gleicher Wiederholungen mit gleichem Ergebnis.
@ -309,6 +324,10 @@ pub fn run_agent(
let mut repeats: u32 = 0;
let class = loop {
if cancel.load(Ordering::SeqCst) {
out.cancelled = true;
break ErrorClass::Ok;
}
if out.steps >= limits.max_steps {
break ErrorClass::MaxSteps;
}