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_token: CapToken,
    ) -> Pin<Box<dyn Future<Output = Result<WorkerResult, WorkerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
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):

  • 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_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_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.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§