pub struct LlmTransition { /* private fields */ }Expand description
Wraps an LLM API call as a Ranvier Transition.
§Builder API
LlmTransition::new(LlmProvider::Claude)
.model("claude-sonnet-4-5-20250929")
.system_prompt("You are a helpful assistant.")
.prompt_template("Classify: {{content}}")
.output_schema::<ModerationResult>()
.max_tokens(200)
.temperature(0.3)
.retry_count(2)
.with_label("ContentModeration")§Template Syntax
{{variable}}— substituted with theStringvalue ofvariablefrom the Bus (viabus.read::<LlmTemplateVars>()).{{json:variable}}— substituted with the JSON-serialized representation ofvariablefrom the Bus template vars.
§Transition Contract
- Input (
String): an optional runtime prompt override; when empty the storedprompt_templateis used. - Output (
String): the raw LLM response text. - Error (
LlmError): typed fault for template, network, or validation failures.
Implementations§
Source§impl LlmTransition
impl LlmTransition
Sourcepub fn new(provider: LlmProvider) -> Self
pub fn new(provider: LlmProvider) -> Self
Create a new LlmTransition targeting provider.
Sourcepub fn model(self, model: impl Into<String>) -> Self
pub fn model(self, model: impl Into<String>) -> Self
Set the model identifier (e.g. "claude-sonnet-4-5-20250929", "gpt-4o").
Sourcepub fn system_prompt(self, system: impl Into<String>) -> Self
pub fn system_prompt(self, system: impl Into<String>) -> Self
Set an optional system prompt prepended to the conversation.
Sourcepub fn prompt_template(self, template: impl Into<String>) -> Self
pub fn prompt_template(self, template: impl Into<String>) -> Self
Set the prompt template.
Template variables use {{variable}} for string substitution and
{{json:variable}} for JSON-serialized substitution from the Bus.
Sourcepub fn max_tokens(self, max: u32) -> Self
pub fn max_tokens(self, max: u32) -> Self
Set the maximum number of tokens to generate.
Sourcepub fn temperature(self, temp: f32) -> Self
pub fn temperature(self, temp: f32) -> Self
Set the sampling temperature (0.0 = deterministic, 1.0+ = creative).
Sourcepub fn retry_count(self, count: u32) -> Self
pub fn retry_count(self, count: u32) -> Self
Set the number of automatic retries on transient failure (default 0).
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Override the transition label shown in the Schematic.
Sourcepub fn output_schema<T: Serialize + for<'de> Deserialize<'de> + Default>(
self,
) -> Self
pub fn output_schema<T: Serialize + for<'de> Deserialize<'de> + Default>( self, ) -> Self
Store a JSON Schema derived from T for response validation.
When set, the LLM response will be parsed as JSON and validated against
this schema. If validation fails the transition returns
Outcome::Fault with LlmError::SchemaValidation.
The schema is generated from the serde_json representation of T.
For richer schema generation, enable the schema feature and use
schemars.
Sourcepub fn output_schema_raw(self, schema: Value) -> Self
pub fn output_schema_raw(self, schema: Value) -> Self
Set a raw JSON Schema value directly for response validation.
Trait Implementations§
Source§impl Clone for LlmTransition
impl Clone for LlmTransition
Source§fn clone(&self) -> LlmTransition
fn clone(&self) -> LlmTransition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more