pub trait Agent: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn description(&self) -> &str;
fn tools(&self) -> Vec<String>;
fn resolve<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<AgentPrompt>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn source(&self) -> &str { ... }
fn arguments(&self) -> Vec<AgentArgument> { ... }
}Expand description
An agent persona that provides a system prompt and tool scoping.
Implement this trait to create a custom agent in Rust. Agents are
registered in an AgentRegistry and exposed via GET /agents/list
for discovery and POST /agents/{name}/prompt for resolution.
§Lifecycle
- The agent is registered via
AgentRegistry::register. - At discovery time,
name,description,tools, andargumentsare called. - When a user selects the agent,
resolveis called with any provided arguments and aToolContextfor KB access.
§Example
use async_trait::async_trait;
use anyhow::Result;
use serde_json::{json, Value};
use context_harness::agents::{Agent, AgentPrompt, AgentArgument};
use context_harness::traits::ToolContext;
pub struct ArchitectAgent;
#[async_trait]
impl Agent for ArchitectAgent {
fn name(&self) -> &str { "architect" }
fn description(&self) -> &str { "Answers architecture questions" }
fn tools(&self) -> Vec<String> { vec!["search".into(), "get".into()] }
async fn resolve(&self, _args: Value, _ctx: &ToolContext) -> Result<AgentPrompt> {
Ok(AgentPrompt {
system: "You are a software architect.".to_string(),
tools: self.tools(),
messages: vec![],
})
}
}Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Returns a one-line description for agent discovery.
Sourcefn resolve<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<AgentPrompt>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn resolve<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<AgentPrompt>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Resolve the agent’s prompt, optionally using the ToolContext
for dynamic context injection (e.g., pre-searching the KB).
§Arguments
args— User-provided argument values (JSON object).ctx— Bridge to the Context Harness knowledge base.
§Returns
An AgentPrompt containing the system prompt, tool list,
and optional pre-injected messages.
Provided Methods§
Sourcefn arguments(&self) -> Vec<AgentArgument>
fn arguments(&self) -> Vec<AgentArgument>
Returns the arguments this agent accepts (may be empty).
Arguments are shown to the user in MCP prompt selection UIs
and passed to resolve as a JSON object.