Agent

Trait Agent 

Source
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

  1. The agent is registered via AgentRegistry::register.
  2. At discovery time, name, description, tools, and arguments are called.
  3. When a user selects the agent, resolve is called with any provided arguments and a ToolContext for 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§

Source

fn name(&self) -> &str

Returns the agent’s unique name (URL-safe, e.g. "code-reviewer").

Source

fn description(&self) -> &str

Returns a one-line description for agent discovery.

Source

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

Returns the list of tool names this agent exposes.

Source

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§

Source

fn source(&self) -> &str

Returns the agent’s source type: "toml", "lua", or "rust".

Source

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.

Implementors§