Add /agent/stop endpoint, make max active agents configurable (#5826)

This commit is contained in:
tlongwell-block
2025-11-21 09:24:19 -05:00
committed by GitHub
parent 0f8d9a7878
commit 7b787f926b
3 changed files with 40 additions and 1 deletions
+34
View File
@@ -67,6 +67,11 @@ pub struct StartAgentRequest {
recipe_deeplink: Option<String>,
}
#[derive(Deserialize, utoipa::ToSchema)]
pub struct StopAgentRequest {
session_id: String,
}
#[derive(Deserialize, utoipa::ToSchema)]
pub struct ResumeAgentRequest {
session_id: String,
@@ -599,6 +604,34 @@ async fn agent_remove_extension(
Ok(StatusCode::OK)
}
#[utoipa::path(
post,
path = "/agent/stop",
request_body = StopAgentRequest,
responses(
(status = 200, description = "Agent stopped successfully", body = String),
(status = 401, description = "Unauthorized - invalid secret key"),
(status = 404, description = "Session not found"),
(status = 500, description = "Internal server error")
)
)]
async fn stop_agent(
State(state): State<Arc<AppState>>,
Json(payload): Json<StopAgentRequest>,
) -> Result<StatusCode, ErrorResponse> {
let session_id = payload.session_id;
state
.agent_manager
.remove_session(&session_id)
.await
.map_err(|e| ErrorResponse {
message: format!("Failed to stop agent for session {}: {}", session_id, e),
status: StatusCode::NOT_FOUND,
})?;
Ok(StatusCode::OK)
}
pub fn routes(state: Arc<AppState>) -> Router {
Router::new()
.route("/agent/start", post(start_agent))
@@ -612,5 +645,6 @@ pub fn routes(state: Arc<AppState>) -> Router {
.route("/agent/update_from_session", post(update_from_session))
.route("/agent/add_extension", post(agent_add_extension))
.route("/agent/remove_extension", post(agent_remove_extension))
.route("/agent/stop", post(stop_agent))
.with_state(state)
}