Skip to main content

Thread

Struct Thread 

Source
pub struct Thread<T, S = Value> { /* private fields */ }
Available on crate feature client only.
Expand description

One local conversation with an agent. T only supplies communication. S is the current state view, defaulting to JSON.

Implementations§

Source§

impl<T: Transport> Thread<T>

Source

pub fn new(transport: T, thread_id: impl Into<ThreadId>) -> Self

Creates an empty JSON conversation. No request is sent.

Source§

impl<T, S> Thread<T, S>

Source

pub fn builder( transport: T, thread_id: impl Into<ThreadId>, ) -> ThreadBuilder<T, S>
where T: Transport,

Configures a conversation and validates its initial typed state at build.

Source

pub fn thread_id(&self) -> &ThreadId

The remote conversation identifier.

Source

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

The current assembled conversation.

Source

pub fn state(&self) -> Result<&S, StateViewError>

The current typed view. A remote type mismatch invalidates the old view.

Source

pub fn raw_state(&self) -> &Value

The latest raw state, even when it does not fit S.

Source

pub fn reasoning(&self) -> &[ReasoningMessage]

Materialized reasoning, separate from the conversation.

Source

pub fn interrupts(&self) -> &[Interrupt]

Pending human input. Dispatching a response does not remove it.

Source

pub fn submission(&self) -> Option<&ResumeSubmission>

Unconfirmed or currently in-flight response submission.

Source

pub fn subagents(&self) -> &[Subagent]

Announced subagents across runs.

Source

pub fn subagent(&self, id: &SubagentRunId) -> Option<&Subagent>

Find a subagent by invocation ID.

Source

pub fn applier(&self) -> &Applier

The current materialized protocol data.

Source

pub fn agent(&self) -> &RemoteAgent<Arc<T>>

The low-level agent using the same owned transport handle.

Source

pub fn last_run_end(&self) -> Option<&RunEnd>

The last observed termination. Dropping a dispatched run records Aborted.

Source

pub fn push_message(&mut self, message: Message) -> Result<()>

Append a client-owned message, rejecting an ID already in the transcript.

Source

pub fn set_tools(&mut self, tools: impl Into<Vec<Tool>>)

Tools offered on subsequent runs. AG-UI does not discover tools.

Source

pub fn set_context(&mut self, context: impl Into<Vec<Context>>)

Context sent on subsequent runs.

Source

pub fn set_forwarded_props(&mut self, props: impl Into<Value>)

Passthrough request properties supplied by the application.

Source

pub fn set_verify(&mut self, verify: bool)

Configure protocol ordering verification. Identity and resume safety checks stay enabled.

Source

pub fn set_diagnostic_limit(&mut self, limit: usize)

Retained diagnostics per run. Excess errors are still yielded as updates.

Source

pub fn set_next_run_id(&mut self, id: impl Into<RunId>)

Reserve an explicit run ID. Reuse is rejected during request preflight.

Source

pub fn clear_event_observer(&mut self)

Remove the event observer.

Source

pub fn on_event(&mut self, observer: impl FnMut(&Event) + Send + 'static)

Available on non-target_family=wasm only.

Replace the synchronous read-only observer. Called once per decoded event, before normalization and validation. Queue slow work in the application.

Source

pub fn snapshot(&self) -> ThreadSnapshot

Save local conversation data. Transport settings and callbacks are excluded.

Source§

impl<T, S: DeserializeOwned> Thread<T, S>

Source

pub fn set_state(&mut self, state: impl Into<Value>) -> Result<()>

Validates local JSON before atomically replacing both raw and typed state.

Source

pub fn restore(transport: T, snapshot: ThreadSnapshot) -> Result<Self>
where T: Transport,

Restore local state using a new transport. No server query is performed.

Source§

impl<T: Transport, S> Thread<T, S>

Source

pub fn send(&mut self, text: impl Into<String>) -> Result<RunStream<'_, T, S>>

Prepare a user turn. Pending decisions and ambiguous submissions are checked before changing history. Dispatch and history insertion occur on first poll.

Source

pub fn send_message(&mut self, message: Message) -> Result<RunStream<'_, T, S>>

Prepare a message of any role, rejecting existing IDs.

Source

pub fn run(&mut self) -> Result<RunStream<'_, T, S>>

Prepare a run with the existing conversation and no new message.

Source

pub fn resume( &mut self, interrupt: &Interrupt, payload: impl Into<Value>, ) -> Result<RunStream<'_, T, S>>

Answer the single outstanding interrupt. All pending IDs must be answered.

Source

pub fn decline(&mut self, interrupt: &Interrupt) -> Result<RunStream<'_, T, S>>

Decline the single outstanding interrupt. This is not execution cancellation.

Source

pub fn resume_many( &mut self, entries: impl IntoIterator<Item = ResumeEntry>, ) -> Result<RunStream<'_, T, S>>

Answer every pending question exactly once. Expiry is checked against the stored interrupt. Response schemas are retained for the application/server to validate; this transport-neutral API does not execute arbitrary schemas.

Trait Implementations§

Source§

impl<T, S: Debug> Debug for Thread<T, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, S = Value> !RefUnwindSafe for Thread<T, S>

§

impl<T, S = Value> !Sync for Thread<T, S>

§

impl<T, S = Value> !UnwindSafe for Thread<T, S>

§

impl<T, S> Freeze for Thread<T, S>

§

impl<T, S> Send for Thread<T, S>

§

impl<T, S> Unpin for Thread<T, S>

§

impl<T, S> UnsafeUnpin for Thread<T, S>

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