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