pub struct PersonaManager { /* private fields */ }Expand description
Registry and runtime controller for AI personas.
§Example
use tokio_prompt_orchestrator::persona_manager::{PersonaManager, default_personas};
let mut mgr = PersonaManager::default();
for p in default_personas() { mgr.register(p); }
assert!(mgr.activate("assistant"));
let persona = mgr.active_persona().unwrap();
let prompt = mgr.apply_persona("What is Rust?", persona);
assert!(prompt.contains("What is Rust?"));Implementations§
Source§impl PersonaManager
impl PersonaManager
Sourcepub fn register(&mut self, persona: Persona)
pub fn register(&mut self, persona: Persona)
Register a new persona. If a persona with the same id already exists it is replaced.
Sourcepub fn activate(&mut self, id: &str) -> bool
pub fn activate(&mut self, id: &str) -> bool
Activate the persona with the given id.
Returns true if the persona was found and activated, false otherwise.
Sourcepub fn active_persona(&self) -> Option<&Persona>
pub fn active_persona(&self) -> Option<&Persona>
Return a reference to the currently active persona, if any.
Sourcepub fn apply_persona(&self, prompt: &str, persona: &Persona) -> String
pub fn apply_persona(&self, prompt: &str, persona: &Persona) -> String
Build the final prompt string by prepending the system context and appending required disclaimers.
Format:
[SYSTEM]: <system_prompt>
[STYLE]: <style_notes>
<prompt>
<disclaimer_1>
<disclaimer_2>Sourcepub fn validate_response(
&self,
response: &str,
persona: &Persona,
) -> Vec<String>
pub fn validate_response( &self, response: &str, persona: &Persona, ) -> Vec<String>
Validate a model response against persona constraints.
Returns a list of human-readable violation messages (empty = valid).
Sourcepub fn blend_personas(
&self,
a_id: &str,
b_id: &str,
alpha: f64,
) -> Option<Persona>
pub fn blend_personas( &self, a_id: &str, b_id: &str, alpha: f64, ) -> Option<Persona>
Create a blended persona by interpolating the numeric constraints of
persona a_id (weight alpha) and persona b_id (weight 1 - alpha).
The resulting persona’s system prompt is the concatenation of both
system prompts separated by a newline. The voice of persona a is used.
Returns None if either id is not found or alpha is outside [0, 1].
Sourcepub fn list_by_voice(&self, voice: &PersonaVoice) -> Vec<&Persona>
pub fn list_by_voice(&self, voice: &PersonaVoice) -> Vec<&Persona>
Return all personas that match the given voice.
Trait Implementations§
Source§impl Debug for PersonaManager
impl Debug for PersonaManager
Source§impl Default for PersonaManager
impl Default for PersonaManager
Source§fn default() -> PersonaManager
fn default() -> PersonaManager
Auto Trait Implementations§
impl Freeze for PersonaManager
impl RefUnwindSafe for PersonaManager
impl Send for PersonaManager
impl Sync for PersonaManager
impl Unpin for PersonaManager
impl UnsafeUnpin for PersonaManager
impl UnwindSafe for PersonaManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request