pub struct PromptRegistry { /* private fields */ }Expand description
A registry of named prompt templates for dynamic dispatch.
Mirrors ToolRegistry for prompts: it stores
type-erased RustPrompt implementations keyed by name, caches each
PromptDefinition at registration time, and renders them on demand,
keeping the type-erasure machinery a private implementation detail.
Implementations§
Source§impl PromptRegistry
impl PromptRegistry
Sourcepub fn register<P: RustPrompt + 'static>(&mut self, prompt: P) -> &mut Self
pub fn register<P: RustPrompt + 'static>(&mut self, prompt: P) -> &mut Self
Register a RustPrompt, replacing any existing prompt of the same name.
Returns &mut Self for chaining.
§Panics
Panics if the prompt’s JSON schema cannot be serialized. This indicates
a bug in the prompt’s Params type. Use
try_register for the non-panicking variant.
Sourcepub fn try_register<P: RustPrompt + 'static>(
&mut self,
prompt: P,
) -> Result<&mut Self, ToolError>
pub fn try_register<P: RustPrompt + 'static>( &mut self, prompt: P, ) -> Result<&mut Self, ToolError>
Register a RustPrompt, returning an error instead of panicking if
the prompt’s JSON schema cannot be built.
This is the fallible counterpart to register. If a
prompt with the same name was already registered, it is replaced.
§Errors
Returns ToolError if the prompt’s Params type fails to produce a
JSON schema.
Sourcepub fn with_prompt<P: RustPrompt + 'static>(self, prompt: P) -> Self
pub fn with_prompt<P: RustPrompt + 'static>(self, prompt: P) -> Self
Register a RustPrompt, consuming and returning Self for chaining.
§Panics
Panics if the prompt’s JSON schema cannot be serialized; see
register.
Sourcepub fn definitions(&self) -> Vec<PromptDefinition>
pub fn definitions(&self) -> Vec<PromptDefinition>
Collect PromptDefinitions for all registered prompts.
Returns clones of the cached definitions computed at registration time.
Sourcepub fn remove(&mut self, name: &str) -> bool
pub fn remove(&mut self, name: &str) -> bool
Remove a prompt by name, returning true if it was present.
Sourcepub fn definition(&self, name: &str) -> Option<&PromptDefinition>
pub fn definition(&self, name: &str) -> Option<&PromptDefinition>
Borrow the cached PromptDefinition for a registered prompt by name.
Returns None if no prompt named name is registered. Unlike
definitions, this clones nothing.
Sourcepub fn iter(&self) -> PromptDefinitions<'_> ⓘ
pub fn iter(&self) -> PromptDefinitions<'_> ⓘ
Iterate over (name, definition) pairs for every registered prompt.
Yields clones of the cached definitions computed at registration time.
Sourcepub async fn render(
&self,
name: &str,
args: Value,
) -> Result<PromptOutput, ToolError>
pub async fn render( &self, name: &str, args: Value, ) -> Result<PromptOutput, ToolError>
Render a registered prompt by name with raw JSON arguments.
§Errors
Returns ToolError::not_found if no prompt named name is registered
(carrying error_kind = "not_registered" metadata), or a render error
if argument deserialization or rendering fails.
Trait Implementations§
Source§impl Debug for PromptRegistry
impl Debug for PromptRegistry
Source§impl Default for PromptRegistry
impl Default for PromptRegistry
Source§fn default() -> PromptRegistry
fn default() -> PromptRegistry
Source§impl<'a> IntoIterator for &'a PromptRegistry
Iterate over (name, definition) pairs for every registered prompt.
impl<'a> IntoIterator for &'a PromptRegistry
Iterate over (name, definition) pairs for every registered prompt.