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//! - `jobs` (feature): synced jobs over the weirdnet-sync job log, claimed under majority-vote
22//! leases and resumed on another device from their last checkpoint.
23//! - `serve` (feature): serve inference and the catalog on a Weirdnet node, checking callers
24//! against the device roster.
25//!
26//! Nothing here is app-specific: browser tools, panels and storage live in the app.
27//!
28//! Public enums are `#[non_exhaustive]`: match them with a wildcard arm.
29
30pub mod budget;
31pub mod cancel;
32pub mod identity;
33#[cfg(feature = "jobs")]
34pub mod jobs;
35pub mod limits;
36pub mod model;
37#[cfg(any(feature = "pool", feature = "serve"))]
38mod net;
39pub mod policy;
40#[cfg(feature = "pool")]
41pub mod pool;
42pub mod remote;
43#[cfg(feature = "serve")]
44pub mod serve;
45pub mod session;
46#[cfg(any(test, feature = "testing"))]
47pub mod testing;
48pub mod tool;
49pub mod trace;
50
51pub use budget::{Budget, BudgetExceeded, BudgetTracker, BudgetUsage, ToolTimer};
52pub use cancel::CancelToken;
53pub use identity::{AgentId, AgentIdentity, AgentKind};
54pub use limits::MediaLimits;
55pub use model::{
56 Content, ContentPart, DeltaSink, ImageUrl, InputAudio, Message, Modalities, ModelBackend, ModelError, ModelNotice, ModelTurn, Role, ToolCall,
57};
58pub use policy::{
59 ActionRequest, AllowRule, ApprovalPrompt, CompanionScope, Decision, DenyReason, Policy, PolicyError, Scope, SharedPolicy, SiteLevel, SkipNotice,
60 StandingAllow, TaskApprovals, Tier, site_of,
61};
62pub use remote::{Admitted, Authorize, Caller, RemoteError};
63pub use session::{AgentConfig, AgentEvent, AgentSession, ApprovalAnswer, Approver, Outcome, PagesPrompt, StopReason};
64pub use tool::{
65 BudgetCharge, CallTarget, LocalTools, RegistryError, SourceKind, Tool, ToolAnnotations, ToolContext, ToolError, ToolOutput, ToolRegistry,
66 ToolSource, ToolSpec,
67};
68pub use trace::{
69 ApprovalOutcome, Citation, CitationError, CitationTarget, SessionMark, StepId, StepKind, Trace, TraceStep, retain_valid, validate_citations,
70};