use rig_core::completion::{Document, GenerationOptions, ProviderOptions, ProviderToolDefinition};
use rig_core::message::ToolChoice;
use serde::{Deserialize, Serialize};
use super::output::OutputMode;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct RunSpec {
pub preamble: Option<String>,
pub static_context: Vec<Document>,
pub additional_params: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub provider_tools: Vec<ProviderToolDefinition>,
#[serde(skip_serializing_if = "GenerationOptions::is_default")]
pub options: GenerationOptions,
#[serde(skip_serializing_if = "ProviderOptions::is_empty")]
pub provider_options: ProviderOptions,
pub max_tokens: Option<u64>,
pub temperature: Option<f64>,
pub tool_choice: Option<ToolChoice>,
pub max_turns: Option<usize>,
pub max_invalid_tool_call_retries: usize,
pub max_consecutive_malformed_tool_calls: Option<usize>,
pub output_schema: Option<rig_core::schemars::Schema>,
pub output_mode: OutputMode,
pub output_tool_name: Option<String>,
pub output_tool_description: Option<String>,
pub augment_output_preamble: bool,
pub unhandled_invalid_tool_call: UnhandledInvalidToolCall,
pub accept_unknown_finish_reasons: bool,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum UnhandledInvalidToolCall {
#[default]
Fail,
Ignore,
}
impl RunSpec {
pub fn new() -> Self {
Self {
preamble: None,
static_context: Vec::new(),
additional_params: None,
provider_tools: Vec::new(),
options: GenerationOptions::default(),
provider_options: ProviderOptions::default(),
max_tokens: None,
temperature: None,
tool_choice: None,
max_turns: None,
max_invalid_tool_call_retries: 0,
max_consecutive_malformed_tool_calls: None,
output_schema: None,
output_mode: OutputMode::default(),
output_tool_name: None,
output_tool_description: None,
augment_output_preamble: true,
unhandled_invalid_tool_call: UnhandledInvalidToolCall::default(),
accept_unknown_finish_reasons: false,
}
}
pub fn effective_max_turns(&self) -> usize {
self.max_turns.unwrap_or(1)
}
}
impl Default for RunSpec {
fn default() -> Self {
Self::new()
}
}
impl RunSpec {
pub const DEFAULT_OUTPUT_RETRIES: usize = 1;
}
#[cfg(test)]
mod tests;