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.
19//!
20//! # Platforms
21//!
22//! Ed has no `cfg(target_os)` gates. `onde` already splits real and fallback
23//! implementations internally, so this crate compiles on every platform `onde`
24//! supports (macOS, iOS, tvOS, visionOS, watchOS, Windows, Linux, Android) and
25//! simply surfaces `onde`'s error where it can't run inference. Outside that
26//! list `onde` falls back to a stub whose signatures differ, so Ed does not
27//! build there either.
28//!
29//! Do not add platform gates here, and be careful about adding them in a host:
30//! a gate narrower than `onde`'s own support list silently disables chat on a
31//! platform that would have worked.
32//!
33//! # Example
34//!
35//! ```no_run
36//! use ed_agent::{Ed, GgufModelConfig};
37//!
38//! # async fn example() {
39//! let ed = Ed::new();
40//! let config = GgufModelConfig::qwen25_1_5b();
41//! ed.load(config, None, None).await.expect("load");
42//!
43//! let reply = ed.send("Summarise this thread.").await;
44//! println!("{}", reply.reply.unwrap_or_default());
45//! # }
46//! ```
47
48#![forbid(unsafe_code)]
49
50mod ed;
51mod reply;
52mod sink;
53mod tool;
54
55pub use ed::Ed;
56pub use reply::ChatReply;
57pub use sink::{EventSink, NoopSink, StatusSink};
58pub use tool::{
59 AgentConfig, AgentError, AgentReply, AgentToolDefinition, ApprovalDecision, ApprovalHandler,
60 ApprovalRequest, DenyApprovals, RejectingExecutor, ToolCall, ToolExecutionResult, ToolExecutor,
61 ToolRisk,
62};
63
64// Re-exported so a host depends on `ed-agent` alone and never has to match a
65// second `onde` version against this crate's.
66pub use onde::inference::types::{ChatMessage, ChatRole};
67pub use onde::inference::{
68 ChatEngine, EngineInfo, EngineStatus, GgufModelConfig, InferenceError, SamplingConfig,
69 ToolCallingSupport, UqffModelConfig,
70};