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//! - [`model`]: the model backend trait and chat messages, whose [`Content`] is text or parts
15//!   (text, images, audio) with the [`Modalities`] a model needs to read them.
16//! - [`remote`]: protocols between one user's nodes over an app-supplied channel: inference
17//!   (`infer/2` with priorities, queueing, reasoning, tool calls, embeddings and resume; `infer/1`
18//!   kept for 0.3 nodes), the model catalog, remote tasks (Node companions), and the
19//!   transport-neutral [`remote::pool::Pool`] that fails over and resumes answers across nodes.
20//! - `pool` (feature): the pool over Weirdnet: inference nodes among the user's linked devices.
21//! - `serve` (feature): serve inference and the catalog on a Weirdnet node, checking callers
22//!   against the device roster.
23//!
24//! Nothing here is app-specific: browser tools, panels and storage live in the app.
25//!
26//! Public enums are `#[non_exhaustive]`: match them with a wildcard arm.
27
28pub mod budget;
29pub mod cancel;
30pub mod identity;
31pub mod model;
32#[cfg(any(feature = "pool", feature = "serve"))]
33mod net;
34pub mod policy;
35#[cfg(feature = "pool")]
36pub mod pool;
37pub mod remote;
38#[cfg(feature = "serve")]
39pub mod serve;
40pub mod session;
41#[cfg(any(test, feature = "testing"))]
42pub mod testing;
43pub mod tool;
44pub mod trace;
45
46pub use budget::{Budget, BudgetExceeded, BudgetTracker, BudgetUsage, ToolTimer};
47pub use cancel::CancelToken;
48pub use identity::{AgentId, AgentIdentity, AgentKind};
49pub use model::{Content, ContentPart, DeltaSink, ImageUrl, InputAudio, Message, Modalities, ModelBackend, ModelError, ModelTurn, Role, ToolCall};
50pub use policy::{
51    ActionRequest, AllowRule, ApprovalPrompt, CompanionScope, Decision, DenyReason, Policy, PolicyError, Scope, SharedPolicy, SiteLevel, SkipNotice,
52    StandingAllow, TaskApprovals, Tier, site_of,
53};
54pub use remote::{Admitted, Authorize, Caller, RemoteError};
55pub use session::{AgentConfig, AgentEvent, AgentSession, ApprovalAnswer, Approver, Outcome, PagesPrompt, StopReason};
56pub use tool::{
57    BudgetCharge, CallTarget, LocalTools, RegistryError, SourceKind, Tool, ToolAnnotations, ToolContext, ToolError, ToolOutput, ToolRegistry,
58    ToolSource, ToolSpec,
59};
60pub use trace::{
61    ApprovalOutcome, Citation, CitationError, CitationTarget, SessionMark, StepId, StepKind, Trace, TraceStep, retain_valid, validate_citations,
62};