enact-core 0.0.2

Core agent runtime for Enact - Graph-Native AI agents
Documentation
//! Kernel - The Execution Engine
//!
//! The kernel is the heart of enact-core. It:
//! - Defines the execution state machine
//! - Applies all state transitions through a reducer
//! - Provides the ExecutionKernel for running graphs
//! - Enables replay from event logs
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────┐
//! │              ExecutionKernel                │
//! │  ┌───────────────────────────────────────┐  │
//! │  │           Execution State             │  │
//! │  │  (ExecutionState, Steps, Artifacts)   │  │
//! │  └───────────────────────────────────────┘  │
//! │                     │                       │
//! │                     ▼                       │
//! │  ┌───────────────────────────────────────┐  │
//! │  │              Reducer                  │  │
//! │  │  (Action, State) → State              │  │
//! │  └───────────────────────────────────────┘  │
//! │                     │                       │
//! │                     ▼                       │
//! │  ┌───────────────────────────────────────┐  │
//! │  │           Event Emitter               │  │
//! │  │  (StreamEvent for UI/persistence)     │  │
//! │  └───────────────────────────────────────┘  │
//! └─────────────────────────────────────────────┘
//! ```
//!
//! ## Key Invariants
//!
//! 1. **Single Source of Truth**: ExecutionKernel owns the Execution state
//! 2. **Reducer-Only Transitions**: All state changes go through the reducer
//! 3. **Deterministic**: Same actions → same state (enables replay)
//! 4. **Observable**: All transitions emit events
//!
//! @see docs/TECHNICAL/01-EXECUTION-TELEMETRY.md

pub mod artifact;
pub mod cost;
mod enforcement;
mod error;
mod event;
mod execution_model;
mod execution_state;
mod execution_strategy;
pub mod ids;
mod interrupt;
#[allow(clippy::module_inception)]
mod kernel;
pub mod persistence;
mod reducer;
mod replay;

// =============================================================================
// IDs - Source of Truth for all execution identifiers
// =============================================================================
pub use ids::{
    // ID prefix constants
    prefixes,
    // Primary IDs
    ArtifactId,
    // Callable types (for billing/traceability)
    CallableType,
    CancellationPolicy,
    ExecutionId,
    GraphId,
    // Message/Thread IDs (MessageStore)
    MessageId,
    NodeId,
    // Parent linkage (causal tracing)
    ParentLink,
    ParentType,
    RunId,
    // SpawnMode (execution isolation control)
    SpawnMode,
    StepId,
    // Step source (discovery tracking for agentic loops)
    StepSource,
    StepSourceType,
    // Step/Node types
    StepType,
    TenantId,
    ThreadId,
    UserId,
};

// =============================================================================
// Events - Source of Truth for all execution events
// =============================================================================
pub use event::{
    // Control events
    ControlAction,
    ControlActor,
    ControlEvent,
    ControlOutcome,
    // Decision audit
    DecisionAlternative,
    DecisionInput,
    DecisionRecord,
    DecisionType,
    Event,
    // Execution events
    ExecutionContext,
    ExecutionEvent,
    ExecutionEventType,
    ModelContext,
};

// =============================================================================
// Core execution types
// =============================================================================
pub use execution_model::{Execution, Step};

// State machine
pub use execution_state::{ExecutionState, StepState, WaitReason};

// Reducer
pub use reducer::{reduce, ExecutionAction, ReducerError};

// Replay
pub use replay::{replay, EventLog, ReplayError};

// The kernel itself
pub use kernel::ExecutionKernel;

// =============================================================================
// Error Taxonomy (feat-02)
// =============================================================================
pub use error::{
    // Retry policies
    BackoffStrategy,
    // Error categories
    ExecutionError,
    ExecutionErrorCategory,
    // Specific error codes
    LlmErrorCode,
    RetryPolicy,
    ToolErrorCode,
};

// =============================================================================
// Enforcement & Limits (feat-03)
// =============================================================================
pub use enforcement::{
    // Middleware
    EnforcementMiddleware,
    EnforcementPolicy,
    // Enforcement results
    EnforcementResult,
    EnforcementViolation,
    EnforcementWarning,
    // Usage tracking
    ExecutionUsage,
    // Long-running execution policy (agentic DAG controls)
    LongRunningExecutionPolicy,
    // Timeout guard
    StepTimeoutGuard,
    UsageSnapshot,
    ViolationType,
};

// =============================================================================
// Execution strategy (parallel, interrupt handling)
// =============================================================================
pub use execution_strategy::{run_parallel, ParallelResult};
pub use interrupt::{InterruptDecision, InterruptReason, InterruptableRunner};

// =============================================================================
// Persistence Layer (feat-05)
// =============================================================================
pub use persistence::{
    // VectorStore
    CollectionInfo,
    // MessageStore
    CostInfo,
    DistanceMetric,
    // EventStore
    EventStore,
    ExecutionEventData,
    // StateStore
    ExecutionSnapshot,
    ExecutionStats,
    FinishReason,
    InMemoryMessageStore,
    Message,
    MessageMetadata,
    MessagePart,
    MessageRole,
    MessageStore,
    StateStore,
    StateStoreJsonExt,
    // Base trait
    StorageBackend,
    StoredEvent,
    Thread,
    TokenUsage,
    VectorDocument,
    VectorFilter,
    VectorSearchResult,
    VectorStore,
};

// =============================================================================
// Cost & Usage Tracking (Observability)
// =============================================================================
pub use cost::{CostCalculator, ModelPricing, TokenUsage as LlmTokenUsage, UsageAccumulator};