Module primitives

Module primitives 

Source
Expand description

§The L2 contract — authoring

This module is the engineered surface of the authoring layer: the closed set of primitives L2 exposes to applications, curated and named. L0 moves frames; L1 gives them meaning and enforces it; this layer makes a whole application sayable — in one fluent expression, or in one JSON document.

L2 promises: two equivalent ways to state a session. In code: the Live builder and the AgentBuilder combinators, composed through eight one-letter algebras — State >>, Context +, Tools |, Prompt +, Middleware |, Artifacts +, Evaluation |, Guards |. As data: SessionSpec, the same session as one serializable document, with load-time validation and offline tests. What serializes, runs; what can fail, fails before connect (check_contracts, SessionSpec::validate).

L2 never: invents runtime semantics. Every builder method lowers to an L1 primitive; every spec field lowers to a builder method. This layer adds phrasing, not behavior — which is why the JSON document and the fluent chain stay equivalent.

The primitives, by concern:

ConcernPrimitives
Voice sessionLive (·builder → connect → LiveHandle)
Text agentsAgentBuilder, Pipeline >>, FanOut |, * loops, until, / fallback
The algebraS, C, T, P, M, A, E, G
Session as dataSessionSpec, SpecResources, SpecTest (SessionSpec::run_tests)
Proof before connectcheck_contracts, ContractViolation
TelephonyTwilioCall (·attach — a phone call on the same pump as a microphone)
Ergonomicslet_clone!

Five lines to a governed voice application (add the voice-io feature for voice::Talk::talk):

// `ignore`: `.talk()` exists only with the `voice-io` feature.
let session = Live::builder()
    .instruction("You are a helpful concierge.")
    .greeting("Greet the caller.")
    .govern(flow)
    .connect_from_env().await?;
session.talk().await?;      // microphone in, speakers out, barge-in handled

Re-exports§

pub use crate::builder::AgentBuilder;
pub use crate::live::Live;
pub use crate::operators::FanOut;
pub use crate::operators::Pipeline;
pub use crate::operators::until;
pub use crate::compose::artifacts::A;
pub use crate::compose::context::C;
pub use crate::compose::eval::E;
pub use crate::compose::guards::G;
pub use crate::compose::middleware::M;
pub use crate::compose::prompt::P;
pub use crate::compose::state::S;
pub use crate::compose::tools::T;
pub use crate::spec::SessionSpec;
pub use crate::spec::SpecResources;
pub use crate::spec::SpecTest;
pub use crate::telephony::TwilioCall;
pub use crate::testing::ContractViolation;
pub use crate::testing::check_contracts;