v0.4.0
Highlights
Adds a cooperative post-tool-result yield point to the agent loop, so hosts can interject a user message between tool rounds without cancelling the turn.
What's Changed
LoopInterrupt::AfterToolResult
After every tool round (i.e. once all tool calls from the previous assistant message have results in the transcript, and the driver is about to invoke the model again), LoopDriver::next() yields LoopStep::Interrupt(LoopInterrupt::AfterToolResult(info)). The host can:
- Ignore it — call
driver.next()again and the turn resumes as if the interrupt never fired. The interrupt is non-blocking;is_blocking()returnsfalse. - Interject — call
info.submit(driver, items)to push user items into the pending queue before resuming.
use agentkit_core::{Item, ItemKind};
use agentkit_loop::{LoopDriver, LoopInterrupt, LoopStep, ModelSession};
async fn run<S: ModelSession>(driver: &mut LoopDriver<S>) -> Result<(), agentkit_loop::LoopError> {
loop {
match driver.next().await? {
LoopStep::Interrupt(LoopInterrupt::AfterToolResult(info)) => {
// The model just got tool results back. Steer it before the
// next model call, e.g. correct an obvious mistake the tool
// surfaced.
info.submit(driver, vec![Item::text(
ItemKind::User,
"Use ripgrep with --hidden next time, that path was excluded.",
)])?;
}
LoopStep::Interrupt(other) if other.is_blocking() => {
// Approvals etc. — handle as before.
break;
}
LoopStep::Interrupt(_) => continue,
LoopStep::Finished(_) => break,
}
}
Ok(())
}The ToolRoundInfo handle carries the session_id, turn_id, and transcript length at the yield point, and is consumed on submit so the same yield can't accept input twice.
Why
Previously the only way to influence a turn mid-flight was an approval interrupt (blocking) or cancelling the whole turn. Coding agents and CLIs need a softer hook — "the tool just returned, let me nudge before the next model call" — without the model having already started writing its reply.
Commits
- feat: post-tool-result user interjection (5823190)
Full Changelog: v0.3.1...v0.4.0