Skip to main content

enact_core/
lib.rs

1//! enact-core - The core runtime for graph-centric agent execution
2//!
3//! This crate provides the foundational types and runtime for executing
4//! agent graphs with full observability and control.
5//!
6//! ## Architecture
7//!
8//! ```text
9//! ┌─────────────────────────────────────────────────────────────────────┐
10//! │                           enact-core                                │
11//! ├─────────────────────────────────────────────────────────────────────┤
12//! │  kernel/       - ExecutionKernel, state machine, reducer, replay    │
13//! │  flow/         - Sequential, parallel, conditional, loop primitives │
14//! │  callable/     - Callable trait, LlmCallable, GraphCallable         │
15//! │  policy/       - Execution, tool, tenant policies and guardrails    │
16//! │  streaming/    - Events, event log, IDs, SSE streaming              │
17//! │  graph/        - StateGraph, CompiledGraph, nodes, edges            │
18//! │  telemetry/    - OpenTelemetry integration, spans, traces           │
19//! │  providers/    - LLM adapters (Azure, Anthropic, Gemini)            │
20//! │  tool/         - Tool trait and implementations                     │
21//! │  memory/       - Episodic, semantic, working memory (future)        │
22//! └─────────────────────────────────────────────────────────────────────┘
23//! ```
24//!
25//! ## Core Concepts
26//!
27//! - **ExecutionId**: One run of a blueprint (Agent/Graph/Workflow)
28//! - **StepId**: A distinct action within that execution
29//! - **ArtifactId**: Data produced by steps
30//! - **RuntimeContext**: The execution context spine
31//! - **TenantContext**: Multi-tenant isolation boundary (REQUIRED)
32//!
33//! ## Getting Started
34//!
35//! Most users should start with:
36//!
37//! ```rust
38//! use enact_core::prelude::*;
39//! ```
40//!
41//! This imports the stable, user-facing API for defining agents, graphs, and executions.
42//! Internal modules remain accessible for advanced use cases.
43//!
44//! @see docs/TECHNICAL/01-EXECUTION-TELEMETRY.md
45//! @see docs/TECHNICAL/02-ENACT-CORE-ARCHITECTURE.md
46
47// =============================================================================
48// Core Modules
49// =============================================================================
50
51pub mod callable; // Callable trait (Agent abstraction)
52pub mod context; // TenantContext, RuntimeContext, TraceContext
53pub mod flow; // Sequential, parallel, conditional, loop
54pub mod kernel; // ExecutionKernel, state machine, reducer, replay
55pub mod policy; // Execution, tool, tenant policies
56
57// =============================================================================
58// Existing Modules
59// =============================================================================
60
61pub mod background; // Background execution and triggers (Phase 5)
62pub mod graph;
63pub mod inbox; // Mid-execution guidance (INV-INBOX-*)
64pub mod memory;
65pub mod providers;
66pub mod routing; // v6: model routing primitives and decisions
67pub mod runner;
68pub mod signal;
69pub mod storage; // Storage factory for event/state stores
70pub mod streaming; // Events, event log, IDs, SSE streaming
71pub mod telemetry; // OpenTelemetry integration
72pub mod tool;
73pub mod util;
74pub mod workflow; // v5: Workflow blueprints, contracts, roles
75
76// =============================================================================
77// Re-exports - Kernel
78// =============================================================================
79
80pub use kernel::{
81    reduce, replay, EventLog as KernelEventLog, Execution, ExecutionAction, ExecutionKernel,
82    ExecutionState, ReducerError, ReplayError, Step, StepState, WaitReason,
83};
84
85// =============================================================================
86// Re-exports - Error Taxonomy (feat-02)
87// =============================================================================
88
89pub use kernel::{
90    // Retry policies
91    BackoffStrategy,
92    // Error types
93    ExecutionError,
94    ExecutionErrorCategory,
95    // Specific error codes
96    LlmErrorCode,
97    RetryPolicy,
98    ToolErrorCode,
99};
100
101// =============================================================================
102// Re-exports - Enforcement & Limits (feat-03)
103// =============================================================================
104
105pub use kernel::{
106    // Middleware
107    EnforcementMiddleware,
108    EnforcementPolicy,
109    // Enforcement results
110    EnforcementResult,
111    EnforcementViolation,
112    EnforcementWarning,
113    // Usage tracking
114    ExecutionUsage,
115    // Timeout guard
116    StepTimeoutGuard,
117    UsageSnapshot,
118    ViolationType,
119};
120
121// =============================================================================
122// Re-exports - Artifact Lifecycle (feat-04)
123// =============================================================================
124
125pub use kernel::artifact::{
126    // Metadata
127    ArtifactMetadata,
128    // Store trait and errors
129    ArtifactStore,
130    ArtifactStoreError,
131    ArtifactType,
132    CompressionType,
133    // Implementations
134    FilesystemArtifactStore,
135};
136
137// =============================================================================
138// Re-exports - Flow
139// =============================================================================
140
141pub use flow::{
142    Branch, Condition, ConditionalFlow, FanIn, FanOut, LoopCondition, LoopFlow, ParallelFlow,
143    ParallelResult, SequentialFlow,
144};
145
146// =============================================================================
147// Re-exports - Callable
148// =============================================================================
149
150pub use callable::{
151    Callable,
152    // Phase 6: Composite Callables
153    CallableDescriptor,
154    CallableInvocation,
155    CallableInvocationResult,
156    CallableInvoker,
157    CallableRegistry,
158    CostTier,
159    DiscoveryQuery,
160    DiscoveryResult,
161    DynCallable,
162    GraphCallable,
163    LlmCallable,
164    ResourceAllocation,
165    ResourceAllocationStrategy,
166    ResourceBudget,
167};
168
169// =============================================================================
170// Re-exports - Policy
171// =============================================================================
172
173pub use policy::{
174    ContentFilter,
175    ExecutionLimits,
176    ExecutionPolicy,
177    FeatureFlags,
178    FilterAction,
179    FilterResult,
180    // Input processors (feat-09: Guardrails)
181    InputProcessor,
182    InputProcessorPipeline,
183    InputProcessorResult,
184    PiiInputMode,
185    PiiInputProcessor,
186    PolicyAction,
187    PolicyContext,
188    PolicyDecision,
189    PolicyEvaluator,
190    TenantLimits,
191    TenantPolicy,
192    ToolPermissions,
193    ToolPolicy,
194    ToolTrustLevel,
195};
196
197// =============================================================================
198// Re-exports - Streaming (events, event log, SSE)
199// =============================================================================
200
201pub use streaming::{
202    ControlAction,
203    ControlActor,
204    ControlEvent,
205    ControlOutcome,
206    // Protection layer (feat-09: Guardrails)
207    DataDestination,
208    DecisionRecord,
209    DecisionType,
210    Event,
211    // Wire format for SSE
212    EventEmitter,
213    // Event log (persistence)
214    EventLog,
215    EventLogEntry,
216    EventStore,
217    EventStream,
218    // Domain events
219    ExecutionContext,
220    ExecutionEvent,
221    ExecutionEventType,
222    InMemoryEventStore,
223    OutputProcessor,
224    PiiProtectionProcessor,
225    ProcessedEvent,
226    ProcessorPipeline,
227    // Protected emitter with processor pipeline
228    ProtectedEventEmitter,
229    ProtectionContext,
230    StreamEvent,
231    StreamMode,
232};
233
234// =============================================================================
235// Re-exports - IDs and State Types (from streaming)
236// =============================================================================
237
238pub use streaming::{
239    // ID prefix constants
240    prefixes,
241    // Primary IDs
242    ArtifactId,
243    ExecutionId,
244    GraphId,
245    // Message/Thread IDs
246    MessageId,
247    NodeId,
248    // Parent linkage
249    ParentLink,
250    ParentType,
251    RunId,
252    StepId,
253    // Step/Node types
254    StepType,
255    TenantId,
256    ThreadId,
257    UserId,
258};
259
260// =============================================================================
261// Re-exports - MessageStore (feat-05 Persistence)
262// =============================================================================
263
264pub use kernel::{
265    // Message types
266    CostInfo,
267    ExecutionStats,
268    FinishReason,
269    // Store trait and implementation
270    InMemoryMessageStore,
271    Message,
272    MessageMetadata,
273    MessagePart,
274    MessageRole,
275    MessageStore,
276    Thread,
277    TokenUsage,
278};
279
280// =============================================================================
281// Re-exports - Context (TenantContext, RuntimeContext, etc.)
282// =============================================================================
283
284pub use context::{
285    // Invocation context
286    InvocationContext,
287    InvocationServices,
288    ResourceLimits,
289    // Runtime context (the spine)
290    RuntimeContext,
291    RuntimeContextBuilder,
292    SessionContext,
293    // Tenant context (REQUIRED for every execution)
294    TenantContext,
295    // Trace context (OpenTelemetry)
296    TraceContext,
297};
298
299// =============================================================================
300// Re-exports - Graph & Execution
301// =============================================================================
302
303pub use graph::{
304    Checkpoint, CheckpointStore, CompiledGraph, FunctionNode, InMemoryCheckpointStore, Node,
305    NodeState, StateGraph,
306};
307
308// =============================================================================
309// Re-exports - Runner
310// =============================================================================
311
312pub use runner::{run_parallel, DefaultRunner, InterruptableRunner, Runner};
313
314// =============================================================================
315// Re-exports - Inbox (Mid-Execution Guidance)
316// =============================================================================
317
318pub use inbox::{
319    // Message types
320    A2aMessage,
321    ControlAction as InboxControlAction,
322    ControlMessage,
323    EvidenceImpact,
324    EvidenceSource,
325    EvidenceUpdate,
326    GuidanceMessage,
327    GuidancePriority,
328    GuidanceSource,
329    InMemoryInboxStore,
330    InboxMessage,
331    InboxMessageType,
332    // Store
333    InboxStore,
334};
335
336// =============================================================================
337// Re-exports - Background (Phase 5: Background Callables)
338// =============================================================================
339
340pub use background::{
341    apply_transform,
342    // Executor types
343    BackgroundExecution,
344    BackgroundExecutionConfig,
345    BackgroundExecutionMode,
346    BackgroundExecutionQueue,
347    BackgroundExecutionStatus,
348    // Trigger types
349    RetryConfig,
350    // Target binding types
351    TargetBindingConfig,
352    TargetBindingResult,
353    TargetBindingTransform,
354    TargetBindingType,
355    ThresholdOperator,
356    Trigger,
357    TriggerAction,
358    TriggerCondition,
359    TriggerFiredEvent,
360    TriggerId,
361    TriggerStatus,
362    TriggerType,
363};
364
365// =============================================================================
366// Re-exports - Storage Factory
367// =============================================================================
368
369pub use storage::{
370    create_event_log, create_event_store, create_state_store, EventStoreConfig, InMemoryStateStore,
371    StateStoreConfig, StorageContext,
372};
373pub use streaming::{JsonlEventStore, JsonlStateStore};
374
375// =============================================================================
376// Re-exports - Providers & Tools
377// =============================================================================
378
379// Re-export provider trait and types (implementations are in enact-providers)
380pub use providers::{
381    ChatMessage, ChatRequest, ChatResponse, EmbeddingRequest, EmbeddingResponse, ModelCapabilities,
382    ModelProvider,
383};
384pub use routing::{
385    resolve_model_precedence, ModelRouter, ModelSelectionSource, RoutingDecision, RoutingPolicy,
386    RoutingProfile, DEFAULT_MODEL_ROUTER_ID,
387};
388pub use tool::{FunctionTool, Tool, ToolExecutionContext, ToolExecutionError, ToolExecutor};
389
390// =============================================================================
391// Prelude - Stable, user-facing API
392// =============================================================================
393
394/// Prelude module - Convenient imports for most users
395///
396/// This module exports the stable, user-facing API for defining agents, graphs,
397/// and executions. It is intentionally small and opinionated.
398///
399/// **Important**: The prelude is semver-sensitive and part of the brand promise.
400/// Changes here should be rare and intentional.
401///
402/// # Usage
403///
404/// ```rust
405/// use enact_core::prelude::*;
406/// ```
407///
408/// This imports:
409/// - Core runtime types (`ExecutionKernel`)
410/// - Graph authoring & execution (`StateGraph`, `CompiledGraph`)
411/// - Execution abstractions (`Callable`, `LlmCallable`, `Tool`, `FunctionTool`)
412/// - Execution identity (`ExecutionId`, `StepId`)
413/// - Observability (`EventStream`, `EventLog`)
414/// - Workflow blueprints (`WorkflowDefinition`, `WorkflowLoader`)
415pub mod prelude {
416    // Core runtime
417    pub use crate::kernel::ExecutionKernel;
418
419    // Graph authoring & execution
420    pub use crate::graph::{CompiledGraph, StateGraph};
421
422    // Execution abstractions
423    pub use crate::callable::{Callable, LlmCallable};
424    pub use crate::tool::{FunctionTool, Tool};
425
426    // Execution identity
427    pub use crate::kernel::{ExecutionId, StepId};
428
429    // Error taxonomy (feat-02)
430    pub use crate::kernel::{ExecutionError, ExecutionErrorCategory};
431
432    // Observability
433    pub use crate::streaming::{EventLog, EventStream};
434
435    // Workflow blueprints (v5)
436    pub use crate::workflow::{
437        WorkflowCompiler, WorkflowDefinition, WorkflowLoader, WorkflowValidator,
438    };
439}