Skip to main content

rig_agent/run/
output.rs

1//! Structured-output enforcement modes for agent requests.
2//!
3//! ```
4//! use rig_agent::run::output::OutputMode;
5//! let mode = OutputMode::default();
6//! assert_eq!(mode, OutputMode::Auto);
7//! ```
8
9use serde::{Deserialize, Serialize};
10
11/// Select how requests convey an agent's output schema.
12/// Native enforcement depends on provider support. Tool and prompted modes are
13/// best-effort; callers must validate returned values before relying on the schema.
14#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
15pub enum OutputMode {
16    /// Resolve to tool output when a schema and function tools are present,
17    /// tool choice permits it, and native output cannot compose with tools.
18    /// Otherwise use native output.
19    #[default]
20    Auto,
21    /// Offer the schema as a synthetic final-answer tool instead of a native
22    /// constraint. Calling it is best-effort; callers must validate the result.
23    Tool,
24    /// Send a native structured-output constraint on every turn.
25    /// Enforcement and compatibility with tool calls depend on provider capabilities.
26    Native,
27    /// Put the schema in the system prompt and return final text verbatim.
28    /// Callers must extract and validate JSON; prose and markdown may be present.
29    Prompted,
30}