Skip to main content

Agent

Struct Agent 

Source
pub struct Agent {
    pub phase: Phase,
    /* private fields */
}
Expand description

The agent state machine. Purely synchronous; the host drives progress.

Fields§

§phase: Phase

Implementations§

Source§

impl Agent

Source

pub fn new(options: AgentOptions) -> Self

Source

pub fn start_turn( &mut self, prompt: AgentMessage, ) -> (Vec<AgentEvent>, Vec<AgentAction>)

Start processing a new prompt.

Source

pub fn continue_turn(&mut self) -> (Vec<AgentEvent>, Vec<AgentAction>)

Continue from the current transcript without adding a new message.

Source

pub fn feed_llm_chunk(&mut self, chunk: LlmChunk) -> Vec<AgentEvent>

Feed a streaming chunk from the LLM.

Source

pub fn on_llm_done( &mut self, result: LlmResult, ) -> (Vec<AgentEvent>, Vec<AgentAction>)

Called by the host when the LLM stream ends.

Source

pub fn on_tool_done( &mut self, tool_call_id: ToolCallId, result: Result<ToolResult, ToolError>, ) -> (Vec<AgentEvent>, Vec<AgentAction>)

Called by the host when a tool finishes executing.

Source

pub fn on_tool_started(&mut self, tool_call_id: ToolCallId) -> Vec<AgentEvent>

Called by the host when a tool starts executing. Emits a ToolExecutionUpdate event for trace/observability. Does not change the core state machine phase.

Source

pub fn on_tool_update(&mut self, update: ToolExecutionUpdate) -> Vec<AgentEvent>

Called by the host with a streaming chunk from a running tool. Emits a ToolExecutionUpdate event for trace/observability only. Does NOT add to the canonical model transcript.

Source

pub fn on_tool_cancelled( &mut self, tool_call_id: ToolCallId, reason: CancelReason, ) -> (Vec<AgentEvent>, Vec<AgentAction>)

Called by the host when a tool is cancelled. Treats cancellation like a tool error result so the state machine can advance.

Source

pub fn steer(&mut self, message: AgentMessage) -> Vec<AgentEvent>

Inject a steering message mid-run.

Source

pub fn follow_up(&mut self, message: AgentMessage)

Queue a follow-up message for after the run would otherwise stop.

Source

pub fn abort(&mut self) -> Vec<AgentEvent>

Abort the current run.

Source

pub fn state(&self) -> &AgentState

Read-only access to current state.

Source

pub fn reset(&mut self)

Reset state (clear messages, queues, runtime state).

Auto Trait Implementations§

§

impl Forget for Agent

§

impl Freeze for Agent

§

impl Move for Agent

§

impl RefUnwindSafe for Agent

§

impl Send for Agent
where RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, RawTable<(ToolCallId, ToolCall)>: Send,

§

impl Sync for Agent
where RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, RawTable<(ToolCallId, ToolCall)>: Sync,

§

impl Unpin for Agent
where *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin,

§

impl UnsafeUnpin for Agent

§

impl UnwindSafe for Agent

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more