pub trait AgentCore: Send + Sync {
// Required methods
fn create_session(
&self,
id: SessionId,
cwd: PathBuf,
mcp_servers: Vec<McpServer>,
fs: Arc<dyn FsBackend>,
shell: Arc<dyn ShellBackend>,
frontend: Frontend,
) -> BoxFuture<'_, Result<Arc<dyn Session>, AgentError>>;
fn load_session(
&self,
id: SessionId,
fs: Arc<dyn FsBackend>,
shell: Arc<dyn ShellBackend>,
frontend: Frontend,
) -> BoxFuture<'_, Result<Arc<dyn Session>, AgentError>>;
fn session(&self, id: &SessionId) -> Option<Arc<dyn Session>>;
}Expand description
Process-level agent root object.
defect-cli constructs a concrete implementation at startup (holding the LLM provider
registry, built-in tool set, and configuration) and injects an Arc<dyn AgentCore>
into defect-acp::serve.
Rationale for extracting a trait:
- Allows injecting a mock in tests without spinning up a real LLM.
- If an “embedded agent” (library mode called by a host application) emerges in the future, a second concrete implementation can be added without touching the ACP bridge code.
Required Methods§
Sourcefn create_session(
&self,
id: SessionId,
cwd: PathBuf,
mcp_servers: Vec<McpServer>,
fs: Arc<dyn FsBackend>,
shell: Arc<dyn ShellBackend>,
frontend: Frontend,
) -> BoxFuture<'_, Result<Arc<dyn Session>, AgentError>>
fn create_session( &self, id: SessionId, cwd: PathBuf, mcp_servers: Vec<McpServer>, fs: Arc<dyn FsBackend>, shell: Arc<dyn ShellBackend>, frontend: Frontend, ) -> BoxFuture<'_, Result<Arc<dyn Session>, AgentError>>
Creates a new session.
id is generated and passed in by the caller (the defect-acp session/new
handler) — the filesystem backend already needs a SessionId when constructed
outside of AgentCore::create_session (see the ACP filesystem delegation
contract). Concrete implementations treat it as the authoritative external id and
return AgentError::DuplicateSessionId on duplicates.
mcp_servers is the per-session MCP server list from the session/new request;
the concrete implementation spawns subprocesses or establishes SSE connections
during initialization, wrapping each MCP tool as a Tool and adding it to the
session’s tool table.
fs is the session-level filesystem backend — defect-acp selects
LocalFsBackend or AcpFsBackend at assembly time based on the client’s
FileSystemCapabilities. The session holds an Arc to it, and all filesystem
tool calls go through it.
shell is the session-level shell backend — defect-acp selects
LocalShellBackend or AcpShellBackend at assembly time based on the client’s
ClientCapabilities::terminal. The session holds an Arc to it, and all bash
tool calls go through it.
frontend indicates how the agent is being accessed (Frontend::Acp carries
the fs/shell delegation state negotiated during the ACP handshake) and is used to
inject the # Environment section of the system prompt.
§Errors
MCP startup failure, missing cwd, duplicate id, etc.
Sourcefn load_session(
&self,
id: SessionId,
fs: Arc<dyn FsBackend>,
shell: Arc<dyn ShellBackend>,
frontend: Frontend,
) -> BoxFuture<'_, Result<Arc<dyn Session>, AgentError>>
fn load_session( &self, id: SessionId, fs: Arc<dyn FsBackend>, shell: Arc<dyn ShellBackend>, frontend: Frontend, ) -> BoxFuture<'_, Result<Arc<dyn Session>, AgentError>>
Restore an existing session from persistent state.
frontend works the same as in AgentCore::create_session — the restored
session also uses it to inject runtime environment information.
§Errors
The session does not exist, the persisted data is corrupted, the restored cwd is
unavailable, etc.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".