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)
}
+1
View File
@@ -807,6 +807,7 @@ config_value!(GOOSE_SEARCH_PATHS, Vec<String>);
config_value!(GOOSE_MODE, GooseMode);
config_value!(GOOSE_PROVIDER, String);
config_value!(GOOSE_MODEL, String);
config_value!(GOOSE_MAX_ACTIVE_AGENTS, usize);
/// Load init-config.yaml from workspace root if it exists.
/// This function is shared between the config recovery and the init_config endpoint.
+5 -1
View File
@@ -1,6 +1,7 @@
use crate::agents::extension::PlatformExtensionContext;
use crate::agents::Agent;
use crate::config::paths::Paths;
use crate::config::Config;
use crate::scheduler::Scheduler;
use crate::scheduler_trait::SchedulerTrait;
use anyhow::Result;
@@ -52,7 +53,10 @@ impl AgentManager {
pub async fn instance() -> Result<Arc<Self>> {
AGENT_MANAGER
.get_or_try_init(|| async {
let manager = Self::new(Some(DEFAULT_MAX_SESSION)).await?;
let max_sessions = Config::global()
.get_goose_max_active_agents()
.unwrap_or(DEFAULT_MAX_SESSION);
let manager = Self::new(Some(max_sessions)).await?;
Ok(Arc::new(manager))
})
.await