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.canceland return promptly withBackendError::Cancelledwhen 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 inArc<dyn AgentBackend>and shared across tasks. - Downcasting: implement
as_any()by returningselfto allow callers to downcast to the concrete backend type.
See the module docs for a complete implementation example.
Required Methods§
Sourcefn capabilities(&self) -> AgentCapabilities
fn capabilities(&self) -> AgentCapabilities
Capability declaration (v0.1: recorded/validated only; routing in v0.2).
Sourcefn 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 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.
Sourcefn as_any(&self) -> &dyn Any
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".