Skip to main content

Crate agentkit_capabilities

Crate agentkit_capabilities 

Source
Expand description

Capability abstractions shared by tools, MCP servers, and agentkit hosts.

This crate defines the Invocable trait and its supporting types, which let you expose arbitrary functionality (tools, resources, prompts) through a uniform interface that the agentkit loop can discover and call during a session.

§Overview

The core abstraction is Invocable: anything the model can call. Each invocable carries an InvocableSpec (name, description, JSON-schema for its input) and an async invoke method that receives an InvocableRequest and returns an InvocableResult.

Beyond direct invocation the crate also provides:

  • ResourceProvider – lists and reads named data blobs (files, database rows, API responses) that the model can reference.
  • PromptProvider – lists and renders parameterised prompt templates.
  • CapabilityProvider – a bundle that groups invocables, resources, and prompts from a single source (e.g. an MCP server).

All provider traits share a common CapabilityContext that carries the current session and turn identifiers, plus an open-ended metadata map.

§Example

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

/// A simple capability that echoes its input back to the model.
struct Echo {
    spec: InvocableSpec,
}

impl Echo {
    fn new() -> Self {
        Self {
            spec: InvocableSpec::new(
                CapabilityName::new("echo"),
                "Return the input unchanged",
                json!({
                    "type": "object",
                    "properties": {
                        "message": { "type": "string" }
                    }
                }),
            ),
        }
    }
}

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

    async fn invoke(
        &self,
        request: InvocableRequest,
        _ctx: &mut CapabilityContext<'_>,
    ) -> Result<InvocableResult, CapabilityError> {
        Ok(InvocableResult::structured(request.input.clone()))
    }
}

let echo = Echo::new();
assert_eq!(echo.spec().name.as_str(), "echo");

Structs§

CapabilityContext
Shared execution context passed to all capability invocations.
CapabilityName
Unique name for an Invocable capability.
InvocableRequest
A request to execute an Invocable capability.
InvocableResult
The result of executing an Invocable capability.
InvocableSpec
Describes an Invocable capability so it can be advertised to the model.
PromptContents
The rendered output of a prompt template.
PromptDescriptor
Describes a prompt template that a PromptProvider can render.
PromptId
Unique identifier for a prompt template.
ResourceContents
The payload returned when a resource is read.
ResourceDescriptor
Describes a resource that a ResourceProvider can serve.
ResourceId
Unique identifier for a resource.

Enums§

CapabilityError
Errors that can occur when interacting with capabilities.
InvocableOutput
The output payload of an Invocable execution.

Traits§

CapabilityProvider
A bundle of capabilities from a single source.
Invocable
A capability that the model can invoke during a conversation turn.
PromptProvider
A provider of parameterised prompt templates.
ResourceProvider
A provider of named data resources that can be listed and read.