Skip to main content

rs_adk/
run_config.rs

1//! RunConfig — configuration for agent execution runs.
2
3use serde::{Deserialize, Serialize};
4
5/// How the agent communicates with clients.
6#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
7pub enum StreamingMode {
8    /// No streaming — single request/response.
9    None,
10    /// Server-sent events (unidirectional streaming).
11    SSE,
12    /// Bidirectional streaming (e.g., WebSocket).
13    #[default]
14    Bidi,
15}
16
17/// Configuration for an agent execution run.
18#[derive(Debug, Clone)]
19pub struct RunConfig {
20    /// Maximum number of LLM calls per run (safety limit).
21    pub max_llm_calls: u32,
22    /// How the agent streams responses.
23    pub streaming_mode: StreamingMode,
24    /// Whether to save input blobs (images, audio) as artifacts.
25    pub save_input_blobs_as_artifacts: bool,
26    /// Whether to support compositional function calling.
27    pub support_cfc: bool,
28    /// Whether to pause execution on tool calls (for confirmation UX).
29    pub pause_on_tool_calls: bool,
30    /// If set, the agent's final text response is automatically saved to this state key.
31    pub output_key: Option<String>,
32    /// JSON Schema for structured output. When set, the LLM is instructed
33    /// to produce JSON output conforming to this schema.
34    pub output_schema: Option<serde_json::Value>,
35}
36
37impl Default for RunConfig {
38    fn default() -> Self {
39        Self {
40            max_llm_calls: 500,
41            streaming_mode: StreamingMode::default(),
42            save_input_blobs_as_artifacts: false,
43            support_cfc: false,
44            pause_on_tool_calls: false,
45            output_key: None,
46            output_schema: None,
47        }
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn default_values() {
57        let config = RunConfig::default();
58        assert_eq!(config.max_llm_calls, 500);
59        assert_eq!(config.streaming_mode, StreamingMode::Bidi);
60        assert!(!config.save_input_blobs_as_artifacts);
61        assert!(!config.support_cfc);
62        assert!(!config.pause_on_tool_calls);
63    }
64
65    #[test]
66    fn streaming_mode_default_is_bidi() {
67        assert_eq!(StreamingMode::default(), StreamingMode::Bidi);
68    }
69
70    #[test]
71    fn clone_run_config() {
72        let config = RunConfig {
73            max_llm_calls: 100,
74            streaming_mode: StreamingMode::SSE,
75            save_input_blobs_as_artifacts: true,
76            support_cfc: true,
77            pause_on_tool_calls: true,
78            output_key: Some("result".to_string()),
79            output_schema: Some(serde_json::json!({"type": "object"})),
80        };
81        let cloned = config.clone();
82        assert_eq!(cloned.max_llm_calls, 100);
83        assert_eq!(cloned.streaming_mode, StreamingMode::SSE);
84        assert!(cloned.save_input_blobs_as_artifacts);
85    }
86
87    #[test]
88    fn streaming_mode_serde_roundtrip() {
89        let mode = StreamingMode::SSE;
90        let json = serde_json::to_string(&mode).unwrap();
91        let parsed: StreamingMode = serde_json::from_str(&json).unwrap();
92        assert_eq!(parsed, StreamingMode::SSE);
93    }
94}