feat(ai): make agent turn limit configurable
This commit is contained in:
1 parent
21e9578f78
commit
9253203d99
21 files changed
+307
-5
No files matched your search
@@ -603,6 +603,10 @@ async fn main() {
|
||||
"/app-settings/mcp-policy",
|
||||
get(routes::app_settings::load_mcp_global_policy).put(routes::app_settings::save_mcp_global_policy),
|
||||
)
|
||||
.route(
|
||||
"/app-settings/max-agent-turns",
|
||||
get(routes::app_settings::load_max_agent_turns).put(routes::app_settings::save_max_agent_turns),
|
||||
)
|
||||
.route("/app-settings/config/decrypt", post(routes::app_settings::decrypt_config))
|
||||
// Cloud sync
|
||||
.route("/cloud-sync/webdav/test", post(routes::cloud_sync::webdav_sync_test))
|
||||
|
||||
@@ -332,6 +332,10 @@ pub async fn ai_agent_stream(
|
||||
.get(&body.connection_id)
|
||||
.is_some_and(|config| dbx_core::production_safety::is_production_database(config, &body.database));
|
||||
|
||||
let max_agent_turns = state.app.storage.load_max_agent_turns().await.unwrap_or_else(|err| {
|
||||
log::warn!("Failed to load max_agent_turns setting, using default: {err}");
|
||||
dbx_core::agent_loop::DEFAULT_MAX_AGENT_TURNS
|
||||
});
|
||||
let agent_ctx = AgentLoopContext {
|
||||
state: state.app.clone(),
|
||||
connection_id: body.connection_id,
|
||||
@@ -342,6 +346,7 @@ pub async fn ai_agent_stream(
|
||||
allow_writes: !production_database && body.allow_write_sql,
|
||||
allow_dangerous: !production_database && body.allow_write_sql,
|
||||
},
|
||||
max_agent_turns,
|
||||
};
|
||||
|
||||
let sid = session_id.clone();
|
||||
|
||||
@@ -65,6 +65,24 @@ pub async fn save_mcp_global_policy(
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SaveMaxAgentTurnsRequest {
|
||||
pub max_agent_turns: u32,
|
||||
}
|
||||
|
||||
pub async fn load_max_agent_turns(State(state): State<Arc<WebState>>) -> Result<Json<u32>, AppError> {
|
||||
state.app.storage.load_max_agent_turns().await.map(Json).map_err(AppError::from)
|
||||
}
|
||||
|
||||
pub async fn save_max_agent_turns(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(body): Json<SaveMaxAgentTurnsRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
state.app.storage.save_max_agent_turns(body.max_agent_turns).await.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn decrypt_config(Json(body): Json<DecryptConfigRequest>) -> Result<Json<String>, AppError> {
|
||||
decrypt_config_payload(&body.payload, &body.passphrase).map(Json).map_err(AppError::from)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user