pub struct AgentLoop {Show 13 fields
pub conversation: Conversation,
pub tool_registry: Arc<ToolRegistry>,
pub turn_runner: TurnRunner,
pub permission_store: Arc<RwLock<PermissionStore>>,
pub config: Config,
pub ctx: Arc<dyn CtxBuilder>,
pub env_snapshot: EnvSnapshot,
pub phase: AgentPhase,
pub turn_tokens: usize,
pub total_tokens: usize,
pub turn_start: Option<Instant>,
pub last_checkpoint: Option<String>,
pub plan_mode: bool,
/* private fields */
}Expand description
The agent loop state.
Fields§
§conversation: Conversation§tool_registry: Arc<ToolRegistry>§turn_runner: TurnRunnerTurnRunner owns the provider, tools, and context.
permission_store: Arc<RwLock<PermissionStore>>§config: Config§ctx: Arc<dyn CtxBuilder>Context construction strategy for the active provider. Selected
at construction via ctx::for_provider and rebuilt on
AgentCommand::ReloadConfig when the provider changes.
Arc (not Box) — shared with turn_runner.ctx so datalog’s
build_messages call and runner’s actual send go through the
same instance. Rebuilds on ReloadConfig update both clones
(see the reload handler below).
env_snapshot: EnvSnapshotSession-start environment snapshot — git branch / HEAD / status.
Captured once in new(), refreshed on ChangeDir (new working
tree ⇒ new repo). Stale-by-design: rendered with a disclaimer
in build_system_prompt so the model knows it’s not live.
See crate::ctx::env.
phase: AgentPhase§turn_tokens: usize§total_tokens: usize§turn_start: Option<Instant>§last_checkpoint: Option<String>Last git checkpoint ref (SHA) for /undo rollback.
plan_mode: boolPlan mode: restrict to read-only tools and inject planning instructions.
Toggled via /plan command or SetPlanMode agent command.
Implementations§
Source§impl AgentLoop
impl AgentLoop
Sourcepub fn new(
config: Config,
provider: Box<dyn LlmProvider>,
tool_registry: ToolRegistry,
tool_context: ToolContext,
conversation: Conversation,
) -> (Self, AgentHandle)
pub fn new( config: Config, provider: Box<dyn LlmProvider>, tool_registry: ToolRegistry, tool_context: ToolContext, conversation: Conversation, ) -> (Self, AgentHandle)
Create a new agent loop and its corresponding UI handle.
Create a new runtime using the already-shared tool and skill registries.
This path intentionally does not reload skills or register use_skill /
graph tools; the initial runtime owns that one-time setup.
Sourcepub fn set_max_turns(&mut self, max: Option<usize>)
pub fn set_max_turns(&mut self, max: Option<usize>)
Set an optional hard cap on the number of LLM turns this agent will
run. When the cap is reached, run_turn_loop exits via
finish_turn(TurnStopReason::TurnLimit). None (the default) is
unbounded. Used by the CLI --max-turns flag.
Auto Trait Implementations§
impl Freeze for AgentLoop
impl !RefUnwindSafe for AgentLoop
impl Send for AgentLoop
impl Sync for AgentLoop
impl Unpin for AgentLoop
impl UnsafeUnpin for AgentLoop
impl !UnwindSafe for AgentLoop
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more