Skip to main content

Crate agent_deadline

Crate agent_deadline 

Source
Expand description

Cooperative per-task deadline primitive for AI agent workflows.

Agent loops chain LLM and tool calls. Each step has its own network timeout, but rarely is there a single wall-clock cap on the whole task. This crate is a small zero-dependency Deadline type that the loop checks between steps and hands to downstream calls as their remaining timeout.

Cooperative model: code checks the deadline. Nothing is preempted.

§Example

use std::time::Duration;
use agent_deadline::Deadline;

let deadline = Deadline::after(Duration::from_secs(30));

// Between agent steps, check whether the cap has passed.
deadline.check_or_err().unwrap();

// Plug the remaining time into per-call timeouts.
let remaining = deadline.remaining();
assert!(remaining <= Duration::from_secs(30));

§Intersecting nested deadlines

A sub-step often has its own soft cap that should never exceed the parent task’s remaining time. Deadline::intersect picks the earlier of the two.

use std::time::Duration;
use agent_deadline::Deadline;

let task = Deadline::after(Duration::from_secs(30));
let retry = Deadline::after(Duration::from_secs(5));

let tighter = task.intersect(&retry);
assert!(tighter.remaining() <= Duration::from_secs(5));

Structs§

Deadline
A monotonic-time deadline for cooperative task cancellation.
DeadlineExceeded
Error returned by Deadline::check_or_err when the cap has passed.