pub trait AgentInvoker: Send + Sync {
// Required method
fn invoke(
&self,
input: AgentInput<'_>,
) -> Result<AgentOutput, AgentInvokeError>;
}Expand description
Trait for invoking AI coding agents.
This trait abstracts the execution of an AI coding agent, enabling dependency injection and mock testing. Boundary adapters for different agents (claude, codex, opencode, gemini, etc.) implement this trait.
§Object Safety
This trait is designed to be object-safe via dyn AgentInvoker. Implementors
must not require any type parameters or use generic methods.
§Example
ⓘ
struct AgentRunner {
invoker: Arc<dyn AgentInvoker>,
}
impl AgentRunner {
fn run_agent(&self, prompt: &str, config: &AgentConfig) -> Result<AgentOutput, AgentInvokeError> {
let input = AgentInput {
prompt,
agent_config: config,
logfile: None,
};
self.invoker.invoke(input)
}
}Required Methods§
Sourcefn invoke(&self, input: AgentInput<'_>) -> Result<AgentOutput, AgentInvokeError>
fn invoke(&self, input: AgentInput<'_>) -> Result<AgentOutput, AgentInvokeError>
Invoke the agent with the given input.
§Arguments
input- The invocation input containing prompt and agent configuration
§Returns
Returns AgentOutput on success, or AgentInvokeError on failure.