Expand description
§AgentBackend Contract
The AgentBackend trait is the control-plane boundary between Luft’s
orchestration runtime and the agent execution environment. Prompt goes in,
structured AgentResult comes out.
§Implementing a Backend
use luft_core::contract::backend::*;
use async_trait::async_trait;
struct MyBackend;
impl MyBackend {
fn new() -> Self { Self }
}
#[async_trait]
impl AgentBackend for MyBackend {
fn id(&self) -> &'static str { "my-backend" }
fn capabilities(&self) -> AgentCapabilities {
AgentCapabilities {
streaming: true,
..Default::default()
}
}
async fn run(&self, task: AgentTask, ctx: RunContext)
-> Result<AgentResult, BackendError>
{
// 1. Observe cancellation
if ctx.cancel.is_cancelled() {
return Err(BackendError::Cancelled);
}
// 2. Execute the agent task (your custom logic)
let output = serde_json::json!({ "text": "hello" });
// 3. Return structured result
Ok(AgentResult {
agent_id: task.agent_id,
status: AgentStatus::Ok,
output,
findings: vec![],
tokens_used: Default::default(),
artifacts: vec![],
logs: LogRef::default(),
thread_id: None,
})
}
fn as_any(&self) -> &dyn std::any::Any { self }
}Structs§
- Agent
Capabilities - Agent
Result - Agent
Task - Artifact
- LogRef
- McpEndpoint
- MCP data-plane endpoint injected into an agent for structured reporting.
- RunContext
- Per-agent runtime context: cancellation + event sink + run association.
- Tool
Policy - Tool permission policy. v0.1 translates to a backend’s acceptEdits + command allowlist.
Enums§
Traits§
- Agent
Backend - A pluggable agent backend (e.g. OpenCode via ACP). Prompt in, structured result out.