Skip to main content

AgentBackend

Trait AgentBackend 

Source
pub trait AgentBackend: Send + Sync {
    // Required methods
    fn id(&self) -> &'static str;
    fn capabilities(&self) -> AgentCapabilities;
    fn run<'life0, 'async_trait>(
        &'life0 self,
        task: AgentTask,
        ctx: RunContext,
    ) -> Pin<Box<dyn Future<Output = Result<AgentResult, BackendError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn as_any(&self) -> &dyn Any;
}
Expand description

A pluggable agent backend (e.g. OpenCode via ACP). Prompt in, structured result out.

§Contract

  • Cancellation: implementations must observe ctx.cancel and return promptly with BackendError::Cancelled when the token fires.
  • Id stability: id() must return a stable string for the backend’s lifetime — it is used as the registry key.
  • Thread safety: the trait requires Send + Sync; backends are typically wrapped in Arc<dyn AgentBackend> and shared across tasks.
  • Downcasting: implement as_any() by returning self to allow callers to downcast to the concrete backend type.

See the module docs for a complete implementation example.

Required Methods§

Source

fn id(&self) -> &'static str

Stable backend id, e.g. “opencode”.

Source

fn capabilities(&self) -> AgentCapabilities

Capability declaration (v0.1: recorded/validated only; routing in v0.2).

Source

fn run<'life0, 'async_trait>( &'life0 self, task: AgentTask, ctx: RunContext, ) -> Pin<Box<dyn Future<Output = Result<AgentResult, BackendError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Run one agent task to completion.

Source

fn as_any(&self) -> &dyn Any

Upcast hook for downcasting &dyn AgentBackend back to a concrete backend type. Standard Rust trait-object downcast pattern: each impl returns self, which Any::downcast_ref then narrows to &Concrete. No default impl is provided — Self is unsized on a trait object, so a default body self would not compile.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§