pub struct Ed<S = NoopSink> { /* private fields */ }Expand description
An embeddable chat agent over a single ChatEngine.
Hold one per application. Ed is Send + Sync and every method takes
&self, so it can live behind a OnceLock, a framework’s managed state,
or an Arc — whichever the host prefers. It is not cloneable by design:
one Ed owns one engine owns one loaded model, and copying that handle
around tends to mean two parts of an app disagree about which model is up.
Implementations§
Source§impl<S: EventSink> Ed<S>
impl<S: EventSink> Ed<S>
Sourcepub fn with_agent(
sink: S,
executor: Arc<dyn ToolExecutor>,
approvals: Arc<dyn ApprovalHandler>,
config: AgentConfig,
) -> Self
pub fn with_agent( sink: S, executor: Arc<dyn ToolExecutor>, approvals: Arc<dyn ApprovalHandler>, config: AgentConfig, ) -> Self
Build an agent with host-defined tool execution and approval handling.
Sourcepub fn with_app_id(sink: S, onde_app_id: Option<String>) -> Self
pub fn with_app_id(sink: S, onde_app_id: Option<String>) -> Self
Associate telemetry with an Onde app id. See ChatEngine::with_app_id.
Sourcepub fn with_agent_and_app_id(
sink: S,
executor: Arc<dyn ToolExecutor>,
approvals: Arc<dyn ApprovalHandler>,
config: AgentConfig,
onde_app_id: Option<String>,
) -> Self
pub fn with_agent_and_app_id( sink: S, executor: Arc<dyn ToolExecutor>, approvals: Arc<dyn ApprovalHandler>, config: AgentConfig, onde_app_id: Option<String>, ) -> Self
The full constructor: tools, approvals, and an Onde app id together.
The narrower constructors each fill in defaults for what they don’t take. Use this one when you need both host tools and telemetry, which the others cannot express between them.
Sourcepub fn engine(&self) -> &ChatEngine
pub fn engine(&self) -> &ChatEngine
The underlying engine.
An escape hatch for the parts of onde Ed deliberately doesn’t wrap —
system prompts, alternative load paths, tool calling. Reach for it when
you need them; anything you find yourself writing here for a second
application is a candidate to move into Ed.
Sourcepub async fn load_with<'a, F, Fut>(
&'a self,
model_name: &str,
load: F,
) -> Result<Duration, InferenceError>
pub async fn load_with<'a, F, Fut>( &'a self, model_name: &str, load: F, ) -> Result<Duration, InferenceError>
Run any load, reporting the transitions around it.
Emits EngineStatus::Loading before load starts and then either
Ready or Error. That
sequence is the whole reason this method exists: calling a
ChatEngine load path directly leaves the UI with no way to know a
multi-minute download has begun.
Ed takes a closure rather than wrapping each load path by name because
onde’s load APIs take types Ed has no business in its public
signature — ChatEngine::load_assigned_model takes an Environment
from the smbCloud SDK, and which crate that type comes from changed
between onde releases. Naming it here would drag that dependency into
every host and pin them all to Ed’s version of it. Passing a closure
keeps Ed’s dependency surface to onde alone and works for load paths
that don’t exist yet.
ed.load_with("Qwen 2.5", |engine| {
engine.load_gguf_model(GgufModelConfig::qwen25_1_5b(), None, None)
})
.await
.expect("load");model_name is what the host wants the UI to show while loading; it is
reported with each transition and needn’t match what the engine ends up
calling the model.
Sourcepub async fn load(
&self,
config: GgufModelConfig,
system_prompt: Option<String>,
sampling: Option<SamplingConfig>,
) -> Result<Duration, InferenceError>
pub async fn load( &self, config: GgufModelConfig, system_prompt: Option<String>, sampling: Option<SamplingConfig>, ) -> Result<Duration, InferenceError>
Load a GGUF model, reporting each transition.
A convenience over load_with for the most common
path. Downloads the weights first if they aren’t in the local cache, so
the Loading state can last a long time on a cold start.
Sourcepub async fn unload(&self) -> Option<String>
pub async fn unload(&self) -> Option<String>
Unload the current model, returning its display name if one was loaded.
Sourcepub async fn send(&self, message: impl Into<String>) -> ChatReply
pub async fn send(&self, message: impl Into<String>) -> ChatReply
Run one inference turn.
Never returns an error: a failure is reported in
ChatReply::error so a caller has one shape to render either way.
The reply also goes to the sink, so a host can render it from an event
instead of awaiting this call — see EventSink::replied.
Sourcepub async fn stream(
&self,
message: impl Into<String>,
) -> Result<TextStream, InferenceError>
pub async fn stream( &self, message: impl Into<String>, ) -> Result<TextStream, InferenceError>
Stream the reply to one message, for plain chat without tools.
Returns once generation has started; the stream yields text deltas as
they are produced. Unlike run this takes no turn lock and
reports nothing to the sink, so don’t overlap it with another turn.
Drop the stream to cancel; a cancel call is not needed.
Sourcepub async fn generate(
&self,
messages: Vec<ChatMessage>,
sampling: Option<SamplingConfig>,
) -> Result<String, InferenceError>
pub async fn generate( &self, messages: Vec<ChatMessage>, sampling: Option<SamplingConfig>, ) -> Result<String, InferenceError>
One-shot generation over explicit messages.
Leaves the conversation history untouched; the engine’s system prompt
is still applied. sampling overrides the engine’s for this call only.
Sourcepub async fn set_system_prompt(&self, prompt: impl Into<String>)
pub async fn set_system_prompt(&self, prompt: impl Into<String>)
Set the system prompt used for every later turn.
Like the other engine setters below, and restore_history, this does
nothing until a model is loaded: onde keeps these on the loaded model.
pub async fn clear_system_prompt(&self)
Sourcepub async fn set_sampling(&self, sampling: SamplingConfig)
pub async fn set_sampling(&self, sampling: SamplingConfig)
Change the default sampling parameters.
Sourcepub async fn restore_history(&self, messages: Vec<ChatMessage>)
pub async fn restore_history(&self, messages: Vec<ChatMessage>)
Replace the conversation with messages.
For switching to a saved session or restoring one at launch. Clears
the current history first, and with it every AllowForSession grant,
exactly as clear_history does: a restored
conversation starts without consent from the previous one.
Sourcepub async fn register_tool(
&self,
tool: AgentToolDefinition,
) -> Result<(), AgentError>
pub async fn register_tool( &self, tool: AgentToolDefinition, ) -> Result<(), AgentError>
Register a host capability that the model may request.
pub async fn unregister_tool(&self, name: &str) -> bool
pub async fn remove_all_tools(&self)
Sourcepub async fn run(
&self,
message: impl Into<String>,
) -> Result<AgentReply, AgentError>
pub async fn run( &self, message: impl Into<String>, ) -> Result<AgentReply, AgentError>
Run a complete local agent turn, including any requested host tools.
With no tools registered this is one inference call. Otherwise Ed
alternates between the model and the host’s executor until the model
answers in text, or until
max_tool_rounds is spent, whichever
comes first. Reaching the budget is reported to the sink as a warning,
and yields AgentError::ToolRoundsExhausted if there is no usable
text by then.
Reports EventSink::agent_replied on success. It does not report
EventSink::replied; that belongs to send.
Sourcepub async fn info(&self) -> EngineInfo
pub async fn info(&self) -> EngineInfo
Current status, loaded model, footprint, and history length.
Sourcepub async fn history(&self) -> Vec<ChatMessage>
pub async fn history(&self) -> Vec<ChatMessage>
The conversation so far.
Sourcepub async fn clear_history(&self) -> usize
pub async fn clear_history(&self) -> usize
Clear the conversation, returning how many messages were dropped.
Leaves the model loaded — this starts a new conversation, it doesn’t tear down the engine.
Also drops every AllowForSession grant. The user approved those
mutating tools for a conversation, and this ends the conversation;
carrying the grants into the next one would keep consent alive past the
thing it was given for.
Trait Implementations§
Auto Trait Implementations§
impl<S = NoopSink> !Freeze for Ed<S>
impl<S = NoopSink> !RefUnwindSafe for Ed<S>
impl<S = NoopSink> !UnwindSafe for Ed<S>
impl<S> Forget for Ed<S>
impl<S> Move for Ed<S>
impl<S> Send for Ed<S>where
S: Send,
impl<S> Sync for Ed<S>where
S: Sync,
impl<S> Unpin for Ed<S>where
S: Unpin,
impl<S> UnsafeUnpin for Ed<S>where
S: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for T
impl<T> MaybeSync for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> SpeculativeProposePreparation for T
impl<T> SpeculativeProposePreparation for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.