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
impl Executor
Sourcepub fn new(
registry: impl Into<Arc<Registry>>,
config: impl Into<Arc<Config>>,
) -> Self
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).
Sourcepub fn with_strategy_name(
registry: impl Into<Arc<Registry>>,
config: impl Into<Arc<Config>>,
name: &str,
) -> Result<Self, ModuleError>
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".
Sourcepub fn with_strategy(
registry: impl Into<Arc<Registry>>,
config: impl Into<Arc<Config>>,
strategy: ExecutionStrategy,
) -> Self
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.
Sourcepub 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
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.
Sourcepub fn middlewares(&self) -> Vec<String>
pub fn middlewares(&self) -> Vec<String>
Get the names of all middlewares in pipeline order.
Sourcepub fn set_approval_handler(&mut self, handler: Box<dyn ApprovalHandler>)
pub fn set_approval_handler(&mut self, handler: Box<dyn ApprovalHandler>)
Set the approval handler.
Sourcepub fn use_middleware(
&self,
middleware: Box<dyn Middleware>,
) -> Result<(), ModuleError>
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 &self — MiddlewareManager 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.
Sourcepub fn remove_middleware(&self, name: &str) -> bool
pub fn remove_middleware(&self, name: &str) -> bool
Remove a middleware by name (legacy alias).
Sourcepub async fn call(
&self,
module_id: &str,
inputs: Value,
ctx: Option<&Context<Value>>,
version_hint: Option<&str>,
) -> Result<Value, ModuleError>
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.
Sourcepub async fn validate(
&self,
module_id: &str,
inputs: &Value,
ctx: Option<&Context<Value>>,
) -> Result<PreflightResult, ModuleError>
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.
Sourcepub fn from_registry(
registry: impl Into<Arc<Registry>>,
config: impl Into<Arc<Config>>,
) -> Self
pub fn from_registry( registry: impl Into<Arc<Registry>>, config: impl Into<Arc<Config>>, ) -> Self
Create an executor from a registry and config.
Sourcepub 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>>
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)
Erritem 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.
Sourcepub fn strategy(&self) -> &ExecutionStrategy
pub fn strategy(&self) -> &ExecutionStrategy
Get a reference to the executor’s execution strategy.
Sourcepub fn describe_pipeline(&self) -> StrategyInfo
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.
Sourcepub fn register_strategy(info: StrategyInfo)
👎Deprecated since 0.20.0: Use the module-level register_strategy function directly.
pub fn register_strategy(info: StrategyInfo)
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.
Sourcepub fn list_strategies() -> Vec<StrategyInfo>
👎Deprecated since 0.20.0: Use the module-level list_strategies function directly.
pub fn list_strategies() -> Vec<StrategyInfo>
Use the module-level list_strategies function directly.
List all registered strategy summaries.
Delegates to the module-level list_strategies function.
Sourcepub async fn call_with_trace(
&self,
module_id: &str,
inputs: Value,
ctx: Option<&Context<Value>>,
strategy: Option<&ExecutionStrategy>,
) -> Result<(Value, PipelineTrace), ModuleError>
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.
Sourcepub fn use_before(
&self,
middleware: Box<dyn BeforeMiddleware>,
) -> Result<(), ModuleError>
pub fn use_before( &self, middleware: Box<dyn BeforeMiddleware>, ) -> Result<(), ModuleError>
Add a before middleware.
Sourcepub fn use_after(
&self,
middleware: Box<dyn AfterMiddleware>,
) -> Result<(), ModuleError>
pub fn use_after( &self, middleware: Box<dyn AfterMiddleware>, ) -> Result<(), ModuleError>
Add an after middleware.