pub struct AgentLoop { /* private fields */ }Expand description
Agent loop executor
Implementations§
Source§impl AgentLoop
impl AgentLoop
pub fn new( llm_client: Arc<dyn LlmClient>, tool_executor: Arc<ToolExecutor>, tool_context: ToolContext, config: AgentConfig, ) -> Self
Sourcepub fn with_progress_tracker(
self,
tracker: Arc<RwLock<ProgressTracker>>,
) -> Self
pub fn with_progress_tracker( self, tracker: Arc<RwLock<ProgressTracker>>, ) -> Self
Set the progress tracker for real-time tool/token usage tracking.
Sourcepub fn with_task_manager(self, manager: Arc<TaskManager>) -> Self
pub fn with_task_manager(self, manager: Arc<TaskManager>) -> Self
Set the task manager for centralized task lifecycle tracking.
Sourcepub fn with_tool_metrics(self, metrics: Arc<RwLock<ToolMetrics>>) -> Self
pub fn with_tool_metrics(self, metrics: Arc<RwLock<ToolMetrics>>) -> Self
Set the tool metrics collector for this agent loop
Sourcepub fn with_queue(self, queue: Arc<SessionLaneQueue>) -> Self
pub fn with_queue(self, queue: Arc<SessionLaneQueue>) -> Self
Set the lane queue for priority-based tool execution.
When set, tools are routed through the lane queue which supports External task handling for multi-machine parallel processing.
Sourcepub async fn execute(
&self,
history: &[Message],
prompt: &str,
event_tx: Option<Sender<AgentEvent>>,
) -> Result<AgentResult>
pub async fn execute( &self, history: &[Message], prompt: &str, event_tx: Option<Sender<AgentEvent>>, ) -> Result<AgentResult>
Execute the agent loop for a prompt
Takes the conversation history and a new user prompt. Returns the agent result and updated message history. When event_tx is provided, uses streaming LLM API for real-time text output.
Sourcepub async fn execute_from_messages(
&self,
messages: Vec<Message>,
session_id: Option<&str>,
event_tx: Option<Sender<AgentEvent>>,
cancel_token: Option<&CancellationToken>,
) -> Result<AgentResult>
pub async fn execute_from_messages( &self, messages: Vec<Message>, session_id: Option<&str>, event_tx: Option<Sender<AgentEvent>>, cancel_token: Option<&CancellationToken>, ) -> Result<AgentResult>
Execute the agent loop with pre-built messages (user message already included).
Used by send_with_attachments / stream_with_attachments where the
user message contains multi-modal content and is already appended to
the messages vec.
Sourcepub async fn execute_with_session(
&self,
history: &[Message],
prompt: &str,
session_id: Option<&str>,
event_tx: Option<Sender<AgentEvent>>,
cancel_token: Option<&CancellationToken>,
) -> Result<AgentResult>
pub async fn execute_with_session( &self, history: &[Message], prompt: &str, session_id: Option<&str>, event_tx: Option<Sender<AgentEvent>>, cancel_token: Option<&CancellationToken>, ) -> Result<AgentResult>
Execute the agent loop for a prompt with session context
Takes the conversation history, user prompt, and optional session ID. When session_id is provided, context providers can use it for session-specific context.
Sourcepub async fn execute_streaming(
&self,
history: &[Message],
prompt: &str,
) -> Result<(Receiver<AgentEvent>, JoinHandle<Result<AgentResult>>, CancellationToken)>
pub async fn execute_streaming( &self, history: &[Message], prompt: &str, ) -> Result<(Receiver<AgentEvent>, JoinHandle<Result<AgentResult>>, CancellationToken)>
Execute with streaming events
Sourcepub async fn plan(
&self,
prompt: &str,
_context: Option<&str>,
) -> Result<ExecutionPlan>
pub async fn plan( &self, prompt: &str, _context: Option<&str>, ) -> Result<ExecutionPlan>
Create an execution plan for a prompt
Delegates to [LlmPlanner] for structured JSON plan generation,
falling back to heuristic planning if the LLM call fails.
Sourcepub async fn execute_with_planning(
&self,
history: &[Message],
prompt: &str,
event_tx: Option<Sender<AgentEvent>>,
) -> Result<AgentResult>
pub async fn execute_with_planning( &self, history: &[Message], prompt: &str, event_tx: Option<Sender<AgentEvent>>, ) -> Result<AgentResult>
Execute with planning phase
Sourcepub async fn extract_goal(&self, prompt: &str) -> Result<AgentGoal>
pub async fn extract_goal(&self, prompt: &str) -> Result<AgentGoal>
Extract goal from prompt
Delegates to [LlmPlanner] for structured JSON goal extraction,
falling back to heuristic logic if the LLM call fails.
Trait Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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