ed_agent/lib.rs
1//! Ed: an embeddable, local-LLM-first chat agent.
2//!
3//! Ed sits one layer above the [`onde`] inference SDK. `onde` gives you a
4//! [`ChatEngine`](onde::inference::ChatEngine) you can load a model into and
5//! send messages to; Ed adds the part every application built on it was
6//! writing for itself:
7//!
8//! - **Lifecycle orchestration.** Loading a model is a sequence of state
9//! changes, not one call. Ed drives `Loading -> Ready` (or `-> Error`) and
10//! reports each transition.
11//! - **Notification.** `onde` exposes status by polling
12//! [`info()`](onde::inference::ChatEngine::info). A UI needs to be told.
13//! Ed pushes transitions and replies to a [`StatusSink`] the host implements.
14//! - **A flattened reply.** Inference returns `Result<InferenceResult, _>`;
15//! a frontend wants one shape covering both outcomes. That's [`ChatReply`].
16//!
17//! Ed deliberately does *not* own sessions, persistence, model catalogues, or
18//! downloads. Those differ per application and belong to the host. For
19//! persistence it defines the [`SessionStore`] seam the host implements.
20//!
21//! # Platforms
22//!
23//! Ed has no `cfg(target_os)` gates. `onde` already splits real and fallback
24//! implementations internally, so this crate compiles on every platform `onde`
25//! supports (macOS, iOS, tvOS, visionOS, watchOS, Windows, Linux, Android) and
26//! simply surfaces `onde`'s error where it can't run inference. On
27//! `wasm32-unknown-unknown` it builds against `onde`'s web target. Other
28//! targets outside that list get a stub engine with the same signatures,
29//! whose calls all return an "unsupported" error.
30//!
31//! Do not add platform gates here, and be careful about adding them in a host:
32//! a gate narrower than `onde`'s own support list silently disables chat on a
33//! platform that would have worked.
34//!
35//! # Example
36//!
37//! ```no_run
38//! use ed_agent::{Ed, GgufModelConfig};
39//!
40//! # async fn example() {
41//! let ed = Ed::new();
42//! let config = GgufModelConfig::qwen25_1_5b();
43//! ed.load(config, None, None).await.expect("load");
44//!
45//! let reply = ed.send("Summarise this thread.").await;
46//! println!("{}", reply.reply.unwrap_or_default());
47//! # }
48//! ```
49
50#![forbid(unsafe_code)]
51
52mod ed;
53pub mod maybe;
54mod reply;
55mod session;
56mod sink;
57mod stream;
58mod tool;
59
60pub use ed::Ed;
61pub use reply::ChatReply;
62pub use session::{SessionError, SessionMeta, SessionStore};
63pub use sink::{EventSink, NoopSink, StatusSink};
64pub use stream::TextStream;
65pub use tool::{
66 AgentConfig, AgentError, AgentReply, AgentToolDefinition, ApprovalDecision, ApprovalHandler,
67 ApprovalRequest, DenyApprovals, RejectingExecutor, ToolCall, ToolExecutionResult, ToolExecutor,
68 ToolRisk,
69};
70
71// Re-exported so a host depends on `ed-agent` alone and never has to match a
72// second `onde` version against this crate's.
73pub use onde::inference::types::{ChatMessage, ChatRole};
74pub use onde::inference::{
75 ChatEngine, EngineInfo, EngineStatus, GgufModelConfig, InferenceError, SamplingConfig,
76 ToolCallingSupport, UqffModelConfig,
77};