pub struct AgentLoop { /* private fields */ }Expand description
AgentLoop.
Implementations§
Source§impl AgentLoop
impl AgentLoop
Sourcepub fn new_with_resolver(
provider: Arc<dyn Provider>,
config: AgentLoopConfig,
tools: Arc<ToolRegistry>,
state: SharedState,
resolver: Arc<dyn ProviderResolver>,
) -> Self
pub fn new_with_resolver( provider: Arc<dyn Provider>, config: AgentLoopConfig, tools: Arc<ToolRegistry>, state: SharedState, resolver: Arc<dyn ProviderResolver>, ) -> Self
TODO. Create a new AgentLoop with an explicit resolver.
Sourcepub fn new(
provider: Arc<dyn Provider>,
config: AgentLoopConfig,
tools: Arc<ToolRegistry>,
state: SharedState,
) -> Self
pub fn new( provider: Arc<dyn Provider>, config: AgentLoopConfig, tools: Arc<ToolRegistry>, state: SharedState, ) -> Self
Create a new AgentLoop using the global resolver (backward compat).
Sourcepub fn with_before_tool_call(self, hook: BeforeToolCallHook) -> Self
pub fn with_before_tool_call(self, hook: BeforeToolCallHook) -> Self
TODO: document this function.
Sourcepub fn with_after_tool_call(self, hook: AfterToolCallHook) -> Self
pub fn with_after_tool_call(self, hook: AfterToolCallHook) -> Self
TODO: document this function.
Sourcepub fn steer(&self, message: Message)
pub fn steer(&self, message: Message)
Inject a steering message into the agent loop.
Steering messages are processed at the start of each turn, before the next LLM call. If the steering queue is at capacity (256 messages), the message is dropped and a warning is logged.
Sourcepub fn follow_up(&self, message: Message)
pub fn follow_up(&self, message: Message)
Enqueue a follow-up message to continue the conversation after all tool calls in the current batch are complete.
If the follow-up queue is at capacity (64 messages), the message is dropped and a warning is logged.
Sourcepub fn clear_steering_queue(&self)
pub fn clear_steering_queue(&self)
TODO: document this function.
Sourcepub fn clear_follow_up_queue(&self)
pub fn clear_follow_up_queue(&self)
TODO: document this function.
Sourcepub fn clear_all_queues(&self)
pub fn clear_all_queues(&self)
TODO: document this function.
Sourcepub fn cancel_auto_retry(&self)
pub fn cancel_auto_retry(&self)
TODO: document this function.
Sourcepub fn auto_retry_attempt(&self) -> usize
pub fn auto_retry_attempt(&self) -> usize
TODO: document this function.
Sourcepub fn state(&self) -> &SharedState
pub fn state(&self) -> &SharedState
Get a reference to the shared state. Used by Agent to sync state after loop execution.
Sourcepub fn external_stop(&self) -> &Arc<AtomicBool> ⓘ
pub fn external_stop(&self) -> &Arc<AtomicBool> ⓘ
Get the external stop flag.
Sourcepub fn set_cancel_signal(&mut self, flag: Arc<AtomicBool>)
pub fn set_cancel_signal(&mut self, flag: Arc<AtomicBool>)
Sets a shared cancel signal (typically Agent::cancel_flag).
The streaming loop checks this in its periodic wake-up timer,
ensuring cancellation is detected even when the provider stream
produces no events (e.g. waiting for first token).
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if cancellation has been requested via either
external_stop or the direct cancel_signal.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Request cancellation from outside the loop (e.g. Ctrl+C).
Sets the external_stop flag which causes the streaming loop
to abort on its next periodic check (~500ms) and the agent loop
to exit after the current turn.
Sourcepub fn set_steering_hook(
&mut self,
hook: Arc<dyn Fn() -> Vec<String> + Send + Sync>,
)
pub fn set_steering_hook( &mut self, hook: Arc<dyn Fn() -> Vec<String> + Send + Sync>, )
Set the steering hook — called each turn to drain new messages from the session’s steering queue into the loop’s internal queue.
Sourcepub fn set_follow_up_hook(
&mut self,
hook: Arc<dyn Fn() -> Vec<String> + Send + Sync>,
)
pub fn set_follow_up_hook( &mut self, hook: Arc<dyn Fn() -> Vec<String> + Send + Sync>, )
Set the follow-up hook — called each turn to drain new messages from the session’s follow-up queue into the loop’s internal queue.
Sourcepub async fn run(
&self,
prompt: String,
emit: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<Vec<AgentEvent>>
pub async fn run( &self, prompt: String, emit: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<Vec<AgentEvent>>
TODO: document this function.
Sourcepub async fn run_messages(
&self,
prompts: Vec<Message>,
emit: Arc<dyn Fn(AgentEvent) + Send + Sync>,
) -> Result<Vec<AgentEvent>>
pub async fn run_messages( &self, prompts: Vec<Message>, emit: Arc<dyn Fn(AgentEvent) + Send + Sync>, ) -> Result<Vec<AgentEvent>>
TODO: document this function.
Sourcepub async fn continue_loop(
&self,
emit: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<Vec<AgentEvent>>
pub async fn continue_loop( &self, emit: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<Vec<AgentEvent>>
TODO: document this function.