swarm: /clear starts an agent's next turn on a fresh session
This commit is contained in:
parent
7b62f2c22a
commit
fb9d4b5040
1 changed files with 155 additions and 22 deletions
|
|
@ -112,6 +112,50 @@ pub(crate) async fn post_agent_cancel(
|
|||
send(&client, &agent, &from, AgentControl::Cancel).await
|
||||
}
|
||||
|
||||
/// Start an agent's next turn on a fresh claude session.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/agents/{name}/new-session",
|
||||
params(("name" = String, Path, description = "agent whose next turn starts a new session")),
|
||||
responses(
|
||||
(status = 200, description = "the agent answered and queued the reset, which takes \
|
||||
effect at its next turn; `acted` is true", body = CancelResponse),
|
||||
(status = 400, description = "the agent name is not shaped like an identifier \
|
||||
(problem+json)", body = String),
|
||||
(status = 401, description = "the request carries no `Remote-User` (problem+json)",
|
||||
body = String),
|
||||
(status = 503, description = "the agent's harness is not subscribed - not running, \
|
||||
or not connected to the swarm queue - or no swarm queue is configured on this \
|
||||
host or it could not be reached (problem+json)", body = String),
|
||||
(status = 504, description = "the harness held the command and did not answer in \
|
||||
time, so whether it took effect is unknown (problem+json)", body = String),
|
||||
(status = 500, description = "the queue refused or failed the request (problem+json)",
|
||||
body = String),
|
||||
),
|
||||
tag = "agents"
|
||||
)]
|
||||
pub(crate) async fn post_agent_new_session(
|
||||
State(state): State<AppState>,
|
||||
Path(agent): Path<String>,
|
||||
headers: HeaderMap,
|
||||
) -> Result<Json<CancelResponse>, ProblemDetails> {
|
||||
let (agent, from) = target(&headers, &agent).map_err(|(s, d)| error_problem(s, d))?;
|
||||
let Some(status) = state.status.as_ref() else {
|
||||
return Err(error_problem(
|
||||
StatusCode::SERVICE_UNAVAILABLE,
|
||||
"no swarm queue is configured on this host",
|
||||
));
|
||||
};
|
||||
let client = status.queue_client();
|
||||
swarm_queue_client::ensure_connected(&client).map_err(|e| {
|
||||
error_problem(
|
||||
StatusCode::SERVICE_UNAVAILABLE,
|
||||
&swarm_queue_client::chain(&e),
|
||||
)
|
||||
})?;
|
||||
send(&client, &agent, &from, AgentControl::NewSession).await
|
||||
}
|
||||
|
||||
/// The agent and who is asking, or the refusal. Everything decided before the
|
||||
/// queue is touched.
|
||||
pub(crate) fn target(
|
||||
|
|
@ -160,7 +204,7 @@ async fn send(
|
|||
Err(error_problem(
|
||||
StatusCode::GATEWAY_TIMEOUT,
|
||||
&format!(
|
||||
"{agent} did not answer in time: whether anything was cancelled is unknown"
|
||||
"{agent} did not answer in time: whether the command took effect is unknown"
|
||||
),
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue