agentkit-task-manager
Task scheduling abstractions for tool execution in agentkit.
A TaskManager decides whether each tool call runs inline (foreground), in the
background, or starts foreground and detaches after a timeout. The agent loop
talks to a single TaskManagerHandle and receives TaskEvents as tasks make
progress, complete, or get cancelled.
What it provides
TaskManagertrait + two implementations:SimpleTaskManager-- executes every tool call inline, no spawningAsyncTaskManager-- spawns tokio tasks and supports background work, cancellation, and detachment
TaskRoutingPolicyfor decidingForegroundvsBackgroundvsForegroundThenDetachAfter(Duration)per requestTaskManagerHandlefor cancellation, listing running/completed tasks, and draining results out-of-bandTaskEventstream coveringStarted,Detached,Completed,Cancelled,Failed, andContinueRequested
Quick start
SimpleTaskManager is the smallest useful implementation. It runs each tool
call to completion before returning a TaskResolution:
use Arc;
use ;
use ;
use ;
use json;
;
# async
Routing tasks to the background
AsyncTaskManager accepts a TaskRoutingPolicy that decides per-request
whether work runs in the foreground (blocking the turn) or in the background
(letting the turn continue while the task runs):
use Duration;
use ;
use ToolRequest;
let manager = new.routing;
# let _ = manager;
The handle returned by manager.handle() is what callers use to observe
events (next_event), cancel by id (cancel), tweak per-task delivery
(set_delivery_mode, set_continue_policy), and drain background results
delivered out-of-band (drain_ready_items).