pub trait Profile: 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<ProfilePrompt>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn source(&self) -> &str { ... }
fn arguments(&self) -> Vec<ProfileArgument> { ... }
}Expand description
A reusable persona that provides a system prompt and tool scoping.
Implement this trait to create a custom profile in Rust. Profiles are
registered in a ProfileRegistry and exposed via GET /profiles/list
for discovery and POST /profiles/{name}/prompt for resolution.
§Lifecycle
- The profile is registered via
ProfileRegistry::register. - At discovery time,
name,description,tools, andargumentsare called. - When a user selects the profile,
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::profiles::{Profile, ProfilePrompt, ProfileArgument};
use context_harness::traits::ToolContext;
pub struct ArchitectProfile;
#[async_trait]
impl Profile for ArchitectProfile {
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<ProfilePrompt> {
Ok(ProfilePrompt {
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 profile discovery.
Sourcefn resolve<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<ProfilePrompt>> + 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<ProfilePrompt>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Resolve the profile’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
A ProfilePrompt containing the system prompt, tool list,
and optional pre-injected messages.
Provided Methods§
Sourcefn arguments(&self) -> Vec<ProfileArgument>
fn arguments(&self) -> Vec<ProfileArgument>
Returns the arguments this profile accepts (may be empty).
Arguments are shown to the user in MCP prompt selection UIs
and passed to resolve as a JSON object.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".