Skip to main content

Ed

Struct Ed 

Source
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 Ed<NoopSink>

Source

pub fn new() -> Self

An agent that reports nothing. Poll info for state.

Source§

impl<S: EventSink> Ed<S>

Source

pub fn with_sink(sink: S) -> Self

An agent that reports transitions and replies to sink.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn load_with<'a, F, Fut>( &'a self, model_name: &str, load: F, ) -> Result<Duration, InferenceError>
where F: FnOnce(&'a ChatEngine) -> Fut, Fut: Future<Output = 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.

Source

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.

Source

pub async fn unload(&self) -> Option<String>

Unload the current model, returning its display name if one was loaded.

Source

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.

Source

pub async fn register_tool( &self, tool: AgentToolDefinition, ) -> Result<(), AgentError>

Register a host capability that the model may request.

Source

pub async fn unregister_tool(&self, name: &str) -> bool

Source

pub async fn remove_all_tools(&self)

Source

pub fn cancel(&self)

Request cancellation of the active agent turn.

Source

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.

Source

pub async fn info(&self) -> EngineInfo

Current status, loaded model, footprint, and history length.

Source

pub async fn is_loaded(&self) -> bool

Whether a model is loaded and ready.

Source

pub async fn history(&self) -> Vec<ChatMessage>

The conversation so far.

Source

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§

Source§

impl Default for Ed<NoopSink>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T> ⓘ
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T> ⓘ

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T> ⓘ

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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