pub struct Thread<T, S = Value> { /* private fields */ }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, S> Thread<T, S>
impl<T, S> Thread<T, S>
Sourcepub fn builder(
transport: T,
thread_id: impl Into<ThreadId>,
) -> ThreadBuilder<T, S>where
T: Transport,
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.
Sourcepub fn state(&self) -> Result<&S, StateViewError>
pub fn state(&self) -> Result<&S, StateViewError>
The current typed view. A remote type mismatch invalidates the old view.
Sourcepub fn reasoning(&self) -> &[ReasoningMessage]
pub fn reasoning(&self) -> &[ReasoningMessage]
Materialized reasoning, separate from the conversation.
Sourcepub fn interrupts(&self) -> &[Interrupt]
pub fn interrupts(&self) -> &[Interrupt]
Pending human input. Dispatching a response does not remove it.
Sourcepub fn submission(&self) -> Option<&ResumeSubmission>
pub fn submission(&self) -> Option<&ResumeSubmission>
Unconfirmed or currently in-flight response submission.
Sourcepub fn subagent(&self, id: &SubagentRunId) -> Option<&Subagent>
pub fn subagent(&self, id: &SubagentRunId) -> Option<&Subagent>
Find a subagent by invocation ID.
Sourcepub fn agent(&self) -> &RemoteAgent<Arc<T>>
pub fn agent(&self) -> &RemoteAgent<Arc<T>>
The low-level agent using the same owned transport handle.
Sourcepub fn last_run_end(&self) -> Option<&RunEnd>
pub fn last_run_end(&self) -> Option<&RunEnd>
The last observed termination. Dropping a dispatched run records Aborted.
Sourcepub fn push_message(&mut self, message: Message) -> Result<()>
pub fn push_message(&mut self, message: Message) -> Result<()>
Append a client-owned message, rejecting an ID already in the transcript.
Sourcepub fn set_tools(&mut self, tools: impl Into<Vec<Tool>>)
pub fn set_tools(&mut self, tools: impl Into<Vec<Tool>>)
Tools offered on subsequent runs. AG-UI does not discover tools.
Sourcepub fn set_context(&mut self, context: impl Into<Vec<Context>>)
pub fn set_context(&mut self, context: impl Into<Vec<Context>>)
Context sent on subsequent runs.
Sourcepub fn set_forwarded_props(&mut self, props: impl Into<Value>)
pub fn set_forwarded_props(&mut self, props: impl Into<Value>)
Passthrough request properties supplied by the application.
Sourcepub fn set_verify(&mut self, verify: bool)
pub fn set_verify(&mut self, verify: bool)
Configure protocol ordering verification. Identity and resume safety checks stay enabled.
Sourcepub fn set_diagnostic_limit(&mut self, limit: usize)
pub fn set_diagnostic_limit(&mut self, limit: usize)
Retained diagnostics per run. Excess errors are still yielded as updates.
Sourcepub fn set_next_run_id(&mut self, id: impl Into<RunId>)
pub fn set_next_run_id(&mut self, id: impl Into<RunId>)
Reserve an explicit run ID. Reuse is rejected during request preflight.
Sourcepub fn clear_event_observer(&mut self)
pub fn clear_event_observer(&mut self)
Remove the event observer.
Sourcepub fn on_event(&mut self, observer: impl FnMut(&Event) + Send + 'static)
Available on non-target_family=wasm only.
pub fn on_event(&mut self, observer: impl FnMut(&Event) + Send + 'static)
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.
Sourcepub fn snapshot(&self) -> ThreadSnapshot
pub fn snapshot(&self) -> ThreadSnapshot
Save local conversation data. Transport settings and callbacks are excluded.
Source§impl<T, S: DeserializeOwned> Thread<T, S>
impl<T, S: DeserializeOwned> Thread<T, S>
Sourcepub fn set_state(&mut self, state: impl Into<Value>) -> Result<()>
pub fn set_state(&mut self, state: impl Into<Value>) -> Result<()>
Validates local JSON before atomically replacing both raw and typed state.
Sourcepub fn restore(transport: T, snapshot: ThreadSnapshot) -> Result<Self>where
T: Transport,
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>
impl<T: Transport, S> Thread<T, S>
Sourcepub fn send(&mut self, text: impl Into<String>) -> Result<RunStream<'_, T, S>>
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.
Sourcepub fn send_message(&mut self, message: Message) -> Result<RunStream<'_, T, S>>
pub fn send_message(&mut self, message: Message) -> Result<RunStream<'_, T, S>>
Prepare a message of any role, rejecting existing IDs.
Sourcepub fn run(&mut self) -> Result<RunStream<'_, T, S>>
pub fn run(&mut self) -> Result<RunStream<'_, T, S>>
Prepare a run with the existing conversation and no new message.
Sourcepub fn resume(
&mut self,
interrupt: &Interrupt,
payload: impl Into<Value>,
) -> Result<RunStream<'_, T, S>>
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.
Sourcepub fn decline(&mut self, interrupt: &Interrupt) -> Result<RunStream<'_, T, S>>
pub fn decline(&mut self, interrupt: &Interrupt) -> Result<RunStream<'_, T, S>>
Decline the single outstanding interrupt. This is not execution cancellation.
Sourcepub fn resume_many(
&mut self,
entries: impl IntoIterator<Item = ResumeEntry>,
) -> Result<RunStream<'_, T, S>>
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.