Skip to main content

weirdnet_agent/
lib.rs

1//! Weirdnet agent runtime.
2//!
3//! A model-agnostic agent loop shared by WeirdBrains apps. Apps supply a
4//! [`ModelBackend`], tool sources and an [`Approver`]; this crate runs the turn
5//! loop, enforces the approval [`Policy`] and research [`Budget`], and records a
6//! [`Trace`] whose [`Citation`]s are checked against the steps that fetched them.
7//!
8//! - [`session`]: [`AgentSession`], the turn loop with streaming [`AgentEvent`]s.
9//! - [`cancel`]: [`CancelToken`], checked between model and tool steps.
10//! - [`tool`]: [`Tool`], [`ToolSource`] (local now, MCP and remote nodes later) and [`ToolRegistry`].
11//! - [`policy`]: tiers, per-companion per-site grants, task approvals and standing allows.
12//! - [`budget`]: searches, pages, concurrency and time limits.
13//! - [`trace`]: steps, citations and the cited-step check.
14//! - [`speech`]: speech out (text to speech): [`SpeechProfile`] (what a speaking model does) and
15//!   [`SpeechNeeds`] (what a request needs), for infer/2 `Speak` and catalog routing.
16//! - [`model`]: the model backend trait and chat messages, whose [`Content`] is text or parts
17//!   (text, images, audio, video) with the [`Modalities`] a model needs to read them.
18//! - [`remote`]: protocols between one user's nodes over an app-supplied channel: inference
19//!   (`infer/2` with priorities, queueing, reasoning, tool calls, embeddings, transcription, speech and resume; `infer/1`
20//!   kept for 0.3 nodes), the model catalog, remote tasks (Node companions), and the
21//!   transport-neutral [`remote::pool::Pool`] that fails over and resumes answers across nodes,
22//!   and [`remote::share`] links for pools shared with another Weirdnet identity.
23//! - `pool` (feature): the pool over Weirdnet: inference nodes among the user's linked devices,
24//!   or (`pool::connect_shared`) the nodes of a pool another identity shared.
25//! - `jobs` (feature): synced jobs over the weirdnet-sync job log, claimed under majority-vote
26//!   leases and resumed on another device from their last checkpoint.
27//! - `serve` (feature): serve inference and the catalog on a Weirdnet node, checking callers
28//!   against the device roster and, opt-in, guests of other identities (`serve::GuestAuth`).
29//!
30//! Nothing here is app-specific: browser tools, panels and storage live in the app.
31//!
32//! Public enums are `#[non_exhaustive]`: match them with a wildcard arm.
33
34pub mod budget;
35pub mod cancel;
36pub mod identity;
37#[cfg(feature = "jobs")]
38pub mod jobs;
39pub mod limits;
40pub mod model;
41#[cfg(any(feature = "pool", feature = "serve"))]
42mod net;
43pub mod policy;
44#[cfg(feature = "pool")]
45pub mod pool;
46pub mod remote;
47#[cfg(feature = "serve")]
48pub mod serve;
49pub mod session;
50pub mod speech;
51#[cfg(any(test, feature = "testing"))]
52pub mod testing;
53pub mod tool;
54pub mod trace;
55
56pub use budget::{Budget, BudgetExceeded, BudgetTracker, BudgetUsage, ToolTimer};
57pub use cancel::CancelToken;
58pub use identity::{AgentId, AgentIdentity, AgentKind};
59pub use limits::MediaLimits;
60pub use model::{
61    Content, ContentPart, DeltaSink, ImageUrl, InputAudio, Message, Modalities, ModelBackend, ModelError, ModelNotice, ModelTurn, Role, ToolCall,
62    VideoUrl,
63};
64pub use policy::{
65    ActionRequest, AllowRule, ApprovalPrompt, CompanionScope, Decision, DenyReason, Policy, PolicyError, Scope, SharedPolicy, SiteLevel, SkipNotice,
66    StandingAllow, TaskApprovals, Tier, site_of,
67};
68pub use remote::{Admitted, Authorize, Caller, RemoteError};
69pub use session::{AgentConfig, AgentEvent, AgentSession, ApprovalAnswer, Approver, Outcome, PagesPrompt, StopReason};
70pub use speech::{AudioFormat, CloneMode, SpeechNeeds, SpeechProfile};
71pub use tool::{
72    BudgetCharge, CallTarget, LocalTools, RegistryError, SourceKind, Tool, ToolAnnotations, ToolContext, ToolError, ToolOutput, ToolRegistry,
73    ToolSource, ToolSpec,
74};
75pub use trace::{
76    ApprovalOutcome, Citation, CitationError, CitationTarget, SessionMark, StepId, StepKind, Trace, TraceStep, retain_valid, validate_citations,
77};