pub struct Agent { /* private fields */ }Expand description
Stateful wrapper around the low-level agent loop.
Implementations§
Source§impl Agent
impl Agent
pub fn new(options: AgentOptions) -> Self
Sourcepub fn subscribe(&self, listener: LoopListener) -> impl FnOnce()
pub fn subscribe(&self, listener: LoopListener) -> impl FnOnce()
Subscribe an async listener (segment 2 — await path). For persistence/I/O subscribers that need the cancellation token. Returns an unsubscribe closure.
For memory-only callbacks (<1µs), use Self::subscribe_sync. For external
subscribers that want a broadcast tokio::sync::broadcast::Receiver, use
Self::subscribe_broadcast.
Sourcepub fn subscribe_sync(&self, callback: LoopSyncCallback) -> impl FnOnce()
pub fn subscribe_sync(&self, callback: LoopSyncCallback) -> impl FnOnce()
Register a synchronous callback (segment 1 — catch_unwind path). The callback MUST complete in <1µs — no I/O, no blocking. Returns an unsubscribe closure.
Sourcepub fn subscribe_broadcast(&self) -> Receiver<LoopEvent>
pub fn subscribe_broadcast(&self) -> Receiver<LoopEvent>
Obtain a new tokio::sync::broadcast::Receiver for the LoopEvent broadcast
channel (segment 3). The receiver sees all events emitted after subscription.
Sourcepub fn state(&self) -> MutexGuard<'_, AgentState>
pub fn state(&self) -> MutexGuard<'_, AgentState>
Inspect the current agent state. The lock guards against concurrent loop mutations.
pub fn is_streaming(&self) -> bool
Sourcepub fn runtime_observer(&self) -> Arc<dyn RuntimeObserver> ⓘ
pub fn runtime_observer(&self) -> Arc<dyn RuntimeObserver> ⓘ
Return the embedder-owned runtime observer used by this agent.
Sourcepub fn observation_context(&self) -> ObservationContext
pub fn observation_context(&self) -> ObservationContext
Return the content-safe correlation context inherited by this agent.
Sourcepub fn active_run_operation(&self) -> Option<OperationId>
pub fn active_run_operation(&self) -> Option<OperationId>
Return the current agent-run operation, if a prompt is active.
pub fn enqueue_steering(&self, message: AgentMessage)
pub fn enqueue_follow_up(&self, message: AgentMessage)
Sourcepub fn interrupt(&self)
pub fn interrupt(&self)
Interrupt the current turn: cancels the in-flight LLM call. The run ends unless a steering message is queued (then the next turn carries it).
Sourcepub fn active_token(&self) -> Option<CancellationToken>
pub fn active_token(&self) -> Option<CancellationToken>
Active cancellation token while a run is in flight, otherwise None.
Sourcepub async fn wait_until_idle(&self)
pub async fn wait_until_idle(&self)
Wait until the active run has released admission and all awaited loop listeners have completed.
Sourcepub async fn prompt(&self, message: AgentMessage) -> Result<(), AgentRunError>
pub async fn prompt(&self, message: AgentMessage) -> Result<(), AgentRunError>
Start a new prompt. Appends a user AgentMessage, runs the loop, awaits completion.
Sourcepub async fn prompt_many(
&self,
messages: Vec<AgentMessage>,
) -> Result<(), AgentRunError>
pub async fn prompt_many( &self, messages: Vec<AgentMessage>, ) -> Result<(), AgentRunError>
Start a new prompt with a batch of messages.
Sourcepub async fn continue_(&self) -> Result<(), AgentRunError>
pub async fn continue_(&self) -> Result<(), AgentRunError>
Continue from the current transcript without appending new user messages.