Skip to main content

Agent

Trait Agent 

Source
pub trait Agent<C>: Send + Sync
where C: AgentContext + Send + Sync,
{ // Required methods fn name(&self) -> String; fn description(&self) -> String; fn run( &self, ctx: C, prompt: String, resources: Vec<Resource>, ) -> impl Future<Output = Result<AgentOutput, BoxError>> + Send; // Provided methods fn definition(&self) -> FunctionDefinition { ... } fn supported_resource_tags(&self) -> Vec<String> { ... } fn select_resources(&self, resources: &mut Vec<Resource>) -> Vec<Resource> { ... } fn init(&self, _ctx: C) -> impl Future<Output = Result<(), BoxError>> + Send { ... } fn tool_dependencies(&self) -> Vec<String> { ... } }
Expand description

Strongly typed interface for an AI agent.

§Type Parameters

Required Methods§

Source

fn name(&self) -> String

Returns the unique agent name.

Names are registered case-insensitively and stored in lowercase.

§Rules
  • Must not be empty;
  • Must not exceed 64 characters;
  • Must start with a lowercase letter;
  • Can only contain: lowercase letters (a-z), digits (0-9), and underscores (_);
  • Unique within the engine in lowercase.
Source

fn description(&self) -> String

Returns a concise description of the agent’s capability.

Source

fn run( &self, ctx: C, prompt: String, resources: Vec<Resource>, ) -> impl Future<Output = Result<AgentOutput, BoxError>> + Send

Executes the agent with the given context and inputs.

§Arguments
  • ctx: The execution context implementing AgentContext.
  • prompt: The input prompt or message for the agent.
  • resources: Additional resources selected for this agent. Ignore resources that are not useful.
§Returns

A future resolving to AgentOutput.

Provided Methods§

Source

fn definition(&self) -> FunctionDefinition

Returns the function definition used for LLM/tool-call integration.

§Returns
  • FunctionDefinition: The structured definition of the agent’s capabilities.
Source

fn supported_resource_tags(&self) -> Vec<String>

Returns resource tags this agent can consume.

The default implementation returns an empty list, meaning no resources are selected for this agent. Return vec!["*".into()] to accept all attached resources.

§Returns

Resource tags supported by this agent.

Source

fn select_resources(&self, resources: &mut Vec<Resource>) -> Vec<Resource>

Removes and returns resources matching this agent’s supported tags.

Source

fn init(&self, _ctx: C) -> impl Future<Output = Result<(), BoxError>> + Send

Initializes the agent with the given context.

Runtimes call this once while building the engine.

Source

fn tool_dependencies(&self) -> Vec<String>

Returns tool names required by this agent.

Runtimes use this list to validate that required tools are registered.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§