Add /agent/stop endpoint, make max active agents configurable (#5826)
This commit is contained in:
@@ -67,6 +67,11 @@ pub struct StartAgentRequest {
|
|||||||
recipe_deeplink: Option<String>,
|
recipe_deeplink: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
|
pub struct StopAgentRequest {
|
||||||
|
session_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, utoipa::ToSchema)]
|
#[derive(Deserialize, utoipa::ToSchema)]
|
||||||
pub struct ResumeAgentRequest {
|
pub struct ResumeAgentRequest {
|
||||||
session_id: String,
|
session_id: String,
|
||||||
@@ -599,6 +604,34 @@ async fn agent_remove_extension(
|
|||||||
Ok(StatusCode::OK)
|
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 {
|
pub fn routes(state: Arc<AppState>) -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/agent/start", post(start_agent))
|
.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/update_from_session", post(update_from_session))
|
||||||
.route("/agent/add_extension", post(agent_add_extension))
|
.route("/agent/add_extension", post(agent_add_extension))
|
||||||
.route("/agent/remove_extension", post(agent_remove_extension))
|
.route("/agent/remove_extension", post(agent_remove_extension))
|
||||||
|
.route("/agent/stop", post(stop_agent))
|
||||||
.with_state(state)
|
.with_state(state)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -807,6 +807,7 @@ config_value!(GOOSE_SEARCH_PATHS, Vec<String>);
|
|||||||
config_value!(GOOSE_MODE, GooseMode);
|
config_value!(GOOSE_MODE, GooseMode);
|
||||||
config_value!(GOOSE_PROVIDER, String);
|
config_value!(GOOSE_PROVIDER, String);
|
||||||
config_value!(GOOSE_MODEL, String);
|
config_value!(GOOSE_MODEL, String);
|
||||||
|
config_value!(GOOSE_MAX_ACTIVE_AGENTS, usize);
|
||||||
|
|
||||||
/// Load init-config.yaml from workspace root if it exists.
|
/// Load init-config.yaml from workspace root if it exists.
|
||||||
/// This function is shared between the config recovery and the init_config endpoint.
|
/// This function is shared between the config recovery and the init_config endpoint.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::agents::extension::PlatformExtensionContext;
|
use crate::agents::extension::PlatformExtensionContext;
|
||||||
use crate::agents::Agent;
|
use crate::agents::Agent;
|
||||||
use crate::config::paths::Paths;
|
use crate::config::paths::Paths;
|
||||||
|
use crate::config::Config;
|
||||||
use crate::scheduler::Scheduler;
|
use crate::scheduler::Scheduler;
|
||||||
use crate::scheduler_trait::SchedulerTrait;
|
use crate::scheduler_trait::SchedulerTrait;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@@ -52,7 +53,10 @@ impl AgentManager {
|
|||||||
pub async fn instance() -> Result<Arc<Self>> {
|
pub async fn instance() -> Result<Arc<Self>> {
|
||||||
AGENT_MANAGER
|
AGENT_MANAGER
|
||||||
.get_or_try_init(|| async {
|
.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))
|
Ok(Arc::new(manager))
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user