Expand description
Runtime-agnostic agent loop orchestration for sessions, turns, tools, and interrupts.
agentkit-loop is the central coordination layer in the agentkit workspace. It
drives a model through a multi-turn agentic loop, executing tool calls,
respecting permission checks, surfacing approval and authentication interrupts
to the host application, and optionally compacting the transcript when it grows
too large.
§Architecture
The main entry point is Agent, constructed via AgentBuilder. After
calling Agent::start you receive a LoopDriver that yields
LoopSteps – either a finished turn or an interrupt that requires host
resolution before the loop can continue.
Agent::builder()
.model(adapter) // ModelAdapter implementation
.tools(registry) // ToolRegistry with registered tools
.permissions(checker) // PermissionChecker for gating tool use
.observer(obs) // LoopObserver for streaming events
.build()?
.start(config).await? -> LoopDriver
.submit_input(...)
.next().await? -> LoopStep::Finished | LoopStep::Interrupt§Example
use agentkit_loop::{Agent, PromptCacheRequest, PromptCacheRetention, SessionConfig};
let agent = Agent::builder()
.model(adapter)
.build()?;
let mut driver = agent
.start(
SessionConfig::new("demo").with_cache(
PromptCacheRequest::automatic().with_retention(PromptCacheRetention::Short),
),
)
.await?;Structs§
- Agent
- A configured agent ready to start a session.
- Agent
Builder - Builder for constructing an
Agent. - Input
Request - Descriptor for a
LoopInterrupt::AwaitingInputinterrupt. - Loop
Driver - The runtime driver that advances the agent loop step by step.
- Loop
Snapshot - A read-only snapshot of the loop driver’s current state.
- Model
Turn Result - Final result produced by a single model turn.
- Pending
Approval - Handle for a pending approval interrupt.
- Pending
Auth - Handle for a pending authentication interrupt.
- Prompt
Cache Request - Prompt caching request sent alongside a turn.
- Session
Config - Configuration required to start a new model session.
- Turn
Request - Payload sent to the model at the start of each turn.
- Turn
Result - Outcome of a completed (or cancelled) turn.
Enums§
- Agent
Event - Lifecycle and streaming events emitted by the
LoopDriver. - Loop
Error - Errors that can occur while driving the agent loop.
- Loop
Interrupt - An interrupt that pauses the agent loop until the host resolves it.
- Loop
Step - The result of advancing the agent loop by one step.
- Model
Turn Event - Streaming event emitted by a
ModelTurnduring generation. - Prompt
Cache Breakpoint - Prefix boundary that a provider should cache when using explicit caching.
- Prompt
Cache Mode - Strength of a prompt-cache request.
- Prompt
Cache Retention - High-level provider-neutral cache retention hint.
- Prompt
Cache Strategy - Provider-neutral prompt caching strategy.
Traits§
- Loop
Observer - Observer hook for streaming agent events to the host application.
- Model
Adapter - Factory for creating model sessions.
- Model
Session - An active model session that can produce sequential turns.
- Model
Turn - A streaming model turn that yields events one at a time.