Skip to main content

Executor

Struct Executor 

Source
pub struct Executor {
    pub registry: Arc<Registry>,
    pub config: Arc<Config>,
    pub acl: Option<Arc<ACL>>,
    pub approval_handler: Option<Arc<dyn ApprovalHandler>>,
    pub middleware_manager: Arc<MiddlewareManager>,
    /* private fields */
}
Expand description

Responsible for executing modules with middleware, ACL, and context management.

Fields§

§registry: Arc<Registry>§config: Arc<Config>§acl: Option<Arc<ACL>>§approval_handler: Option<Arc<dyn ApprovalHandler>>§middleware_manager: Arc<MiddlewareManager>

Implementations§

Source§

impl Executor

Source

pub fn new( registry: impl Into<Arc<Registry>>, config: impl Into<Arc<Config>>, ) -> Self

Create a new executor with the given (shared) registry and config.

Builds a standard execution strategy — all calls go through PipelineEngine. Accepts either an owned Registry/Config (convenient for tests) or a pre-shared Arc<Registry>/Arc<Config> (required for runtime wiring).

Source

pub fn with_strategy_name( registry: impl Into<Arc<Registry>>, config: impl Into<Arc<Config>>, name: &str, ) -> Result<Self, ModuleError>

Create a new executor with a strategy resolved by name.

Built-in preset names: "standard", "internal", "testing", "performance", "minimal".

Source

pub fn with_strategy( registry: impl Into<Arc<Registry>>, config: impl Into<Arc<Config>>, strategy: ExecutionStrategy, ) -> Self

Create a new executor with a custom execution strategy.

Source

pub fn with_options( registry: impl Into<Arc<Registry>>, config: impl Into<Arc<Config>>, middlewares: Option<Vec<Box<dyn Middleware>>>, acl: Option<ACL>, approval_handler: Option<Box<dyn ApprovalHandler>>, ) -> Self

Create a new executor with all optional parameters.

Source

pub fn registry(&self) -> &Registry

Get a reference to the registry.

Source

pub fn middlewares(&self) -> Vec<String>

Get the names of all middlewares in pipeline order.

Source

pub fn set_acl(&mut self, acl: ACL)

Set the ACL for access control.

Source

pub fn set_approval_handler(&mut self, handler: Box<dyn ApprovalHandler>)

Set the approval handler.

Source

pub fn use_middleware( &self, middleware: Box<dyn Middleware>, ) -> Result<(), ModuleError>

Add a middleware to the pipeline.

Returns an error if the middleware’s priority exceeds the allowed range.

Takes &selfMiddlewareManager uses interior mutability, so the executor can be held behind a shared reference and still have middleware added after construction. This removes the previous Arc::get_mut hack that panicked once the middleware manager was cloned into a pipeline context.

Source

pub fn remove(&self, name: &str) -> bool

Remove a middleware by name.

Source

pub fn remove_middleware(&self, name: &str) -> bool

Remove a middleware by name (legacy alias).

Source

pub async fn call( &self, module_id: &str, inputs: Value, ctx: Option<&Context<Value>>, version_hint: Option<&str>, ) -> Result<Value, ModuleError>

Execute (call) a module by ID with the given inputs and context.

Delegates to PipelineEngine::run() using the configured strategy.

Source

pub async fn validate( &self, module_id: &str, inputs: &Value, ctx: Option<&Context<Value>>, ) -> Result<PreflightResult, ModuleError>

Validate module inputs without executing (steps 1-7, spec §12.3).

Runs the pipeline in dry_run mode — pure steps only, side-effecting steps are skipped automatically.

ctx is the optional execution context. When provided, call-chain checks (depth limit, circular-call detection) and ACL caller-identity matching can run against real caller state. When omitted, an anonymous @external context is synthesized for backward compatibility, in which case call-chain checks are no-ops.

Aligned with apcore-python.Executor.validate(module_id, inputs, context=None) and apcore-typescript.Executor.validate(moduleId, inputs?, context?) per PROTOCOL_SPEC §12.2.

Source

pub fn from_registry( registry: impl Into<Arc<Registry>>, config: impl Into<Arc<Config>>, ) -> Self

Create an executor from a registry and config.

Source

pub fn stream<'a>( &'a self, module_id: &str, inputs: Value, ctx: Option<&Context<Value>>, version_hint: Option<&str>, ) -> Pin<Box<dyn Stream<Item = Result<Value, ModuleError>> + Send + 'a>>

Stream execution of a module.

Returns an async Stream of output chunks. Each chunk is delivered to the caller as soon as it is produced by the underlying module — no buffering — so this is true incremental streaming.

Pipeline phases:

  • Phase 1 (pre-stream): context creation, call-chain guard, module lookup, ACL check, approval gate, before-middleware, input validation. Any failure surfaces as the first (and only) Err item in the stream.
  • Phase 2 (body): call module.stream(), forward each chunk to the caller as it arrives, and accumulate copies into a buffer for Phase 3.
  • Phase 3 (post-stream): after the inner stream is exhausted, deep-merge the accumulated chunks, validate the merged result against the module’s output schema, then run after-middleware. If either step fails, the error is yielded as the final item of the output stream.

If the module does not implement stream() (returns None), an error with ErrorCode::GeneralNotImplemented is yielded.

Source

pub fn strategy(&self) -> &ExecutionStrategy

Get a reference to the executor’s execution strategy.

Source

pub fn describe_pipeline(&self) -> StrategyInfo

Return structured info about the configured pipeline.

Returns a StrategyInfo describing the strategy name, step count, step names, and auto-generated description. This matches the spec and aligns with the Python and TypeScript SDK return types.

Use .to_string() on the result for a human-readable summary.

Source

pub fn register_strategy(info: StrategyInfo)

👎Deprecated since 0.20.0:

Use the module-level register_strategy function directly.

Register a strategy’s info in the global registry for introspection.

Delegates to the module-level register_strategy function.

Source

pub fn list_strategies() -> Vec<StrategyInfo>

👎Deprecated since 0.20.0:

Use the module-level list_strategies function directly.

List all registered strategy summaries.

Delegates to the module-level list_strategies function.

Source

pub async fn call_with_trace( &self, module_id: &str, inputs: Value, ctx: Option<&Context<Value>>, strategy: Option<&ExecutionStrategy>, ) -> Result<(Value, PipelineTrace), ModuleError>

Execute a module through the pipeline engine, returning both the output and a full execution trace.

Uses the provided strategy override, or the executor’s default strategy.

Source

pub fn use_before( &self, middleware: Box<dyn BeforeMiddleware>, ) -> Result<(), ModuleError>

Add a before middleware.

Source

pub fn use_after( &self, middleware: Box<dyn AfterMiddleware>, ) -> Result<(), ModuleError>

Add an after middleware.

Trait Implementations§

Source§

impl Debug for Executor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more