agent_base/types/
config.rs1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
5pub enum Language {
6 En,
7 Zh,
8}
9
10impl Default for Language {
11 fn default() -> Self {
12 Language::En
13 }
14}
15
16impl std::fmt::Display for Language {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 Language::En => write!(f, "en"),
20 Language::Zh => write!(f, "zh"),
21 }
22 }
23}
24
25#[derive(Clone, Debug)]
26pub struct RetryConfig {
27 pub max_retries: u32,
28 pub initial_backoff_ms: u64,
29 pub max_backoff_ms: u64,
30 pub backoff_multiplier: f64,
31 pub jitter: bool,
32}
33
34impl Default for RetryConfig {
35 fn default() -> Self {
36 Self {
37 max_retries: 3,
38 initial_backoff_ms: 500,
39 max_backoff_ms: 10_000,
40 backoff_multiplier: 2.0,
41 jitter: true,
42 }
43 }
44}
45
46impl RetryConfig {
47 pub fn new() -> Self {
48 Self::default()
49 }
50
51 pub fn max_retries(mut self, n: u32) -> Self {
52 self.max_retries = n;
53 self
54 }
55
56 pub fn initial_backoff_ms(mut self, ms: u64) -> Self {
57 self.initial_backoff_ms = ms;
58 self
59 }
60
61 pub fn max_backoff_ms(mut self, ms: u64) -> Self {
62 self.max_backoff_ms = ms;
63 self
64 }
65
66 pub fn no_jitter(mut self) -> Self {
67 self.jitter = false;
68 self
69 }
70}
71
72#[derive(Clone, Debug)]
73pub enum ResponseFormat {
74 JsonObject,
75 JsonSchema {
76 name: String,
77 schema: Value,
78 },
79}
80
81impl ResponseFormat {
82 pub fn to_api_value(&self) -> Value {
83 match self {
84 ResponseFormat::JsonObject => {
85 serde_json::json!({ "type": "json_object" })
86 }
87 ResponseFormat::JsonSchema { name, schema } => {
88 serde_json::json!({
89 "type": "json_schema",
90 "json_schema": {
91 "name": name,
92 "schema": schema,
93 }
94 })
95 }
96 }
97 }
98}
99
100use crate::llm::ReasoningConfig;
101
102#[derive(Clone, Debug)]
103pub struct AgentConfig {
104 pub system_prompt: Option<String>,
105 pub enable_thought: bool,
106 pub reasoning: Option<ReasoningConfig>,
107 pub language: Language,
108 pub execution: ExecutionConfig,
109 pub llm: LlmConfig,
110 pub tool: ToolConfig,
111}
112
113impl Default for AgentConfig {
114 fn default() -> Self {
115 Self {
116 system_prompt: None,
117 enable_thought: false,
118 reasoning: None,
119 language: Language::default(),
120 execution: ExecutionConfig::default(),
121 llm: LlmConfig::default(),
122 tool: ToolConfig::default(),
123 }
124 }
125}
126
127#[derive(Clone, Debug)]
128pub struct ExecutionConfig {
129 pub max_turns: Option<u32>,
130 pub approval_timeout_ms: Option<u64>,
131 pub fail_on_persist_error: bool,
132}
133
134impl Default for ExecutionConfig {
135 fn default() -> Self {
136 Self {
137 max_turns: None,
138 approval_timeout_ms: None,
139 fail_on_persist_error: false,
140 }
141 }
142}
143
144#[derive(Clone, Debug)]
145pub struct LlmConfig {
146 pub response_format: Option<ResponseFormat>,
147 pub llm_retry: Option<RetryConfig>,
148}
149
150impl Default for LlmConfig {
151 fn default() -> Self {
152 Self {
153 response_format: None,
154 llm_retry: None,
155 }
156 }
157}
158
159#[derive(Clone, Debug)]
160pub struct ToolConfig {
161 pub tool_timeout_ms: Option<u64>,
162 pub max_tool_output_chars: Option<usize>,
163 pub tool_error_retry_prompt: Option<String>,
164}
165
166impl Default for ToolConfig {
167 fn default() -> Self {
168 Self {
169 tool_timeout_ms: None,
170 max_tool_output_chars: None,
171 tool_error_retry_prompt: None,
172 }
173 }
174}