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§
- Capability
Context - Shared execution context passed to all capability invocations.
- Capability
Name - Unique name for an
Invocablecapability. - Invocable
Request - A request to execute an
Invocablecapability. - Invocable
Result - The result of executing an
Invocablecapability. - Invocable
Spec - Describes an
Invocablecapability so it can be advertised to the model. - Prompt
Contents - The rendered output of a prompt template.
- Prompt
Descriptor - Describes a prompt template that a
PromptProvidercan render. - Prompt
Id - Unique identifier for a prompt template.
- Resource
Contents - The payload returned when a resource is read.
- Resource
Descriptor - Describes a resource that a
ResourceProvidercan serve. - Resource
Id - Unique identifier for a resource.
Enums§
- Capability
Error - Errors that can occur when interacting with capabilities.
- Invocable
Output - The output payload of an
Invocableexecution.
Traits§
- Capability
Provider - A bundle of capabilities from a single source.
- Invocable
- A capability that the model can invoke during a conversation turn.
- Prompt
Provider - A provider of parameterised prompt templates.
- Resource
Provider - A provider of named data resources that can be listed and read.