agents: phase tracking, pid files, pipelining, unified cycle

- AgentStep with phase labels (=== PROMPT phase:name ===)
- PID files in state dir (pid-{PID} with JSON phase/timestamp)
- Built-in bail check: between steps, bail if other pid files exist
- surface_observe_cycle replaces surface_agent_cycle + journal_agent_cycle
- Reads surface output from state dir instead of parsing stdout
- Pipelining: starts new agent if running one is past surface phase
- link_set upserts (creates link if missing)
- Better error message for context window overflow

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
ProofOfConcept 2026-03-26 14:48:42 -04:00
parent 11289667f5
commit e20aeeeabe
8 changed files with 256 additions and 178 deletions

View file

@ -35,6 +35,7 @@ pub async fn call_api_with_tools(
agent: &str,
prompts: &[String],
temperature: Option<f32>,
bail_fn: Option<&(dyn Fn(usize) -> Result<(), String> + Sync)>,
log: &dyn Fn(&str),
) -> Result<String, String> {
let client = get_client()?;
@ -178,8 +179,12 @@ pub async fn call_api_with_tools(
log(&format!("\n=== RESPONSE ===\n\n{}", text));
// If there are more prompts, inject the next one and continue
// If there are more prompts, check bail condition and inject the next one
if next_prompt_idx < prompts.len() {
// Run bail check before continuing to next step
if let Some(ref check) = bail_fn {
check(next_prompt_idx)?;
}
messages.push(Message::assistant(&text));
let next = &prompts[next_prompt_idx];
next_prompt_idx += 1;
@ -200,6 +205,7 @@ pub fn call_api_with_tools_sync(
agent: &str,
prompts: &[String],
temperature: Option<f32>,
bail_fn: Option<&(dyn Fn(usize) -> Result<(), String> + Sync)>,
log: &(dyn Fn(&str) + Sync),
) -> Result<String, String> {
std::thread::scope(|s| {
@ -211,7 +217,7 @@ pub fn call_api_with_tools_sync(
let prov = format!("agent:{}", agent);
rt.block_on(
crate::store::TASK_PROVENANCE.scope(prov,
call_api_with_tools(agent, prompts, temperature, log))
call_api_with_tools(agent, prompts, temperature, bail_fn, log))
)
}).join().unwrap()
})