Skip to main content

Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }

Implementations§

Source§

impl Agent

Source

pub fn new(cfg: AgentConfig) -> Agent

Source

pub fn steer(&self, m: AgentMessage)

Queued for injection at the next turn start (this run or a later one).

Source

pub fn set_plan_mode(&mut self, on: bool)

Toggle plan mode: flips the shared handle and recomposes system from base_system — appending PLAN_SECTION when on, restoring the base prompt exactly when off. Takes effect on the NEXT run (the in-flight one cloned system into its LoopConfig at start). Not persisted.

Source

pub fn set_model(&mut self, model: String) -> Result<()>

Swaps the model mid-conversation (takes effect on the next run) and logs a ModelChange entry when a session is open. The new id’s [models.<id>] profile re-points endpoint/base_url/api_key by settling on the launch provider first, so an unmapped id — and a switch back to a previous model — falls back to it (the switch is reversible).

Source

pub fn effort(&self) -> Option<&str>

Current reasoning effort (None = send nothing).

Source

pub fn title_after_turns(&self) -> usize

Assistant turns before the auto-titler fires (0 = off) — the resolved [session] title_after_turns this agent was built with (W031).

Source

pub fn set_effort(&mut self, effort: Option<String>) -> Result<()>

Swaps the reasoning effort mid-conversation (next run) and logs an EffortChange entry when a session is open. None clears it.

Source

pub fn set_title(&mut self, title: &str) -> Result<()>

Give this session a name: append a Title entry (last write wins) and mirror it in memory. The EXPLICIT rename path — /rename on both human surfaces, --title, and crate::protocol::Request::SetTitle — never calls a model.

Appends BEFORE the in-memory write, deliberately (the Agent::set_model rationale, “a failed append must not leave the agent and the session disagreeing”): if the append fails the caller gets the io::Error and Agent::title is unchanged, so a UI never claims a name the file does not have.

§Errors

The session append’s io::Error, unchanged. The in-memory mirror is NOT updated on failure.

§Does not

Sanitize (/rename takes the user’s text verbatim; the AUTO path sanitizes, in crate::title::sanitize), call a model, or refuse an empty string — set_title("") stores an empty title and Agent::title then returns Some("").

Source

pub fn title(&self) -> Option<String>

The session’s current title (None = never titled).

Reads the SESSION first, the in-memory mirror second — and that order is the whole contract. The auto-titler runs inside run_loop, which holds &mut Session and no &mut Agent, so a title it appends lands in the session and NOT in an Agent field; a mirror-only getter would report None right after a successful auto-title, and a UI asking the actor would disagree with the file. Session-first makes the persisted value authoritative; the mirror covers --no-session, where there is no session to ask.

Source

pub fn steer_sender(&self) -> UnboundedSender<AgentMessage>

Sender clone for steering while run holds the &mut borrow (UI tasks).

run_loop hands the lent channels back at the end of every run, so a clone taken once stays valid across runs and a message sent while a run is in flight — even one the loop never drained — reaches the next run. (Only an error exit reboots the channels, invalidating old clones.)

Source

pub fn follow_up(&self, m: AgentMessage)

Runs after the loop would stop.

Source

pub fn follow_up_sender(&self) -> UnboundedSender<AgentMessage>

Sender clone for injecting a follow-up while run holds the &mut borrow (the mirror of Agent::steer_sender, for a UI/actor task that cannot reach follow_up directly).

Source

pub fn cancel(&self)

Source

pub fn cancel_token(&self) -> CancellationToken

Token for the run in flight or the next one; re-acquire after each run() (a fresh token is minted at the end of every run).

Source

pub fn hooks(&self) -> &HooksSet

The hook set, exposed so the actor can run the inbound policy (HooksSet::before_inbound) while run holds the &mut borrow.

Source

pub async fn run( &mut self, user_text: &str, sink: UnboundedSender<AgentEvent>, ) -> Result<StopReason, LoopError>

Source

pub fn messages(&self) -> &[AgentMessage]

Source

pub fn notify(&mut self, content: String) -> Result<AgentMessage>

Record an inbound peer message into the conversation without starting a turn (the Request::Notify semantic): persist it as a user message and push it onto the context, so the next run sees it. Returns the recorded message so the actor can surface it. Idle-only — the actor routes a Notify that arrives mid-run through steering instead.

Source

pub async fn side_ask(&self, text: &str) -> Result<SideAnswer, LoopError>

Answer text tool-free, from the current context, as a one-off side call.

CLONES ctx, appends the (framed) question, runs the raw stream_fn once with an EMPTY tool list, and folds TextDelta → text until Done (capturing usage). self.ctx and self.session are never mutated or appended — hence &self, so it stays callable while the actor holds &mut Agent for a run.

Errors become LoopError::Stream: a stream Error, or a call that ended with no text. No retry loop of its own — it inherits whatever retry/idle-timeout the configured stream_fn adapter applies internally, exactly as crate::compaction::summarize does. No cancel path in v1.

Source

pub fn side_handle(&self) -> SideHandle

A read-only handle the actor takes before a run borrows the agent, so a mid-run GetHistory/SideAsk is answered from the context snapshot run_loop republishes each turn, instead of waiting for the whole run. See SideHandle.

Source

pub async fn compact( &mut self, instructions: Option<&str>, ) -> Result<CompactOutcome, String>

Summarize the older part of the conversation in place: keep the newest messages per CompactionPolicy and replace the rest with a single summary message. instructions focuses the summary (the /compact <prompt> argument).

When a session is open, the boundary is persisted (crate::session::SessionEntry::Compaction), so a resumed session rebuilds to the same summary + kept view instead of re-expanding.

Source

pub fn session_path(&self) -> Option<&Path>

Source

pub fn session_id(&self) -> Option<String>

The session’s stable id (from its Header), if a session is open. The address a SessionHandle’s frames carry.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Agent

§

impl !UnwindSafe for Agent

§

impl Freeze for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin 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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

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
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