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 model;
36#[cfg(any(feature = "pool", feature = "serve"))]
37mod net;
38pub mod policy;
39#[cfg(feature = "pool")]
40pub mod pool;
41pub mod remote;
42#[cfg(feature = "serve")]
43pub mod serve;
44pub mod session;
45#[cfg(any(test, feature = "testing"))]
46pub mod testing;
47pub mod tool;
48pub mod trace;
49
50pub use budget::{Budget, BudgetExceeded, BudgetTracker, BudgetUsage, ToolTimer};
51pub use cancel::CancelToken;
52pub use identity::{AgentId, AgentIdentity, AgentKind};
53pub use model::{
54 Content, ContentPart, DeltaSink, ImageUrl, InputAudio, Message, Modalities, ModelBackend, ModelError, ModelNotice, ModelTurn, Role, ToolCall,
55};
56pub use policy::{
57 ActionRequest, AllowRule, ApprovalPrompt, CompanionScope, Decision, DenyReason, Policy, PolicyError, Scope, SharedPolicy, SiteLevel, SkipNotice,
58 StandingAllow, TaskApprovals, Tier, site_of,
59};
60pub use remote::{Admitted, Authorize, Caller, RemoteError};
61pub use session::{AgentConfig, AgentEvent, AgentSession, ApprovalAnswer, Approver, Outcome, PagesPrompt, StopReason};
62pub use tool::{
63 BudgetCharge, CallTarget, LocalTools, RegistryError, SourceKind, Tool, ToolAnnotations, ToolContext, ToolError, ToolOutput, ToolRegistry,
64 ToolSource, ToolSpec,
65};
66pub use trace::{
67 ApprovalOutcome, Citation, CitationError, CitationTarget, SessionMark, StepId, StepKind, Trace, TraceStep, retain_valid, validate_citations,
68};