agentmux_common/agent_create_types.rs
1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The request types of `Agents create` and of the `runtime` choice `Agents spawn` shares with it. Re-exported by
5//! `api_types`, where the rest of the agent requests are.
6
7use serde::{Deserialize, Serialize};
8
9use crate::api_types::UiAutomationAuth;
10
11/// Where a new agent runs, for `Agents spawn` and `Agents create`: absent, a worker runs as its leader does
12/// and a created agent as its template says.
13#[derive(Debug, Clone, Default, Serialize, Deserialize)]
14pub struct ContainerAsk {
15 /// `native` (on the host) or `container`.
16 #[serde(default, skip_serializing_if = "Option::is_none")]
17 pub runtime: Option<String>,
18 /// The image of a container agent: `ghcr.io/agentmuxai/agent-base:developer` or `ghcr.io/agentmuxai/agent-base:latest`.
19 #[serde(default, skip_serializing_if = "Option::is_none")]
20 pub container_image: Option<String>,
21 /// A container agent's memory limit in MB (`"auto"`, or `0` for no limit).
22 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub memory_mb: Option<serde_json::Value>,
24 /// A container agent's CPU limit (fractions allowed; `"auto"`, or `0` for no limit).
25 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub cpus: Option<serde_json::Value>,
27}
28
29impl ContainerAsk {
30 /// Whether the caller asked for anything.
31 pub fn is_empty(&self) -> bool {
32 self.runtime.is_none() && self.container_image.is_none() && self.memory_mb.is_none() && self.cpus.is_none()
33 }
34}
35
36/// Which harness and model route a new agent runs on, for `Agents spawn` and `Agents create`: absent, a worker
37/// has its leader's harness and route, and a created agent its template's. The model is the request's own `model`.
38#[derive(Debug, Clone, Default, Serialize, Deserialize)]
39pub struct RouteAsk {
40 /// The harness (`claude`, `codex`, ...). It is fixed when the agent is made.
41 #[serde(default, skip_serializing_if = "Option::is_none")]
42 pub harness: Option<String>,
43 /// A model route from `Agents routes` (`openrouter`); `anthropic` or `login` for the harness's own sign-in.
44 #[serde(default, skip_serializing_if = "Option::is_none")]
45 pub route: Option<String>,
46}
47
48/// `POST /api/v1/agent/create`: a named agent made from a template, not a worker (`Agents create`).
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct CreateAgentRequest {
51 #[serde(flatten)]
52 pub auth: UiAutomationAuth,
53 /// The new agent's name.
54 pub name: String,
55 /// The seeded template to make it from, by id or name.
56 pub template: String,
57 /// The account to link, by id or name/email; absent, the caller's, or another signed-in one.
58 #[serde(default, skip_serializing_if = "Option::is_none")]
59 pub account: Option<String>,
60 #[serde(flatten)]
61 pub container: ContainerAsk,
62 /// The model, on the route (`route`); absent, the route's default.
63 #[serde(default, skip_serializing_if = "Option::is_none")]
64 pub model: Option<String>,
65 #[serde(flatten)]
66 pub route: RouteAsk,
67 /// The user's own words in this turn asking for it, verbatim; empty when the user didn't ask.
68 #[serde(default)]
69 pub user_instruction: String,
70}
71
72/// `POST /api/v1/agent/import`: an agent archive file put in My Agents (`Agents import`).
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct ImportAgentRequest {
75 #[serde(flatten)]
76 pub auth: UiAutomationAuth,
77 /// The archive: a name or path ending `.abf` under the caller's working folder.
78 pub file: String,
79 /// `move` keeps the agent's id (it is the same agent, arriving here) and is refused where that id is already an agent;
80 /// `copy` makes a new agent of it with a new id. Absent: `move`.
81 #[serde(default, skip_serializing_if = "Option::is_none")]
82 pub mode: Option<String>,
83 /// The agent's name here; absent, its own (a copy gets " copy" after it).
84 #[serde(default, skip_serializing_if = "Option::is_none")]
85 pub name: Option<String>,
86 /// Read and check the archive and say what would be made; make nothing and ask no one.
87 #[serde(default)]
88 pub dry_run: bool,
89 /// The user's own words in this turn asking for it, verbatim; empty when the user didn't ask.
90 #[serde(default)]
91 pub user_instruction: String,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct SpawnAgentRequest {
96 #[serde(flatten)]
97 pub auth: UiAutomationAuth,
98 /// The worker's name; absent, the first free "<leader> worker N".
99 #[serde(default, skip_serializing_if = "Option::is_none")]
100 pub name: Option<String>,
101 /// The worker's model and effort; absent, the leader's.
102 #[serde(default, skip_serializing_if = "Option::is_none")]
103 pub model: Option<String>,
104 #[serde(default, skip_serializing_if = "Option::is_none")]
105 pub effort: Option<String>,
106 /// The account to run the worker on, by id or name/email; absent, the
107 /// leader's, or another signed-in one when the leader's can't run.
108 #[serde(default, skip_serializing_if = "Option::is_none")]
109 pub account: Option<String>,
110 /// The worker's task, its first message. srv shows its start to the user
111 /// when it asks; the MCP server sends it, signed as the leader.
112 pub brief: String,
113 /// Where it runs, when not as its leader does.
114 #[serde(flatten)]
115 pub container: ContainerAsk,
116 #[serde(flatten)]
117 pub route: RouteAsk,
118 /// The user's own words in this turn asking for it, verbatim; empty when
119 /// the user didn't ask. Checked like `QuitSelf`'s (`self_quit::gate`).
120 #[serde(default)]
121 pub user_instruction: String,
122}
123
124/// One worker of a `POST /api/v1/agent/spawn_many`: what `SpawnAgentRequest` asks of one.
125#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct SpawnWorkerSpec {
127 #[serde(default, skip_serializing_if = "Option::is_none")]
128 pub name: Option<String>,
129 #[serde(default, skip_serializing_if = "Option::is_none")]
130 pub model: Option<String>,
131 #[serde(default, skip_serializing_if = "Option::is_none")]
132 pub effort: Option<String>,
133 #[serde(default, skip_serializing_if = "Option::is_none")]
134 pub account: Option<String>,
135 /// The worker's task, its first message.
136 pub brief: String,
137 #[serde(flatten)]
138 pub container: ContainerAsk,
139 #[serde(flatten)]
140 pub route: RouteAsk,
141}
142
143/// `POST /api/v1/agent/spawn_many`: several workers at once, with one approval for all of them
144/// (`SPEC_COUNTDOWN_BUTTONS_AND_BATCH_AGENT_ACTIONS_2026_10_28.md` ยง5). All start or none do.
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct SpawnManyRequest {
147 #[serde(flatten)]
148 pub auth: UiAutomationAuth,
149 pub workers: Vec<SpawnWorkerSpec>,
150 /// The user's own words in this turn asking for them, verbatim; empty when the user didn't ask.
151 #[serde(default)]
152 pub user_instruction: String,
153}