Skip to main content

Crate layer0

Crate layer0 

Source
Expand description

§layer0 — Protocol traits for composable agentic AI systems

This crate defines the four protocol boundaries and two cross-cutting interfaces that compose to form any agentic AI system.

§The Protocols

ProtocolTraitWhat it does
① OperatorOperatorWhat one operator does per cycle
② OrchestrationOrchestratorHow operators compose + durability
③ StateStateStoreHow data persists across turns
④ EnvironmentEnvironmentIsolation, credentials, resources

§The Interfaces

InterfaceTypesWhat it does
⑤ MiddlewareDispatchMiddleware, StoreMiddleware, ExecMiddlewareInterception + policy
⑥ LifecycleBudgetEvent, CompactionEventCross-layer coordination

§Design Principle

Every protocol trait is operation-defined, not mechanism-defined. Operator::execute means “cause this agent to process one cycle” — not “make an API call” or “run a subprocess.” This is what makes implementations swappable: a Temporal workflow, a function call, and a future system that doesn’t exist yet all implement the same trait.

§Companion Documents

  • See ARCHITECTURE.md for design rationale

§Dependency Notes

This crate depends on serde_json::Value for extension data fields (metadata, tool inputs, custom payloads). This is an intentional choice: JSON is the universal interchange format for agentic systems, and serde_json::Value is the de facto standard in the Rust ecosystem. The alternative (generic T: Serialize) would complicate trait object safety without practical benefit.

§Future: Native Async Traits

Protocol traits currently use async-trait (heap-allocated futures). When Rust stabilizes async fn in dyn Trait with Send bounds, these traits will migrate to native async. This will be a breaking change in a minor version bump before v1.0.

Re-exports§

pub use content::Content;
pub use content::ContentBlock;
pub use context::Context;
pub use context::ContextError;
pub use context::ContextMessage;
pub use context::ContextSnapshot;
pub use context::ContextWatcher;
pub use context::Message;
pub use context::MessageMeta;
pub use context::OperatorContext;
pub use context::Position;
pub use context::Role;
pub use context::WatcherVerdict;
pub use duration::DurationMs;
pub use effect::Effect;
pub use effect::Scope;
pub use effect::SignalPayload;
pub use environment::Environment;
pub use environment::EnvironmentSpec;
pub use error::EnvError;
pub use error::OperatorError;
pub use error::OrchError;
pub use error::StateError;
pub use id::OperatorId;
pub use id::ScopeId;
pub use id::SessionId;
pub use id::WorkflowId;
pub use lifecycle::BudgetEvent;
pub use lifecycle::CompactionEvent;
pub use lifecycle::CompactionPolicy;
pub use middleware::DispatchMiddleware;
pub use middleware::DispatchNext;
pub use middleware::DispatchStack;
pub use middleware::ExecMiddleware;
pub use middleware::ExecNext;
pub use middleware::ExecStack;
pub use middleware::StoreMiddleware;
pub use middleware::StoreReadNext;
pub use middleware::StoreStack;
pub use middleware::StoreWriteNext;
pub use operator::ExitReason;
pub use operator::Operator;
pub use operator::OperatorConfig;
pub use operator::OperatorInput;
pub use operator::OperatorMetadata;
pub use operator::OperatorOutput;
pub use operator::SubDispatchRecord;
pub use operator::ToolMetadata;
pub use orchestrator::Orchestrator;
pub use orchestrator::QueryPayload;
pub use secret::SecretAccessEvent;
pub use secret::SecretAccessOutcome;
pub use secret::SecretSource;
pub use state::ContentKind;
pub use state::Lifetime;
pub use state::MemoryTier;
pub use state::SearchOptions;
pub use state::SearchResult;
pub use state::StateReader;
pub use state::StateStore;
pub use state::StoreOptions;

Modules§

content
Universal content types that cross every protocol boundary.
context
Context management for operator message histories.
duration
Stable duration type for protocol wire format.
effect
Effect system — side-effects declared by operators for external execution.
environment
The Environment protocol — isolation, credentials, and resource constraints.
error
Error types for each protocol.
id
Typed ID wrappers for operator, session, workflow, and scope identifiers.
lifecycle
Lifecycle events — cross-protocol coordination vocabulary.
middleware
Per-boundary middleware traits using the continuation pattern.
operator
The Operator protocol — what one operator does per cycle.
orchestrator
The Orchestrator protocol — how operators from different agents compose.
secret
Secret management data types — the stability contract for credential resolution.
state
The State protocol — how data persists and is retrieved across turns.