Skip to main content

Operator

Trait Operator 

Source
pub trait Operator: Send + Sync {
    // Required method
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 Ctx,
        system: Option<String>,
        prompt: String,
        worker: Option<WorkerBinding>,
        worker_token: CapToken,
    ) -> Pin<Box<dyn Future<Output = Result<WorkerResult, WorkerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn requires_worker_binding(&self) -> bool { ... }
}
Expand description

The Operator trait: takes a spawn request and returns a WorkerResult. The backend for OperatorSpawner. Implementations are free to differ per kind; the spawner just calls execute and stays out of the internals.

Arguments — a two-slot payload plus worker_token (the thin path was added later) plus worker (the Blueprint-baked binding, added later still):

  • system: the agent persona — the rendered value of AgentDef.profile.system_prompt after template expansion. None means no profile. Expected to map straight onto the LLM API’s system message; direct-LLM operators consume this.
  • prompt: task-specific intent — TaskSpec.initial_directive, pulled server-side via engine.fetch_prompt. Expected to map straight onto the LLM API’s user message.
  • worker: the compile-time-baked WorkerBinding (subagent type + declared tools) resolved from AgentDef.profile.worker_binding. None for agents whose profile has no worker_binding set. Backends that require one (see Operator::requires_worker_binding) must fail loud rather than silently degrade when this is None.
  • worker_token: a capability token (Role::Worker, 600s TTL, scopes = ["*"]). Thin-path operators (a a WebSocket-backed operator session, for instance) encode() this token and hand it to the MainAI WebSocket client, so the SubAgent can hit /v1/worker/prompt + /v1/worker/result with Authorization: Bearer <encoded>. Direct-LLM operators may ignore it.

The trait passes both slots so the same signature works for the thin path and the direct path; the implementation picks which one it takes (consume the server-rendered system directly, or forward the token and let the client fetch).

Required Methods§

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 Ctx, system: Option<String>, prompt: String, worker: Option<WorkerBinding>, worker_token: CapToken, ) -> Pin<Box<dyn Future<Output = Result<WorkerResult, WorkerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Executes one spawn request against this operator’s backend and returns the resulting WorkerResult (or a WorkerError if the backend failed). See the trait doc above for the meaning of each argument.

Provided Methods§

Source

fn requires_worker_binding(&self) -> bool

Whether this operator backend requires a non-None worker binding to execute at all. false by default (direct-LLM operators consume system / prompt directly and have no SubAgent to dispatch). WS thin-path operators override this to true — the compiler uses it to fail loud at compile() time when AgentDef.profile.worker_binding is absent, rather than silently degrading at dispatch time.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§