pub trait ToolExecutorPort: Send + Sync {
// Required methods
fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<ToolDefinition>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
call: &'life1 ToolCall,
) -> Pin<Box<dyn Future<Output = Result<ToolResult, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Port: dispatches tool calls to the underlying execution backend.
§Implementing this trait
ⓘ
use gglib_core::ports::{AgentError, ToolExecutorPort};
use gglib_core::domain::{ToolCall, ToolDefinition, ToolResult};
struct McpToolExecutor { /* ... */ }
#[async_trait::async_trait]
impl ToolExecutorPort for McpToolExecutor {
async fn list_tools(&self) -> Vec<ToolDefinition> { /* ... */ }
async fn execute(&self, call: &ToolCall) -> Result<ToolResult, anyhow::Error> {
// Call the MCP client; convert McpToolResult → ToolResult.
// Return Err(_) only if the infrastructure itself is unavailable.
}
}§Error contract
- Returns
Ok(ToolResult { success: false, .. })when the tool ran but produced an application-level error (wrong args, resource not found, etc.). The loop implementation must feed this back to the LLM as context. - Returns
Err(anyhow::Error)only when the executor infrastructure is unavailable (e.g. MCP process died, network unreachable). The loop implementation converts this intoToolResult { success: false, content: "executor unavailable: …" }so the LLM still receives context.
Required Methods§
Sourcefn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<ToolDefinition>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<ToolDefinition>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Return all tool definitions available in this executor.
Called once per agent run invocation to build the tool list sent to
the LLM.
Sourcefn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
call: &'life1 ToolCall,
) -> Pin<Box<dyn Future<Output = Result<ToolResult, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
call: &'life1 ToolCall,
) -> Pin<Box<dyn Future<Output = Result<ToolResult, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute a single tool call.
Returns Err only for infrastructure failures (see error contract above).