Skip to main content

Invocable

Trait Invocable 

Source
pub trait Invocable: Send + Sync {
    // Required methods
    fn spec(&self) -> &InvocableSpec;
    fn invoke<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: InvocableRequest,
        ctx: &'life1 mut CapabilityContext<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<InvocableResult, CapabilityError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

A capability that the model can invoke during a conversation turn.

Implement this trait to expose custom functionality – database queries, API calls, file operations, code execution – to the agentic loop. Each implementor provides a spec describing the capability and an async invoke method that performs the work.

The agentkit loop discovers invocables through a CapabilityProvider and presents them to the model alongside regular tools.

§Example

use agentkit_capabilities::{
    CapabilityContext, CapabilityError, CapabilityName, Invocable,
    InvocableOutput, InvocableRequest, InvocableResult, InvocableSpec,
};
use async_trait::async_trait;
use serde_json::json;

struct CurrentTime {
    spec: InvocableSpec,
}

impl CurrentTime {
    fn new() -> Self {
        Self {
            spec: InvocableSpec::new(
                CapabilityName::new("current_time"),
                "Return the current UTC time",
                json!({ "type": "object" }),
            ),
        }
    }
}

#[async_trait]
impl Invocable for CurrentTime {
    fn spec(&self) -> &InvocableSpec {
        &self.spec
    }

    async fn invoke(
        &self,
        _request: InvocableRequest,
        _ctx: &mut CapabilityContext<'_>,
    ) -> Result<InvocableResult, CapabilityError> {
        Ok(InvocableResult::text("2026-03-22T12:00:00Z"))
    }
}

Required Methods§

Source

fn spec(&self) -> &InvocableSpec

Returns the specification that describes this capability to the model.

Source

fn invoke<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: InvocableRequest, ctx: &'life1 mut CapabilityContext<'life2>, ) -> Pin<Box<dyn Future<Output = Result<InvocableResult, CapabilityError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Executes the capability with the given request and context.

§Arguments
  • request - The invocation request containing the model-provided input and session identifiers.
  • ctx - The shared capability context for this turn.
§Errors

Returns CapabilityError if the capability is unavailable, the input is invalid, or execution fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§