Skip to main content

Module backend

Module backend 

Source
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(),
            session_id: None,
        })
    }

    fn as_any(&self) -> &dyn std::any::Any { self }
}

Structs§

AgentCapabilities
AgentResult
AgentTask
Artifact
ClientIdentity
Luft’s own identity as sent in the client_info field of the ACP InitializeRequest. Stored so downstream code can log or surface which Luft version initiated the session.
CurrentBackend
Identity of the backend currently connected to this process, captured at the ACP initialize handshake.
LogRef
McpEndpoint
MCP data-plane endpoint injected into an agent for structured reporting.
RunContext
Per-agent runtime context: cancellation + event sink + run association.
ToolPolicy
Tool permission policy. v0.1 translates to a backend’s acceptEdits + command allowlist.

Enums§

AgentStatus
BackendError

Traits§

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

Functions§

clear_current_backend
Clear the recorded current backend identity. Primarily for tests, so a current_backend-dependent assertion does not leak into the next test.
current_backend
Read the current backend identity, if a handshake has completed yet.
set_current_backend
Record the backend identity captured during a handshake. Called by the ACP adapter after initialize. Overwrites any prior value.