kiteml-cli 0.7.0__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/PKG-INFO +14 -2
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/README.md +13 -1
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/pyproject.toml +1 -1
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/__init__.py +1 -1
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/commands/augment.py +5 -5
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/commands/evaluations.py +56 -17
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/commands/rl.py +14 -14
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/commands/twin.py +66 -11
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/main.py +14 -1
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/client.py +39 -3
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/mcp/common.py +5 -2
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/mcp/server.py +99 -46
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/.gitignore +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/archive.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/auth.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/__init__.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/commands/__init__.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/commands/auth_cmd.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/cli/commands/config_cmd.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/config.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/mcp/__init__.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/output.py +0 -0
- {kiteml_cli-0.7.0 → kiteml_cli-0.9.0}/src/kite_cli/progress.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: kiteml-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Kite CLI and MCP server: train robot policies with reinforcement learning in simulation, augment LeRobot datasets, and build MuJoCo digital twins, from your terminal or an AI agent.
|
|
5
5
|
Project-URL: Homepage, https://kiteml.com
|
|
6
6
|
Project-URL: Documentation, https://docs.kiteml.com/tools/cli-and-mcp
|
|
@@ -109,6 +109,7 @@ lerobot/pusht to look like this photo".
|
|
|
109
109
|
| `kite_rl_status`, `kite_rl_metrics`, `kite_rl_report`, `kite_rl_list` | Follow training and read each run's verdict |
|
|
110
110
|
| `kite_augment_create`, `kite_augment_status`, `kite_augment_list`, `kite_augment_cancel` | Augment LeRobot datasets |
|
|
111
111
|
| `kite_twin_validate`, `kite_twin_create`, `kite_twin_status`, `kite_twin_list`, `kite_twin_cancel`, `kite_twin_resume` | Build MuJoCo digital twins (beta) |
|
|
112
|
+
| `kite_twin_note`, `kite_twin_answer` | Guide a twin while it builds: leave notes for its agents, answer their questions |
|
|
112
113
|
| `kite_eval_validate`, `kite_eval_run`, `kite_eval_status`, `kite_eval_list`, `kite_eval_report`, `kite_eval_logs`, `kite_eval_cancel`, `kite_eval_resume` | Evaluate a policy on a Kite SDK spec on Kite's machines and read the scorecard (beta) |
|
|
113
114
|
| `kite_doctor` | Check connectivity and authentication |
|
|
114
115
|
|
|
@@ -141,6 +142,16 @@ Build a digital twin (beta, enabled per account):
|
|
|
141
142
|
kite twin create lerobot/svla_so101_pickplace --robot so101 --out ./twins # -> ./twins/twin_.../scene.xml
|
|
142
143
|
```
|
|
143
144
|
|
|
145
|
+
While it builds, `kite twin status twin_...` shows each judged round's scores, what the agents are doing, an open
|
|
146
|
+
question and your notes. Guide it:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
kite twin note twin_... "It is 2.5 cm, a matte red cube" --on red_block # read by the agents at their next step
|
|
150
|
+
kite twin note twin_... --delete note_...
|
|
151
|
+
kite twin answer twin_... "2.5 cm" # answers the open question
|
|
152
|
+
kite twin resume twin_... --from-round 1 # go back to a kept round
|
|
153
|
+
```
|
|
154
|
+
|
|
144
155
|
Evaluate a policy on a Kite SDK spec, on Kite's machines (beta):
|
|
145
156
|
|
|
146
157
|
```bash
|
|
@@ -152,7 +163,8 @@ A file too big to send, such as a checkpoint's weights, can come from the Huggin
|
|
|
152
163
|
`--hf PATH=OWNER/NAME@COMMIT:FILE` or `--hf PATH=<the file's huggingface.co URL>`, and `--s3 PATH=s3://BUCKET/KEY`,
|
|
153
164
|
PATH being the path the spec names. A checkpoint of one of your Kite training runs goes as
|
|
154
165
|
`--training-run PATH=trn_...[@STEP]` (its latest without `@STEP`), PATH being the checkpoint folder the spec names:
|
|
155
|
-
Kite reads it from its own storage and publishes nothing.
|
|
166
|
+
Kite reads it from its own storage and publishes nothing. One of your twins goes as `--twin PATH=twin_...`, PATH being
|
|
167
|
+
the folder the twin unpacks to; the files in your PATH that differ from the twin's go inline beside it.
|
|
156
168
|
|
|
157
169
|
Every command prints JSON (`{"ok": true, "data": ...}`) so scripts and agents can parse it. Run `kite --help` for
|
|
158
170
|
the full list.
|
|
@@ -67,6 +67,7 @@ lerobot/pusht to look like this photo".
|
|
|
67
67
|
| `kite_rl_status`, `kite_rl_metrics`, `kite_rl_report`, `kite_rl_list` | Follow training and read each run's verdict |
|
|
68
68
|
| `kite_augment_create`, `kite_augment_status`, `kite_augment_list`, `kite_augment_cancel` | Augment LeRobot datasets |
|
|
69
69
|
| `kite_twin_validate`, `kite_twin_create`, `kite_twin_status`, `kite_twin_list`, `kite_twin_cancel`, `kite_twin_resume` | Build MuJoCo digital twins (beta) |
|
|
70
|
+
| `kite_twin_note`, `kite_twin_answer` | Guide a twin while it builds: leave notes for its agents, answer their questions |
|
|
70
71
|
| `kite_eval_validate`, `kite_eval_run`, `kite_eval_status`, `kite_eval_list`, `kite_eval_report`, `kite_eval_logs`, `kite_eval_cancel`, `kite_eval_resume` | Evaluate a policy on a Kite SDK spec on Kite's machines and read the scorecard (beta) |
|
|
71
72
|
| `kite_doctor` | Check connectivity and authentication |
|
|
72
73
|
|
|
@@ -99,6 +100,16 @@ Build a digital twin (beta, enabled per account):
|
|
|
99
100
|
kite twin create lerobot/svla_so101_pickplace --robot so101 --out ./twins # -> ./twins/twin_.../scene.xml
|
|
100
101
|
```
|
|
101
102
|
|
|
103
|
+
While it builds, `kite twin status twin_...` shows each judged round's scores, what the agents are doing, an open
|
|
104
|
+
question and your notes. Guide it:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
kite twin note twin_... "It is 2.5 cm, a matte red cube" --on red_block # read by the agents at their next step
|
|
108
|
+
kite twin note twin_... --delete note_...
|
|
109
|
+
kite twin answer twin_... "2.5 cm" # answers the open question
|
|
110
|
+
kite twin resume twin_... --from-round 1 # go back to a kept round
|
|
111
|
+
```
|
|
112
|
+
|
|
102
113
|
Evaluate a policy on a Kite SDK spec, on Kite's machines (beta):
|
|
103
114
|
|
|
104
115
|
```bash
|
|
@@ -110,7 +121,8 @@ A file too big to send, such as a checkpoint's weights, can come from the Huggin
|
|
|
110
121
|
`--hf PATH=OWNER/NAME@COMMIT:FILE` or `--hf PATH=<the file's huggingface.co URL>`, and `--s3 PATH=s3://BUCKET/KEY`,
|
|
111
122
|
PATH being the path the spec names. A checkpoint of one of your Kite training runs goes as
|
|
112
123
|
`--training-run PATH=trn_...[@STEP]` (its latest without `@STEP`), PATH being the checkpoint folder the spec names:
|
|
113
|
-
Kite reads it from its own storage and publishes nothing.
|
|
124
|
+
Kite reads it from its own storage and publishes nothing. One of your twins goes as `--twin PATH=twin_...`, PATH being
|
|
125
|
+
the folder the twin unpacks to; the files in your PATH that differ from the twin's go inline beside it.
|
|
114
126
|
|
|
115
127
|
Every command prints JSON (`{"ok": true, "data": ...}`) so scripts and agents can parse it. Run `kite --help` for
|
|
116
128
|
the full list.
|
|
@@ -14,7 +14,7 @@ from typing import List, Optional
|
|
|
14
14
|
|
|
15
15
|
import typer
|
|
16
16
|
|
|
17
|
-
from kite_cli.client import KiteClient, KiteAPIError
|
|
17
|
+
from kite_cli.client import KiteClient, KiteAPIError, seg
|
|
18
18
|
from kite_cli.output import print_error, print_json
|
|
19
19
|
from kite_cli.progress import wait_for_completion
|
|
20
20
|
|
|
@@ -166,7 +166,7 @@ def status(
|
|
|
166
166
|
"""Get an augmentation's status."""
|
|
167
167
|
try:
|
|
168
168
|
client = KiteClient()
|
|
169
|
-
path = f"/v1/augmentations/{aug_id}"
|
|
169
|
+
path = f"/v1/augmentations/{seg(aug_id)}"
|
|
170
170
|
result = wait_for_completion(client, path, terminal_states=_TERMINAL) if wait else client.get(path)
|
|
171
171
|
print_json(result)
|
|
172
172
|
except KiteAPIError as e:
|
|
@@ -189,7 +189,7 @@ def cancel(aug_id: str = typer.Argument(..., help="Augmentation id (aug_...)")):
|
|
|
189
189
|
"""Cancel a running augmentation."""
|
|
190
190
|
try:
|
|
191
191
|
client = KiteClient()
|
|
192
|
-
result = client.post(f"/v1/augmentations/{aug_id}/cancel")
|
|
192
|
+
result = client.post(f"/v1/augmentations/{seg(aug_id)}/cancel")
|
|
193
193
|
print_json(result)
|
|
194
194
|
except KiteAPIError as e:
|
|
195
195
|
print_error(e.message, code=e.code, details=e.details)
|
|
@@ -220,7 +220,7 @@ def download(
|
|
|
220
220
|
"""Download a finished download-output dataset, preserving its file layout."""
|
|
221
221
|
try:
|
|
222
222
|
client = KiteClient()
|
|
223
|
-
result = client.get(f"/v1/augmentations/{aug_id}")
|
|
223
|
+
result = client.get(f"/v1/augmentations/{seg(aug_id)}")
|
|
224
224
|
if result.get("status") != "succeeded":
|
|
225
225
|
print_error(f"Augmentation is '{result.get('status')}', not succeeded yet.")
|
|
226
226
|
return
|
|
@@ -234,7 +234,7 @@ def download(
|
|
|
234
234
|
# to a GCS signed URL); the layout is reconstructed from each file's path.
|
|
235
235
|
dest = out / f["path"]
|
|
236
236
|
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
237
|
-
client.download(f"/v1/augmentations/{aug_id}/files/{f['path']}", str(dest))
|
|
237
|
+
client.download(f"/v1/augmentations/{seg(aug_id)}/files/{f['path']}", str(dest))
|
|
238
238
|
written.append(str(dest))
|
|
239
239
|
print_json({"downloaded": written, "dir": str(out)})
|
|
240
240
|
except KiteAPIError as e:
|
|
@@ -18,7 +18,9 @@ names (`files_required`), and sends each from this disk: a file or folder Kite s
|
|
|
18
18
|
else inline (about 15 MB in all). A file on the Hugging Face Hub, such as a checkpoint's weights, goes as a
|
|
19
19
|
reference: `--hf PATH=OWNER/NAME@COMMIT:FILE`, PATH as the spec names it (a folder's file as FOLDER/FILE); an object
|
|
20
20
|
in a public S3 bucket as `--s3 PATH=s3://BUCKET/KEY`; a checkpoint of one of your Kite training runs as
|
|
21
|
-
`--training-run PATH=trn_...[@STEP]`, PATH being the folder the spec names (`policy.asset_dir`)
|
|
21
|
+
`--training-run PATH=trn_...[@STEP]`, PATH being the folder the spec names (`policy.asset_dir`); one of your
|
|
22
|
+
twins as `--twin PATH=twin_...`, PATH being the folder its archive unpacks to (`scene.xml`, `assets/`), and every file
|
|
23
|
+
in your PATH the twin does not have as it is (a scene of your own, an embodiment file) inline beside it.
|
|
22
24
|
Where runs go: --out DIR, else $KITE_EVAL_RUNS_DIR, else ./runs (`~` works). Paths printed are absolute. A run
|
|
23
25
|
directory extracts to <out>/<run_id>/; the SDK's `kite verify <out>/<run_id> --evals DIR` checks it, DIR being the
|
|
24
26
|
evaluators the spec named (the run records where its job read them, not your folder).
|
|
@@ -41,7 +43,7 @@ import httpx
|
|
|
41
43
|
import typer
|
|
42
44
|
|
|
43
45
|
from kite_cli.archive import storage_client, unpack, verified
|
|
44
|
-
from kite_cli.client import KiteAPIError, KiteClient, post_create
|
|
46
|
+
from kite_cli.client import KiteAPIError, KiteClient, post_create, seg
|
|
45
47
|
from kite_cli.output import print_error, print_json
|
|
46
48
|
from kite_cli.progress import wait_for_completion
|
|
47
49
|
|
|
@@ -57,6 +59,7 @@ _ROUNDS = 64 # validate calls while the files are worked out: one per missing p
|
|
|
57
59
|
_HF = re.compile(r"(?P<repo>[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*)@(?P<revision>[0-9a-f]{40})"
|
|
58
60
|
r":(?P<path>.+)")
|
|
59
61
|
_TRN = re.compile(r"(?P<run>trn_[0-9A-HJKMNP-TV-Z]{26})(@(?P<step>[0-9]+))?") # a training run's id, as the API has it
|
|
62
|
+
_TWIN = re.compile(r"twin_[0-9A-HJKMNP-TV-Z]{26}")
|
|
60
63
|
|
|
61
64
|
_SET_HELP = "FIELD=VALUE, as `kite run --set` (repeatable)"
|
|
62
65
|
_HF_HELP = ("PATH=OWNER/NAME@COMMIT:FILE, or PATH=URL (https://huggingface.co/OWNER/NAME/blob/REVISION/FILE; Kite pins a "
|
|
@@ -66,6 +69,8 @@ _S3_HELP = ("PATH=s3://BUCKET/KEY (or its https://BUCKET.s3.amazonaws.com/KEY UR
|
|
|
66
69
|
_TRN_HELP = ("PATH=trn_...[@STEP]: the spec's PATH (a folder, e.g. policy.asset_dir) is the pretrained_model/ folder "
|
|
67
70
|
"of one of your training runs' checkpoints, at STEP or its latest; read from Kite's storage, nothing is "
|
|
68
71
|
"published (repeatable)")
|
|
72
|
+
_TWIN_HELP = ("PATH=twin_...: the spec's PATH is the folder one of your twins unpacks to (scene.xml, assets/), read from "
|
|
73
|
+
"Kite's storage; a file in your PATH the twin does not have as it is goes inline beside it (repeatable)")
|
|
69
74
|
|
|
70
75
|
|
|
71
76
|
@app.command()
|
|
@@ -75,12 +80,13 @@ def validate(
|
|
|
75
80
|
hf: Optional[List[str]] = typer.Option(None, "--hf", help=_HF_HELP),
|
|
76
81
|
s3: Optional[List[str]] = typer.Option(None, "--s3", help=_S3_HELP),
|
|
77
82
|
training_run: Optional[List[str]] = typer.Option(None, "--training-run", help=_TRN_HELP),
|
|
83
|
+
twin: Optional[List[str]] = typer.Option(None, "--twin", help=_TWIN_HELP),
|
|
78
84
|
kite_version: Optional[str] = typer.Option(None, "--kite-version", help="The Kite release you expect"),
|
|
79
85
|
):
|
|
80
86
|
"""Free dry run of a run: the spec plans, every file it names is sent, and the price. Creates nothing."""
|
|
81
87
|
try:
|
|
82
88
|
client = KiteClient(timeout=_SLOW_S)
|
|
83
|
-
_, validation, sent = request(client, spec, set_ or [], remote_refs(hf, s3, training_run), kite_version)
|
|
89
|
+
_, validation, sent = request(client, spec, set_ or [], remote_refs(hf, s3, training_run, twin), kite_version)
|
|
84
90
|
print_json({"ok": True, "data": validation, "files": sent})
|
|
85
91
|
except KiteAPIError as e:
|
|
86
92
|
print_error(e.message, code=e.code, details=e.details)
|
|
@@ -93,6 +99,7 @@ def run(
|
|
|
93
99
|
hf: Optional[List[str]] = typer.Option(None, "--hf", help=_HF_HELP),
|
|
94
100
|
s3: Optional[List[str]] = typer.Option(None, "--s3", help=_S3_HELP),
|
|
95
101
|
training_run: Optional[List[str]] = typer.Option(None, "--training-run", help=_TRN_HELP),
|
|
102
|
+
twin: Optional[List[str]] = typer.Option(None, "--twin", help=_TWIN_HELP),
|
|
96
103
|
max_minutes: Optional[int] = typer.Option(
|
|
97
104
|
None, "--max-minutes", help="The run's cap, 1-720: what it reserves and the most it can cost "
|
|
98
105
|
"(default 60 on CPU, 120 on an L4)"),
|
|
@@ -113,7 +120,7 @@ def run(
|
|
|
113
120
|
key = idempotency_key or str(uuid.uuid4())
|
|
114
121
|
try:
|
|
115
122
|
client = KiteClient(timeout=_SLOW_S)
|
|
116
|
-
body, _, _ = request(client, spec, set_ or [], remote_refs(hf, s3, training_run), kite_version)
|
|
123
|
+
body, _, _ = request(client, spec, set_ or [], remote_refs(hf, s3, training_run, twin), kite_version)
|
|
117
124
|
options = {k: v for k, v in (("max_minutes", max_minutes), ("no_eval", no_eval),
|
|
118
125
|
("verify_determinism", verify_determinism)) if v}
|
|
119
126
|
body = {**body, **({"options": options} if options else {}), **({"label": label} if label else {})}
|
|
@@ -148,7 +155,7 @@ def status(
|
|
|
148
155
|
"""A run's live status, phase, episodes done, and once it has succeeded its result and `download`."""
|
|
149
156
|
try:
|
|
150
157
|
client = KiteClient()
|
|
151
|
-
path = f"/v1/evaluations/{run_id}"
|
|
158
|
+
path = f"/v1/evaluations/{seg(run_id)}"
|
|
152
159
|
if wait:
|
|
153
160
|
print_json(wait_for_completion(client, path, terminal_states=_TERMINAL, poll_interval=_POLL_S))
|
|
154
161
|
else:
|
|
@@ -173,7 +180,7 @@ def list_runs(
|
|
|
173
180
|
def report(run_id: str = typer.Argument(..., help="Evaluation id (eval_...)")):
|
|
174
181
|
"""A succeeded run's scorecard: every evaluator's value, interval and count, and what was not measured."""
|
|
175
182
|
try:
|
|
176
|
-
print_json(KiteClient().get(f"/v1/evaluations/{run_id}/report"))
|
|
183
|
+
print_json(KiteClient().get(f"/v1/evaluations/{seg(run_id)}/report"))
|
|
177
184
|
except KiteAPIError as e:
|
|
178
185
|
print_error(e.message, code=e.code, details=e.details)
|
|
179
186
|
|
|
@@ -185,7 +192,7 @@ def logs(
|
|
|
185
192
|
):
|
|
186
193
|
"""What the SDK printed, oldest first: readable while the run builds and after."""
|
|
187
194
|
try:
|
|
188
|
-
print_json(KiteClient().get(f"/v1/evaluations/{run_id}/logs", params={"tail": tail}))
|
|
195
|
+
print_json(KiteClient().get(f"/v1/evaluations/{seg(run_id)}/logs", params={"tail": tail}))
|
|
189
196
|
except KiteAPIError as e:
|
|
190
197
|
print_error(e.message, code=e.code, details=e.details)
|
|
191
198
|
|
|
@@ -198,7 +205,7 @@ def list_files(
|
|
|
198
205
|
all_pages: bool = typer.Option(False, "--all", help="Follow next_cursor through every page; print one list"),
|
|
199
206
|
):
|
|
200
207
|
"""The files of a succeeded run's directory (path, bytes, sha256), sorted by path."""
|
|
201
|
-
path = f"/v1/evaluations/{run_id}/files"
|
|
208
|
+
path = f"/v1/evaluations/{seg(run_id)}/files"
|
|
202
209
|
size = limit or 100
|
|
203
210
|
try:
|
|
204
211
|
client = KiteClient()
|
|
@@ -229,7 +236,7 @@ def download(
|
|
|
229
236
|
"""Download a succeeded run: <out>/<run_id>.tar.gz, sha256-verified, unpacked to <out>/<run_id>/."""
|
|
230
237
|
try:
|
|
231
238
|
client = KiteClient(timeout=120)
|
|
232
|
-
print_json(_save(client, client.get(f"/v1/evaluations/{run_id}"), _out_dir(out), extract=extract))
|
|
239
|
+
print_json(_save(client, client.get(f"/v1/evaluations/{seg(run_id)}"), _out_dir(out), extract=extract))
|
|
233
240
|
except KiteAPIError as e:
|
|
234
241
|
print_error(e.message, code=e.code, details=e.details)
|
|
235
242
|
|
|
@@ -239,7 +246,7 @@ def cancel(run_id: str = typer.Argument(..., help="Evaluation id (eval_...)")):
|
|
|
239
246
|
"""Stop a queued or running run: canceling until its job has stopped, then canceled. It pays the minutes it
|
|
240
247
|
ran."""
|
|
241
248
|
try:
|
|
242
|
-
print_json(KiteClient().post(f"/v1/evaluations/{run_id}/cancel"))
|
|
249
|
+
print_json(KiteClient().post(f"/v1/evaluations/{seg(run_id)}/cancel"))
|
|
243
250
|
except KiteAPIError as e:
|
|
244
251
|
print_error(e.message, code=e.code, details=e.details)
|
|
245
252
|
|
|
@@ -248,7 +255,7 @@ def cancel(run_id: str = typer.Argument(..., help="Evaluation id (eval_...)")):
|
|
|
248
255
|
def resume(run_id: str = typer.Argument(..., help="Evaluation id (eval_...)")):
|
|
249
256
|
"""Run a failed or canceled run again from its request, as a new attempt: it reserves its cap again."""
|
|
250
257
|
try:
|
|
251
|
-
print_json(KiteClient().post(f"/v1/evaluations/{run_id}/resume"))
|
|
258
|
+
print_json(KiteClient().post(f"/v1/evaluations/{seg(run_id)}/resume"))
|
|
252
259
|
except KiteAPIError as e:
|
|
253
260
|
print_error(e.message, code=e.code, details=e.details)
|
|
254
261
|
|
|
@@ -258,8 +265,9 @@ def resume(run_id: str = typer.Argument(..., help="Evaluation id (eval_...)")):
|
|
|
258
265
|
def request(client: KiteClient, spec: Path, overrides: List[str], remote: Dict[str, dict],
|
|
259
266
|
kite_version: Optional[str] = None) -> Tuple[dict, dict, Dict[str, str]]:
|
|
260
267
|
"""The request body for SPEC with every path it names, the validation that accepted it, and how each path went
|
|
261
|
-
(`sha256`, `inline`, `hf`, `s3`, `training_run`). `remote` maps the paths that are an `hf` file, an `s3`
|
|
262
|
-
|
|
268
|
+
(`sha256`, `inline`, `hf`, `s3`, `training_run`, `twin`). `remote` maps the paths that are an `hf` file, an `s3`
|
|
269
|
+
object, a training run's checkpoint folder or a twin's to their reference ({"hf": …}, {"s3": …},
|
|
270
|
+
{"training_run": …} or {"twin": …}).
|
|
263
271
|
|
|
264
272
|
The API names what it lacks: `files_required` lists the paths the spec names that the request does not carry,
|
|
265
273
|
and `file_unavailable` on `files.<path>` says a hash Kite does not ship. A path first goes by its hash alone, so
|
|
@@ -274,6 +282,10 @@ def request(client: KiteClient, spec: Path, overrides: List[str], remote: Dict[s
|
|
|
274
282
|
if local.is_file() and "training_run" not in ref:
|
|
275
283
|
files[key]["sha256"] = _file_sha256(local)
|
|
276
284
|
sent[key] = next(iter(ref))
|
|
285
|
+
if "twin" in ref and local.is_dir(): # the twin covers the folder: the API asks for none of its files
|
|
286
|
+
for rel in _twin_edits(client, ref["twin"], local):
|
|
287
|
+
files[posixpath.join(key, rel)] = _inline(base, posixpath.join(key, rel), files)
|
|
288
|
+
sent[posixpath.join(key, rel)] = "inline"
|
|
277
289
|
body: dict = {"spec_yaml": text, "spec_path": spec_path, "files": files}
|
|
278
290
|
if overrides:
|
|
279
291
|
body["overrides"] = list(overrides)
|
|
@@ -373,7 +385,8 @@ def _fits(key: str, raw_bytes: int, files: Dict[str, dict], biggest: List[Tuple[
|
|
|
373
385
|
raise KiteAPIError(413, f"{key} is not a file Kite ships, and it is too big to send inline "
|
|
374
386
|
f"({raw_bytes >> 20} MB{hint}): put its large files on the Hugging Face Hub or in a public "
|
|
375
387
|
"S3 bucket and pass each with --hf PATH=OWNER/NAME@COMMIT:FILE or --s3 PATH=s3://BUCKET/KEY (a "
|
|
376
|
-
"checkpoint Kite trained for you: --training-run PATH=trn_…@STEP
|
|
388
|
+
"checkpoint Kite trained for you: --training-run PATH=trn_…@STEP; a twin: --twin "
|
|
389
|
+
"PATH=twin_…)", code="file_too_large",
|
|
377
390
|
details={"path": key})
|
|
378
391
|
|
|
379
392
|
|
|
@@ -457,9 +470,35 @@ def training_run_refs(pairs: List[str]) -> Dict[str, dict]:
|
|
|
457
470
|
return refs
|
|
458
471
|
|
|
459
472
|
|
|
460
|
-
def
|
|
461
|
-
"""
|
|
462
|
-
|
|
473
|
+
def twin_refs(pairs: List[str]) -> Dict[str, dict]:
|
|
474
|
+
"""PATH=twin_… pairs as {"twin": id} references; the API checks the twin is the caller's and has succeeded."""
|
|
475
|
+
refs: Dict[str, dict] = {}
|
|
476
|
+
for pair in pairs:
|
|
477
|
+
key, _, ref = pair.partition("=")
|
|
478
|
+
if not key.strip() or not _TWIN.fullmatch(ref.strip()):
|
|
479
|
+
raise KiteAPIError(400, f"--twin {pair!r}: expected PATH=twin_…, a twin's id (twin_ and 26 characters)",
|
|
480
|
+
code="parameter_invalid", details={"param": "twin"})
|
|
481
|
+
refs[key.strip()] = {"twin": ref.strip()}
|
|
482
|
+
return refs
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
def _twin_edits(client: KiteClient, twin_id: str, local: Path) -> List[str]:
|
|
486
|
+
"""The files of the folder LOCAL that the twin does not have as they are (Kite's scene with its table lowered, an
|
|
487
|
+
embodiment file): what goes inline beside it, each replacing the twin's own."""
|
|
488
|
+
have: Dict[str, str] = {}
|
|
489
|
+
after = None
|
|
490
|
+
while True:
|
|
491
|
+
page = client.get(f"/v1/twins/{seg(twin_id)}/files", params={"limit": 100, **({"after": after} if after else {})})
|
|
492
|
+
have.update((f["path"], f["sha256"]) for f in page.get("data") or [])
|
|
493
|
+
after = page.get("next_cursor")
|
|
494
|
+
if not page.get("has_more") or not after:
|
|
495
|
+
return [rel for rel, p in _tree(local) if have.get(rel) != _file_sha256(p)]
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def remote_refs(hf: Optional[List[str]], s3: Optional[List[str]], training_run: Optional[List[str]],
|
|
499
|
+
twin: Optional[List[str]] = None) -> Dict[str, dict]:
|
|
500
|
+
"""The --hf, --s3, --training-run and --twin pairs as one map of path to reference."""
|
|
501
|
+
return {**hf_refs(hf or []), **s3_refs(s3 or []), **training_run_refs(training_run or []), **twin_refs(twin or [])}
|
|
463
502
|
|
|
464
503
|
|
|
465
504
|
# --- downloads ------------------------------------------------------------------------------------------------------
|
|
@@ -35,7 +35,7 @@ from typing import List, Optional
|
|
|
35
35
|
import httpx
|
|
36
36
|
import typer
|
|
37
37
|
|
|
38
|
-
from kite_cli.client import KiteAPIError, KiteClient, post_create
|
|
38
|
+
from kite_cli.client import KiteAPIError, KiteClient, post_create, seg
|
|
39
39
|
from kite_cli.output import print_error, print_json
|
|
40
40
|
from kite_cli.progress import wait_for_completion
|
|
41
41
|
|
|
@@ -103,7 +103,7 @@ def estimate(spec: Path = _SPEC):
|
|
|
103
103
|
@app.command()
|
|
104
104
|
def train(
|
|
105
105
|
spec: Path = _SPEC,
|
|
106
|
-
seeds: Optional[int] = typer.Option(None, "--seeds", help="Runs to start, one per seed (1-
|
|
106
|
+
seeds: Optional[int] = typer.Option(None, "--seeds", help="Runs to start, one per seed (1-4)"),
|
|
107
107
|
budget: Optional[str] = typer.Option(
|
|
108
108
|
None, "--budget", help="probe (300 iterations, a first signal in minutes) or standard; replaces the "
|
|
109
109
|
"spec's budget.iterations"
|
|
@@ -143,7 +143,7 @@ def status(
|
|
|
143
143
|
"""A run's live status, phase, progress and metrics; once packaged, its verdict and `output`."""
|
|
144
144
|
try:
|
|
145
145
|
client = KiteClient()
|
|
146
|
-
path = f"/v1/rl_runs/{run_id}"
|
|
146
|
+
path = f"/v1/rl_runs/{seg(run_id)}"
|
|
147
147
|
if wait:
|
|
148
148
|
print_json(wait_for_completion(client, path, terminal_states=_TERMINAL, poll_interval=_POLL_S))
|
|
149
149
|
else:
|
|
@@ -157,7 +157,7 @@ def metrics(run_id: str = _RUN_ID):
|
|
|
157
157
|
"""The training curve, every 5 iterations: mean reward per step, the same by reward term, episode length and
|
|
158
158
|
throughput."""
|
|
159
159
|
try:
|
|
160
|
-
print_json(KiteClient().get(f"/v1/rl_runs/{run_id}/metrics"))
|
|
160
|
+
print_json(KiteClient().get(f"/v1/rl_runs/{seg(run_id)}/metrics"))
|
|
161
161
|
except KiteAPIError as e:
|
|
162
162
|
print_error(e.message, code=e.code, details=e.details)
|
|
163
163
|
|
|
@@ -167,7 +167,7 @@ def report(run_id: str = _RUN_ID):
|
|
|
167
167
|
"""The verdict and how it was reached: each check with its value and limit, the metrics, the judge's read of the
|
|
168
168
|
clip, and the checkpoint chosen. run_not_ready until the run is packaged."""
|
|
169
169
|
try:
|
|
170
|
-
print_json(KiteClient().get(f"/v1/rl_runs/{run_id}/report"))
|
|
170
|
+
print_json(KiteClient().get(f"/v1/rl_runs/{seg(run_id)}/report"))
|
|
171
171
|
except KiteAPIError as e:
|
|
172
172
|
print_error(e.message, code=e.code, details=e.details)
|
|
173
173
|
|
|
@@ -175,7 +175,7 @@ def report(run_id: str = _RUN_ID):
|
|
|
175
175
|
@app.command()
|
|
176
176
|
def files(run_id: str = _RUN_ID):
|
|
177
177
|
"""Every file in a packaged run's bundle (path, bytes, sha256), sorted by path, following the cursor."""
|
|
178
|
-
path, params = f"/v1/rl_runs/{run_id}/files", {"limit": 100}
|
|
178
|
+
path, params = f"/v1/rl_runs/{seg(run_id)}/files", {"limit": 100}
|
|
179
179
|
try:
|
|
180
180
|
client = KiteClient()
|
|
181
181
|
data: list = []
|
|
@@ -207,7 +207,7 @@ def download(
|
|
|
207
207
|
def checkpoints(run_id: str = _RUN_ID):
|
|
208
208
|
"""The iterations the run saved (about every tenth of its budget, and the last)."""
|
|
209
209
|
try:
|
|
210
|
-
print_json(KiteClient().get(f"/v1/rl_runs/{run_id}/checkpoints"))
|
|
210
|
+
print_json(KiteClient().get(f"/v1/rl_runs/{seg(run_id)}/checkpoints"))
|
|
211
211
|
except KiteAPIError as e:
|
|
212
212
|
print_error(e.message, code=e.code, details=e.details)
|
|
213
213
|
|
|
@@ -223,7 +223,7 @@ def checkpoint(
|
|
|
223
223
|
"""Download one saved iteration of a run's policy."""
|
|
224
224
|
dest = (out or Path(f"{run_id}_{iteration}.{fmt}")).expanduser().resolve()
|
|
225
225
|
try:
|
|
226
|
-
KiteClient(timeout=120).download(f"/v1/rl_runs/{run_id}/checkpoints/{iteration}/download?format={fmt}", str(dest))
|
|
226
|
+
KiteClient(timeout=120).download(f"/v1/rl_runs/{seg(run_id)}/checkpoints/{iteration}/download?format={fmt}", str(dest))
|
|
227
227
|
print_json({"id": run_id, "iteration": iteration, "format": fmt, "path": str(dest)})
|
|
228
228
|
except KiteAPIError as e:
|
|
229
229
|
print_error(e.message, code=e.code, details=e.details)
|
|
@@ -235,7 +235,7 @@ def cancel(run_id: str = _RUN_ID):
|
|
|
235
235
|
then canceled with its outputs, charged for the minutes it trained. One that never started, or left nothing to
|
|
236
236
|
package, is refunded in full."""
|
|
237
237
|
try:
|
|
238
|
-
print_json(KiteClient().post(f"/v1/rl_runs/{run_id}/cancel"))
|
|
238
|
+
print_json(KiteClient().post(f"/v1/rl_runs/{seg(run_id)}/cancel"))
|
|
239
239
|
except KiteAPIError as e:
|
|
240
240
|
print_error(e.message, code=e.code, details=e.details)
|
|
241
241
|
|
|
@@ -245,13 +245,13 @@ def fork(
|
|
|
245
245
|
run_id: str = _RUN_ID,
|
|
246
246
|
overrides: List[str] = typer.Option([], "--set", help="key=value: a reward or randomization parameter "
|
|
247
247
|
"(repeatable; `kite rl catalog` lists them)"),
|
|
248
|
-
seeds: Optional[int] = typer.Option(None, "--seeds", help="Runs to start, one per seed (1-
|
|
248
|
+
seeds: Optional[int] = typer.Option(None, "--seeds", help="Runs to start, one per seed (1-4)"),
|
|
249
249
|
idempotency_key: Optional[str] = _KEY,
|
|
250
250
|
):
|
|
251
251
|
"""Train from a run's weights: its robot, task and budget, with the parameters you --set."""
|
|
252
252
|
params = _params(overrides)
|
|
253
253
|
try:
|
|
254
|
-
body = from_run(KiteClient().get(f"/v1/rl_runs/{run_id}"), "fork", params=params)
|
|
254
|
+
body = from_run(KiteClient().get(f"/v1/rl_runs/{seg(run_id)}"), "fork", params=params)
|
|
255
255
|
except KiteAPIError as e:
|
|
256
256
|
print_error(e.message, code=e.code, details=e.details)
|
|
257
257
|
return
|
|
@@ -269,7 +269,7 @@ def continue_run(
|
|
|
269
269
|
):
|
|
270
270
|
"""Keep training a run: its weights, schedule and optimizer, with its robot, task and budget."""
|
|
271
271
|
try:
|
|
272
|
-
body = from_run(KiteClient().get(f"/v1/rl_runs/{run_id}"), "continue", iterations=iterations)
|
|
272
|
+
body = from_run(KiteClient().get(f"/v1/rl_runs/{seg(run_id)}"), "continue", iterations=iterations)
|
|
273
273
|
except KiteAPIError as e:
|
|
274
274
|
print_error(e.message, code=e.code, details=e.details)
|
|
275
275
|
return
|
|
@@ -336,11 +336,11 @@ def _unzip(client: KiteClient, run_id: str, out: Path) -> Path:
|
|
|
336
336
|
unpack it into `out`; keeps no zip. A mismatch, or a file outside kiteml_<run_id>/, refuses the whole archive."""
|
|
337
337
|
if not re.fullmatch(r"[A-Za-z0-9_-]+", run_id):
|
|
338
338
|
raise KiteAPIError(400, f"unexpected run id {run_id!r}", code="parameter_invalid")
|
|
339
|
-
expected = str((client.get(f"/v1/rl_runs/{run_id}").get("output") or {}).get("sha256") or "").lower()
|
|
339
|
+
expected = str((client.get(f"/v1/rl_runs/{seg(run_id)}").get("output") or {}).get("sha256") or "").lower()
|
|
340
340
|
out.mkdir(parents=True, exist_ok=True)
|
|
341
341
|
part = out / f"{run_id}.zip.part"
|
|
342
342
|
try:
|
|
343
|
-
client.download(f"/v1/rl_runs/{run_id}/archive", str(part))
|
|
343
|
+
client.download(f"/v1/rl_runs/{seg(run_id)}/archive", str(part))
|
|
344
344
|
if expected and hashlib.sha256(part.read_bytes()).hexdigest() != expected:
|
|
345
345
|
raise KiteAPIError(502, f"{run_id}.zip does not match its sha256; download it again",
|
|
346
346
|
code="archive_invalid")
|
|
@@ -4,11 +4,14 @@ MuJoCo scene out (about 100 minutes per twin).
|
|
|
4
4
|
kite twin validate lerobot/svla_so101_pickplace [--camera side] free: cameras, episodes, time and price
|
|
5
5
|
kite twin validate s3://my-bucket/my_dataset --robot so101 a dataset in a public S3 bucket
|
|
6
6
|
kite twin create lerobot/svla_so101_pickplace --wait --out ./twins -> ./twins/twin_.../scene.xml
|
|
7
|
-
kite twin status twin_01K... [--wait]
|
|
7
|
+
kite twin status twin_01K... [--wait] while it builds, also its rounds, agents, open question and notes
|
|
8
8
|
kite twin list [--limit 20] [--after twin_...]
|
|
9
9
|
kite twin files twin_01K... [--limit 20] [--after PATH] [--all] what the archive holds, once succeeded
|
|
10
10
|
kite twin cancel twin_01K... -> canceling, then canceled once the build has stopped
|
|
11
|
-
kite twin resume twin_01K...
|
|
11
|
+
kite twin resume twin_01K... [--from-round N] --from-round goes back to a kept round, building or not
|
|
12
|
+
kite twin note twin_01K... "It is 2.5 cm, a matte red cube" [--on red_block] read by the agents next step
|
|
13
|
+
kite twin note twin_01K... --delete note_01K...
|
|
14
|
+
kite twin answer twin_01K... "2.5 cm" answers the twin's open question
|
|
12
15
|
kite twin download twin_01K... [--out DIR] [--no-extract]
|
|
13
16
|
|
|
14
17
|
DATASET is a Hugging Face repo id or URL, which the API takes as {"source": {"type": "huggingface", "repo_id": DATASET}},
|
|
@@ -32,7 +35,7 @@ import httpx
|
|
|
32
35
|
import typer
|
|
33
36
|
|
|
34
37
|
from kite_cli.archive import storage_client, unpack, verified
|
|
35
|
-
from kite_cli.client import KiteAPIError, KiteClient, post_create
|
|
38
|
+
from kite_cli.client import KiteAPIError, KiteClient, post_create, seg
|
|
36
39
|
from kite_cli.output import print_error, print_json
|
|
37
40
|
from kite_cli.progress import wait_for_completion
|
|
38
41
|
|
|
@@ -116,10 +119,11 @@ def status(
|
|
|
116
119
|
twin_id: str = typer.Argument(..., help="Twin id (twin_...)"),
|
|
117
120
|
wait: bool = typer.Option(False, "--wait", help="Poll until succeeded | failed | canceled"),
|
|
118
121
|
):
|
|
119
|
-
"""A twin's live status, progress, stage and stage measurements;
|
|
122
|
+
"""A twin's live status, progress, stage and stage measurements; while it builds, its rounds (scores, layer scores,
|
|
123
|
+
issues), agents, open question and notes; `download` once succeeded."""
|
|
120
124
|
try:
|
|
121
125
|
client = KiteClient()
|
|
122
|
-
path = f"/v1/twins/{twin_id}"
|
|
126
|
+
path = f"/v1/twins/{seg(twin_id)}"
|
|
123
127
|
if wait:
|
|
124
128
|
print_json(wait_for_completion(client, path, terminal_states=_TERMINAL, poll_interval=_POLL_S))
|
|
125
129
|
else:
|
|
@@ -151,7 +155,7 @@ def list_files(
|
|
|
151
155
|
all_pages: bool = typer.Option(False, "--all", help="Follow next_cursor through every page; print one list"),
|
|
152
156
|
):
|
|
153
157
|
"""The files in a succeeded twin's archive (path, bytes, sha256), sorted by path; twin_not_ready before that."""
|
|
154
|
-
path = f"/v1/twins/{twin_id}/files"
|
|
158
|
+
path = f"/v1/twins/{seg(twin_id)}/files"
|
|
155
159
|
size = limit if limit is not None else (100 if all_pages else 20)
|
|
156
160
|
try:
|
|
157
161
|
client = KiteClient()
|
|
@@ -176,21 +180,72 @@ def cancel(twin_id: str = typer.Argument(..., help="Twin id (twin_...)")):
|
|
|
176
180
|
"""Stop a queued or processing twin: it reads canceling until the build has stopped, then canceled. The
|
|
177
181
|
stages it finished stay cached for a resume."""
|
|
178
182
|
try:
|
|
179
|
-
print_json(KiteClient().post(f"/v1/twins/{twin_id}/cancel"))
|
|
183
|
+
print_json(KiteClient().post(f"/v1/twins/{seg(twin_id)}/cancel"))
|
|
180
184
|
except KiteAPIError as e:
|
|
181
185
|
print_error(e.message, code=e.code, details=e.details)
|
|
182
186
|
|
|
183
187
|
|
|
184
188
|
@app.command()
|
|
185
|
-
def resume(
|
|
189
|
+
def resume(
|
|
190
|
+
twin_id: str = typer.Argument(..., help="Twin id (twin_...)"),
|
|
191
|
+
from_round: Optional[int] = typer.Option(
|
|
192
|
+
None, "--from-round", min=0, help="Go back to this kept round (rounds[].kept): a failed or canceled twin "
|
|
193
|
+
"resumes from it; a building one starts its next round from it, free"
|
|
194
|
+
),
|
|
195
|
+
):
|
|
186
196
|
"""Re-queue a failed or canceled twin; only the stages that did not finish run again. Free while it's paid for;
|
|
187
|
-
a twin that was refunded is charged 25,000 tokens again."""
|
|
197
|
+
a twin that was refunded is charged 25,000 tokens again. --from-round goes back to a kept round."""
|
|
188
198
|
try:
|
|
189
|
-
print_json(KiteClient().post(f"/v1/twins/{twin_id}/resume"))
|
|
199
|
+
print_json(KiteClient().post(f"/v1/twins/{seg(twin_id)}/resume", json_data=_body(from_round=from_round) or None))
|
|
190
200
|
except KiteAPIError as e:
|
|
191
201
|
print_error(e.message, code=e.code, details=e.details)
|
|
192
202
|
|
|
193
203
|
|
|
204
|
+
@app.command()
|
|
205
|
+
def note(
|
|
206
|
+
twin_id: str = typer.Argument(..., help="Twin id (twin_...)"),
|
|
207
|
+
text: Optional[str] = typer.Argument(None, help="What is wrong, a size, a colour (up to 2,000 characters)"),
|
|
208
|
+
on: Optional[str] = typer.Option(None, "--on", help="What it is about: a layer (registration, objects, table, "
|
|
209
|
+
"room, motion) or a body in the twin's scene; default the whole twin"),
|
|
210
|
+
delete: Optional[str] = typer.Option(None, "--delete", help="Remove this note (note_...) instead"),
|
|
211
|
+
):
|
|
212
|
+
"""Leave a note for the agents building a twin, read at their next step until it is deleted or the twin ends
|
|
213
|
+
(free); or --delete one."""
|
|
214
|
+
try:
|
|
215
|
+
client = KiteClient()
|
|
216
|
+
if delete:
|
|
217
|
+
client.delete(f"/v1/twins/{seg(twin_id)}/notes/{seg(delete)}")
|
|
218
|
+
print_json({"id": delete, "deleted": True})
|
|
219
|
+
elif text:
|
|
220
|
+
print_json(client.post(f"/v1/twins/{seg(twin_id)}/notes", json_data=_body(text=text, on=on)))
|
|
221
|
+
else:
|
|
222
|
+
print_error("give the note's text, or --delete NOTE_ID", code="parameter_invalid")
|
|
223
|
+
except KiteAPIError as e:
|
|
224
|
+
print_error(e.message, code=e.code, details=e.details)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@app.command()
|
|
228
|
+
def answer(
|
|
229
|
+
twin_id: str = typer.Argument(..., help="Twin id (twin_...)"),
|
|
230
|
+
text: str = typer.Argument(..., help="One of the question's options, or your own words (up to 500 characters)"),
|
|
231
|
+
):
|
|
232
|
+
"""Answer the twin's open question (see `status`): the answer becomes a note the agents read at their next step.
|
|
233
|
+
Free."""
|
|
234
|
+
try:
|
|
235
|
+
print_json(answer_question(KiteClient(), twin_id, text))
|
|
236
|
+
except KiteAPIError as e:
|
|
237
|
+
print_error(e.message, code=e.code, details=e.details)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def answer_question(client: KiteClient, twin_id: str, text: str) -> dict:
|
|
241
|
+
"""Answer the question a GET of the twin shows open; question_closed when there is none. Shared with the MCP
|
|
242
|
+
tool kite_twin_answer."""
|
|
243
|
+
question = client.get(f"/v1/twins/{seg(twin_id)}").get("question")
|
|
244
|
+
if not question:
|
|
245
|
+
raise KiteAPIError(409, f"Twin '{twin_id}' has no open question.", code="question_closed")
|
|
246
|
+
return client.post(f"/v1/twins/{seg(twin_id)}/answers", json_data={"question": question["id"], "answer": text})
|
|
247
|
+
|
|
248
|
+
|
|
194
249
|
@app.command()
|
|
195
250
|
def download(
|
|
196
251
|
twin_id: str = typer.Argument(..., help="Twin id (twin_...)"),
|
|
@@ -202,7 +257,7 @@ def download(
|
|
|
202
257
|
"""Download a succeeded twin: <out>/<twin_id>.tar.gz, sha256-verified, unpacked to <out>/<twin_id>/scene.xml."""
|
|
203
258
|
try:
|
|
204
259
|
client = KiteClient(timeout=120)
|
|
205
|
-
print_json(_save(client, client.get(f"/v1/twins/{twin_id}"), _out_dir(out), extract=extract))
|
|
260
|
+
print_json(_save(client, client.get(f"/v1/twins/{seg(twin_id)}"), _out_dir(out), extract=extract))
|
|
206
261
|
except KiteAPIError as e:
|
|
207
262
|
print_error(e.message, code=e.code, details=e.details)
|
|
208
263
|
|
|
@@ -101,5 +101,18 @@ def doctor():
|
|
|
101
101
|
raise typer.Exit(code=1)
|
|
102
102
|
|
|
103
103
|
|
|
104
|
+
def main() -> None:
|
|
105
|
+
"""The `kite` command: the app, with a request that never got an answer (a timeout, no connection, a URL httpx
|
|
106
|
+
refuses) printed as a structured error like the API's own, never a traceback."""
|
|
107
|
+
import httpx
|
|
108
|
+
|
|
109
|
+
from kite_cli.output import print_error
|
|
110
|
+
|
|
111
|
+
try:
|
|
112
|
+
app()
|
|
113
|
+
except (httpx.HTTPError, httpx.InvalidURL) as e:
|
|
114
|
+
print_error(f"{type(e).__name__}: {e}", code="network_error")
|
|
115
|
+
|
|
116
|
+
|
|
104
117
|
if __name__ == "__main__":
|
|
105
|
-
|
|
118
|
+
main()
|
|
@@ -14,10 +14,14 @@ Shared by both CLI commands and the MCP server.
|
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
16
|
import json
|
|
17
|
+
import os
|
|
18
|
+
import socket
|
|
17
19
|
import sys
|
|
18
20
|
import time
|
|
19
21
|
from pathlib import Path
|
|
20
22
|
from typing import Any, BinaryIO, Dict, Optional
|
|
23
|
+
from urllib.parse import quote
|
|
24
|
+
from urllib.request import getproxies
|
|
21
25
|
|
|
22
26
|
import httpx
|
|
23
27
|
|
|
@@ -32,6 +36,24 @@ API_VERSION = "2026-10-12"
|
|
|
32
36
|
VERSION_HEADER = "Kite-Version"
|
|
33
37
|
|
|
34
38
|
|
|
39
|
+
# TCP keepalive every 2 s on the API connection: a network that drops a connection idle for a few seconds would
|
|
40
|
+
# otherwise lose the answer to a call the API takes ~10 s over (`kite rl plan`). TCP_KEEPIDLE is Linux's (and
|
|
41
|
+
# Windows') name for the idle time, TCP_KEEPALIVE macOS's; each option is set only where the platform has it.
|
|
42
|
+
_KEEPALIVE = [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)] + [
|
|
43
|
+
(socket.IPPROTO_TCP, getattr(socket, name), 2)
|
|
44
|
+
for name in ("TCP_KEEPIDLE", "TCP_KEEPALIVE", "TCP_KEEPINTVL") if hasattr(socket, name)]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def seg(value: Any) -> str:
|
|
48
|
+
"""A caller's value (a run id, a twin id) as one URL path segment, percent-encoded, so it can't leave its
|
|
49
|
+
resource (`../credits`), add a segment (`x/resume`) or end the path early (`?`, `#`). `.` and `..` alone are
|
|
50
|
+
refused: no encoding stops a URL from resolving them."""
|
|
51
|
+
s = quote(str(value), safe="")
|
|
52
|
+
if s in ("", ".", ".."):
|
|
53
|
+
raise KiteAPIError(400, f"{value!r} is not an id", code="parameter_invalid")
|
|
54
|
+
return s
|
|
55
|
+
|
|
56
|
+
|
|
35
57
|
def user_agent(surface: str = "kite-cli") -> str:
|
|
36
58
|
"""The User-Agent every request sends: `kite-cli/<version>`, or `kite-mcp/<version>` from the MCP server. The
|
|
37
59
|
API's request log and run attribution read the surface from this prefix."""
|
|
@@ -88,10 +110,13 @@ class KiteClient:
|
|
|
88
110
|
self.base_url = (api_url or get_api_url()).rstrip("/")
|
|
89
111
|
self._token_override = token
|
|
90
112
|
self._user_agent = user_agent(surface)
|
|
113
|
+
# httpx ignores the proxy settings once it is given a transport, so behind a proxy it keeps its own.
|
|
114
|
+
proxied = getproxies().keys() & {"http", "https", "all"}
|
|
91
115
|
self._client = httpx.Client(
|
|
92
116
|
base_url=self.base_url,
|
|
93
117
|
timeout=timeout,
|
|
94
118
|
follow_redirects=True,
|
|
119
|
+
transport=None if proxied else httpx.HTTPTransport(socket_options=_KEEPALIVE),
|
|
95
120
|
)
|
|
96
121
|
|
|
97
122
|
def _base_headers(self) -> Dict[str, str]:
|
|
@@ -106,10 +131,21 @@ class KiteClient:
|
|
|
106
131
|
def _headers(self) -> Dict[str, str]:
|
|
107
132
|
return {"Content-Type": "application/json", **self._base_headers()}
|
|
108
133
|
|
|
134
|
+
def _error(self, resp: httpx.Response) -> KiteAPIError:
|
|
135
|
+
"""The response's error. A key missing a scope that is the KITE_API_KEY set in the environment says so: it is
|
|
136
|
+
used ahead of `kite auth login`'s key, so a stale one there is easy to miss."""
|
|
137
|
+
e = _api_error(resp)
|
|
138
|
+
env_key = os.environ.get("KITE_API_KEY")
|
|
139
|
+
if e.code == "missing_scope" and env_key and env_key == (self._token_override or get_token()):
|
|
140
|
+
e = KiteAPIError(e.status_code, f"{e.message} (the key is KITE_API_KEY from the environment, used instead "
|
|
141
|
+
"of your `kite auth login` key: unset it or give it the scope)",
|
|
142
|
+
code=e.code, details=e.details, param=e.param, request_id=e.request_id)
|
|
143
|
+
return e
|
|
144
|
+
|
|
109
145
|
def _handle_response(self, resp: httpx.Response) -> dict:
|
|
110
146
|
"""Parse response, raise KiteAPIError on non-2xx."""
|
|
111
147
|
if resp.status_code >= 400:
|
|
112
|
-
raise
|
|
148
|
+
raise self._error(resp)
|
|
113
149
|
|
|
114
150
|
if resp.status_code == 204:
|
|
115
151
|
return {"ok": True}
|
|
@@ -155,7 +191,7 @@ class KiteClient:
|
|
|
155
191
|
with self._client.stream("GET", path, headers=headers) as resp:
|
|
156
192
|
if resp.status_code >= 400:
|
|
157
193
|
resp.read()
|
|
158
|
-
raise
|
|
194
|
+
raise self._error(resp)
|
|
159
195
|
resp.raise_for_status()
|
|
160
196
|
with open(output_path, "wb") as f:
|
|
161
197
|
for chunk in resp.iter_bytes(chunk_size=8192):
|
|
@@ -169,7 +205,7 @@ class KiteClient:
|
|
|
169
205
|
return resp.headers.get("location")
|
|
170
206
|
if resp.status_code >= 400:
|
|
171
207
|
resp.read()
|
|
172
|
-
raise
|
|
208
|
+
raise self._error(resp)
|
|
173
209
|
return None
|
|
174
210
|
|
|
175
211
|
def close(self) -> None:
|
|
@@ -18,5 +18,8 @@ def ok(data: Any) -> list[TextContent]:
|
|
|
18
18
|
return [TextContent(type="text", text=json.dumps({"ok": True, "data": data}, default=str, indent=2))]
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def err(message: str) -> list[TextContent]:
|
|
22
|
-
|
|
21
|
+
def err(message: str, **fields: Any) -> list[TextContent]:
|
|
22
|
+
"""`{"ok": false, "error": message}` plus whichever of `fields` are set: an API error's `code`, `status` and
|
|
23
|
+
`details`, the same fields the CLI prints, so an agent can act on the code instead of parsing the message."""
|
|
24
|
+
extra = {k: v for k, v in fields.items() if v}
|
|
25
|
+
return [TextContent(type="text", text=json.dumps({"ok": False, "error": message, **extra}, default=str))]
|
|
@@ -18,6 +18,7 @@ import json
|
|
|
18
18
|
import logging
|
|
19
19
|
import os
|
|
20
20
|
import sys
|
|
21
|
+
import uuid
|
|
21
22
|
|
|
22
23
|
try:
|
|
23
24
|
from mcp.server import Server
|
|
@@ -27,7 +28,8 @@ except ModuleNotFoundError as e: # `pip install kiteml-cli` without the extra i
|
|
|
27
28
|
raise ModuleNotFoundError('kite-mcp needs the MCP extra: pip install "kiteml-cli[mcp]"', name=e.name) from e
|
|
28
29
|
|
|
29
30
|
from kite_cli import __version__
|
|
30
|
-
from kite_cli.client import KiteClient, KiteAPIError
|
|
31
|
+
from kite_cli.client import KiteClient, KiteAPIError, post_create, seg
|
|
32
|
+
from kite_cli.config import get_app_url
|
|
31
33
|
from kite_cli.mcp.common import DESTRUCTIVE, READ, WRITE, err as _err, ok as _ok
|
|
32
34
|
|
|
33
35
|
logger = logging.getLogger(__name__)
|
|
@@ -40,7 +42,7 @@ _request_token: contextvars.ContextVar[str | None] = contextvars.ContextVar(
|
|
|
40
42
|
)
|
|
41
43
|
|
|
42
44
|
|
|
43
|
-
def _client() -> KiteClient:
|
|
45
|
+
def _client(timeout: float = 30.0) -> KiteClient:
|
|
44
46
|
"""Create a KiteClient. In HTTP mode, uses the per-request token from the
|
|
45
47
|
Authorization header. In stdio mode, falls back to env vars."""
|
|
46
48
|
token = (
|
|
@@ -48,7 +50,7 @@ def _client() -> KiteClient:
|
|
|
48
50
|
or os.environ.get("KITE_API_KEY")
|
|
49
51
|
or os.environ.get("KITE_TOKEN")
|
|
50
52
|
)
|
|
51
|
-
return KiteClient(api_url=os.environ.get("KITE_API_URL"), token=token, surface="kite-mcp")
|
|
53
|
+
return KiteClient(api_url=os.environ.get("KITE_API_URL"), token=token, timeout=timeout, surface="kite-mcp")
|
|
52
54
|
|
|
53
55
|
|
|
54
56
|
def _fetch_command(d: dict, fname: str, client: KiteClient) -> str:
|
|
@@ -82,9 +84,12 @@ def _twin_view(twin: dict, client: KiteClient) -> dict:
|
|
|
82
84
|
+ (f" (link valid until {d['expires_at']}; call kite_twin_status again for a fresh one)"
|
|
83
85
|
if d.get("expires_at") else ""))
|
|
84
86
|
elif status in ("queued", "processing"):
|
|
85
|
-
eta = twin.get("eta_seconds")
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
eta, q = twin.get("eta_seconds"), twin.get("question")
|
|
88
|
+
wait = ("call kite_twin_status again in a few minutes"
|
|
89
|
+
+ (f" (stage {twin['stage']}, about {max(1, eta // 60)} min left)" if eta and twin.get("stage") else ""))
|
|
90
|
+
out["next"] = (f'kite_twin_answer {tid} answers the agents\' open question "{q.get("text")}"'
|
|
91
|
+
+ (f" (options: {', '.join(q['options'])})" if q.get("options") else "")
|
|
92
|
+
+ f'; until then the build carries on with "{q.get("default")}". Then {wait}') if q else wait
|
|
88
93
|
elif status == "canceling":
|
|
89
94
|
out["next"] = ("call kite_twin_status again in a few seconds: the cancel was accepted and the build is "
|
|
90
95
|
"stopping; it then reads canceled")
|
|
@@ -137,8 +142,8 @@ def _eval_request(args: dict, client: KiteClient) -> tuple[dict, dict | None]:
|
|
|
137
142
|
|
|
138
143
|
from kite_cli.cli.commands.evaluations import remote_refs, request
|
|
139
144
|
|
|
140
|
-
pairs = {m: [f"{k}={v}" for k, v in (args.get(m) or {}).items()] for m in ("hf", "s3", "training_runs")}
|
|
141
|
-
remote = remote_refs(pairs["hf"], pairs["s3"], pairs["training_runs"])
|
|
145
|
+
pairs = {m: [f"{k}={v}" for k, v in (args.get(m) or {}).items()] for m in ("hf", "s3", "training_runs", "twins")}
|
|
146
|
+
remote = remote_refs(pairs["hf"], pairs["s3"], pairs["training_runs"], pairs["twins"])
|
|
142
147
|
body, validation, _ = request(client, Path(args["spec"]), args.get("overrides") or [], remote, args.get("kite_version"))
|
|
143
148
|
return body, validation
|
|
144
149
|
|
|
@@ -148,6 +153,8 @@ def _rl_view(run: dict, client: KiteClient) -> dict:
|
|
|
148
153
|
cannot write to the agent's disk, so a packaged run's `next` is the exact command that fetches its bundle."""
|
|
149
154
|
out = dict(run)
|
|
150
155
|
status, rid = run.get("status"), run.get("id")
|
|
156
|
+
charged = int((run.get("tokens") or {}).get("charged") or 0)
|
|
157
|
+
cost = f"it was charged {charged:,} tokens" if charged else "nothing was charged"
|
|
151
158
|
if run.get("output"): # packaged: succeeded, or canceled after it trained
|
|
152
159
|
url = f"{client.base_url.rstrip('/')}{run['output']['archive_url']}"
|
|
153
160
|
top = f"kiteml_{rid}"
|
|
@@ -160,11 +167,24 @@ def _rl_view(run: dict, client: KiteClient) -> dict:
|
|
|
160
167
|
elif status == "canceling":
|
|
161
168
|
out["next"] = ("the cancel was accepted: the run stops, keeps the policy it has and is packaged, then reads "
|
|
162
169
|
"canceled; call kite_rl_status again in a few minutes")
|
|
170
|
+
elif run.get("studio_run_id"): # made in RL Studio, which keeps its policy, report and checkpoints
|
|
171
|
+
sid, trained = run["studio_run_id"], int((run.get("metrics") or {}).get("iteration") or 0)
|
|
172
|
+
studio = f"open {get_app_url().rstrip('/')}/rl-studio?run={sid}"
|
|
173
|
+
if status == "succeeded":
|
|
174
|
+
clip = f"{client.base_url.rstrip('/')}/v1/rl_runs/{rid}/files/media/video.mp4"
|
|
175
|
+
out["next"] = (f"made in RL Studio, which keeps its policy, report and publishing: {studio}. Its clip: "
|
|
176
|
+
f'curl -fL -H "Authorization: Bearer $KITE_API_KEY" "{clip}" -o {rid}.mp4')
|
|
177
|
+
elif trained or charged:
|
|
178
|
+
out["next"] = (f"{status} at iteration {trained} in RL Studio, which keeps any policy it saved: {studio}; "
|
|
179
|
+
f"{cost}" + ("; read `error`" if status == "failed" else ""))
|
|
180
|
+
else:
|
|
181
|
+
out["next"] = f"{status} before it trained, so there is nothing to download and {cost}"
|
|
163
182
|
elif status == "failed":
|
|
164
|
-
out["next"] = "read `error
|
|
183
|
+
out["next"] = (f"read `error` ({cost}), then start a new run with kite_rl_train (or kite_rl_fork from a run "
|
|
184
|
+
"that trained)")
|
|
165
185
|
elif status == "canceled":
|
|
166
|
-
out["next"] = ("it was canceled before it saved a policy, so there is nothing to download and
|
|
167
|
-
"
|
|
186
|
+
out["next"] = (f"it was canceled before it saved a policy, so there is nothing to download and {cost}; start "
|
|
187
|
+
"a new run with kite_rl_train")
|
|
168
188
|
return out
|
|
169
189
|
|
|
170
190
|
|
|
@@ -187,7 +207,7 @@ _RL_SPEC = {
|
|
|
187
207
|
"kite_rl_plan writes one"},
|
|
188
208
|
"budget": {"type": "object", "description": "{preset: probe | standard, iterations?, num_envs?, max_tokens?}; "
|
|
189
209
|
"probe is 300 iterations, a first signal in minutes. Optional"},
|
|
190
|
-
"seeds": {"type": "integer", "description": "Runs to start, one per seed (1-
|
|
210
|
+
"seeds": {"type": "integer", "description": "Runs to start, one per seed (1-4, default 1). Optional"},
|
|
191
211
|
"from": {"type": "object", "description": "Start from a trained policy instead of from scratch: {run: rlr_..., "
|
|
192
212
|
"mode: fork | continue} or {policy: <public policy id>}. Optional"},
|
|
193
213
|
"description": {"type": "string", "description": "What the behavior should look like; the report compares the "
|
|
@@ -199,11 +219,12 @@ _EVAL_SPEC = {
|
|
|
199
219
|
"spec": {"type": "string", "description": "A Kite SDK spec file on this machine, best as an absolute path (the local server only): every path it names is sent from this disk, a file Kite ships by its hash alone"},
|
|
200
220
|
"spec_yaml": {"type": "string", "description": "The spec's text, instead of `spec` (the hosted server): send `spec_path` and `files` with it"},
|
|
201
221
|
"spec_path": {"type": "string", "description": "With spec_yaml: its path in your workspace, e.g. specs/smoke.yaml. Paths in the spec are read relative to it"},
|
|
202
|
-
"files": {"type": "object", "description": "With spec_yaml: each path the spec names, as it names it, to where its bytes come from: {\"kind\": \"directory\", \"shipped\": \"evals\"} (a path Kite ships), {\"sha256\", \"kind\"} (a shipped file by hash), {\"text\"} or {\"base64\"} (a folder as a .tar), or {\"hf\": {\"repo\", \"revision\" (a full commit), \"path\"}} or {\"hf\": \"<the file's huggingface.co URL>\"} (a branch is pinned to its commit), or {\"s3\": \"s3://BUCKET/KEY\"} (an object in a public bucket, pinned to its ETag), or {\"training_run\": \"trn_...\", \"step\"} (a folder: the pretrained_model/ of one of your training runs' checkpoints, step left out for its latest; nothing is published). A missing one is files_required, listing each"},
|
|
222
|
+
"files": {"type": "object", "description": "With spec_yaml: each path the spec names, as it names it, to where its bytes come from: {\"kind\": \"directory\", \"shipped\": \"evals\"} (a path Kite ships), {\"sha256\", \"kind\"} (a shipped file by hash), {\"text\"} or {\"base64\"} (a folder as a .tar), or {\"hf\": {\"repo\", \"revision\" (a full commit), \"path\"}} or {\"hf\": \"<the file's huggingface.co URL>\"} (a branch is pinned to its commit), or {\"s3\": \"s3://BUCKET/KEY\"} (an object in a public bucket, pinned to its ETag), or {\"training_run\": \"trn_...\", \"step\"} (a folder: the pretrained_model/ of one of your training runs' checkpoints, step left out for its latest; nothing is published), or {\"twin\": \"twin_...\"} (a folder: what one of your succeeded twins unpacks to, scene.xml and assets/; a file sent under a path inside it replaces the twin's own). A missing one is files_required, listing each"},
|
|
203
223
|
"overrides": {"type": "array", "items": {"type": "string"}, "description": "FIELD=VALUE pairs, as `kite run --set`, e.g. episodes.count=20. Optional"},
|
|
204
224
|
"hf": {"type": "object", "description": "With spec: {PATH: \"OWNER/NAME@COMMIT:FILE\" or the file's huggingface.co URL}, the paths that are a public Hugging Face file (a checkpoint's weights). Optional"},
|
|
205
225
|
"s3": {"type": "object", "description": "With spec: {PATH: \"s3://BUCKET/KEY\"}, the paths that are an object in a public S3 bucket. Optional"},
|
|
206
226
|
"training_runs": {"type": "object", "description": "With spec: {PATH: \"trn_...\" or \"trn_...@STEP\"}, the folders (policy.asset_dir) that are the pretrained_model/ of one of your training runs' checkpoints, its latest without @STEP; read from Kite's storage, nothing is published. Optional"},
|
|
227
|
+
"twins": {"type": "object", "description": "With spec: {PATH: \"twin_...\"}, the folders that are one of your succeeded twins (its scene.xml and assets/), read from Kite's storage; a file in PATH on this machine that the twin does not have as it is goes inline beside it. Optional"},
|
|
207
228
|
"kite_version": {"type": "string", "description": "The Kite release you expect; refused if it is not the one served. Optional"},
|
|
208
229
|
}
|
|
209
230
|
_EVAL_ID = {"run_id": {"type": "string", "description": "Evaluation id (eval_...)"}}
|
|
@@ -282,7 +303,7 @@ TOOLS = [
|
|
|
282
303
|
"idempotency_key": {"type": "string", "description": "Reuse the same key when retrying, so a retry never builds twice. Optional"}},
|
|
283
304
|
"required": ["dataset", "robot"]}, annotations=_WRITE),
|
|
284
305
|
Tool(name="kite_twin_status", title="Get Digital Twin Status",
|
|
285
|
-
description="Get a twin's status (queued/processing/canceling/succeeded/failed/canceled), stage, progress, each finished stage's measurement, and a `next` instruction. canceling means a cancel was accepted but the build has not stopped yet; it becomes canceled. When succeeded, `download.url` is a direct link to the whole scene as one .tar.gz and `next` is the exact command to fetch and extract it (the folder contains scene.xml for MuJoCo).",
|
|
306
|
+
description="Get a twin's status (queued/processing/canceling/succeeded/failed/canceled), stage, progress, each finished stage's measurement, and a `next` instruction. canceling means a cancel was accepted but the build has not stopped yet; it becomes canceled. While it builds: `rounds` (each judged round's score against target_score, its layer scores, summary and issues; `best_round` becomes the download), `agents` (what each is doing), `question` (an agent's open question, which `next` names: answer it with kite_twin_answer) and `notes` (yours, queued or read). When succeeded, `download.url` is a direct link to the whole scene as one .tar.gz and `next` is the exact command to fetch and extract it (the folder contains scene.xml for MuJoCo).",
|
|
286
307
|
inputSchema={"type": "object", "properties": {
|
|
287
308
|
"twin_id": {"type": "string", "description": "Twin id (twin_...) from kite_twin_create"}},
|
|
288
309
|
"required": ["twin_id"]}, annotations=_READ),
|
|
@@ -296,10 +317,25 @@ TOOLS = [
|
|
|
296
317
|
"twin_id": {"type": "string", "description": "Twin id (twin_...)"}},
|
|
297
318
|
"required": ["twin_id"]}, annotations=_DESTRUCTIVE),
|
|
298
319
|
Tool(name="kite_twin_resume", title="Resume Digital Twin",
|
|
299
|
-
description="Re-queue a failed or canceled twin. Every stage it finished is cached, so only what did not finish runs again. Free while the twin is paid for; one that was refunded (it ended before authoring) is charged 25,000 tokens again.",
|
|
320
|
+
description="Re-queue a failed or canceled twin. Every stage it finished is cached, so only what did not finish runs again. Free while the twin is paid for; one that was refunded (it ended before authoring) is charged 25,000 tokens again. With from_round, go back to a kept round (rounds[].kept, else round_not_kept): a failed or canceled twin resumes from that round's snapshot, and a building twin starts its next round from it once the current round finishes, free.",
|
|
300
321
|
inputSchema={"type": "object", "properties": {
|
|
301
|
-
"twin_id": {"type": "string", "description": "Twin id (twin_...)"}
|
|
322
|
+
"twin_id": {"type": "string", "description": "Twin id (twin_...)"},
|
|
323
|
+
"from_round": {"type": "integer", "minimum": 0, "description": "A kept round to go back to (kite_twin_status lists rounds). Optional"}},
|
|
324
|
+
"required": ["twin_id"]}, annotations=_WRITE),
|
|
325
|
+
Tool(name="kite_twin_note", title="Leave a Note for a Digital Twin's Agents",
|
|
326
|
+
description="Leave a note for the agents building a twin: what is wrong, a size, a colour, about one thing in the scene (`on`) or the whole twin. Every agent step reads it until it is deleted or the twin ends; it reads queued, then read with read_in_round, and the next round's scores and issues show whether it helped. With `delete` (a note id), removes that note instead. Free; twin_not_building once the twin has ended, too_many_notes past 20 active notes.",
|
|
327
|
+
inputSchema={"type": "object", "properties": {
|
|
328
|
+
"twin_id": {"type": "string", "description": "Twin id (twin_...)"},
|
|
329
|
+
"text": {"type": "string", "description": "The note, up to 2,000 characters (not with delete)"},
|
|
330
|
+
"on": {"type": "string", "description": "What it is about: a layer (registration, objects, table, room, motion) or a body name from the twin's scene (as rounds[].issues[].object names them). Optional: the whole twin"},
|
|
331
|
+
"delete": {"type": "string", "description": "A note id (note_...) to remove instead. Optional"}},
|
|
302
332
|
"required": ["twin_id"]}, annotations=_WRITE),
|
|
333
|
+
Tool(name="kite_twin_answer", title="Answer a Digital Twin's Question",
|
|
334
|
+
description="Answer the open question an agent building a twin asked (kite_twin_status shows it as `question`, with its options and the default the build carries on with meanwhile). The answer becomes a note the agents read at their next step; returns that note. Free; question_closed when no question is open.",
|
|
335
|
+
inputSchema={"type": "object", "properties": {
|
|
336
|
+
"twin_id": {"type": "string", "description": "Twin id (twin_...)"},
|
|
337
|
+
"answer": {"type": "string", "description": "One of the question's options, or your own words (up to 500 characters)"}},
|
|
338
|
+
"required": ["twin_id", "answer"]}, annotations=_WRITE),
|
|
303
339
|
|
|
304
340
|
# Evaluations (public /v1 API): a Kite SDK spec on Kite's machines -> a scorecard and a verifiable run directory
|
|
305
341
|
Tool(name="kite_eval_validate", title="Validate Evaluation",
|
|
@@ -362,6 +398,7 @@ TOOLS = [
|
|
|
362
398
|
description="List your RL training runs, newest first, with their last known status (kite_rl_status has live progress).",
|
|
363
399
|
inputSchema={"type": "object", "properties": {
|
|
364
400
|
"limit": {"type": "integer", "description": "Max rows (1-100, default 20)"},
|
|
401
|
+
"after": {"type": "string", "description": "The previous page's next_cursor, for the page after it. Optional"},
|
|
365
402
|
"group_id": {"type": "string", "description": "Only the runs one kite_rl_train started (rlg_...). Optional"}}},
|
|
366
403
|
annotations=_READ),
|
|
367
404
|
Tool(name="kite_rl_status", title="Get RL Run Status",
|
|
@@ -408,11 +445,15 @@ async def list_tools() -> list[Tool]:
|
|
|
408
445
|
|
|
409
446
|
@server.call_tool()
|
|
410
447
|
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
|
|
448
|
+
from kite_cli.cli.commands.rl import _SLOW_S
|
|
449
|
+
|
|
411
450
|
try:
|
|
412
|
-
|
|
451
|
+
# The RL calls the CLI gives three minutes: plan asks a model, validate rolls policies, create starts jobs.
|
|
452
|
+
client = _client(_SLOW_S if name in ("kite_rl_plan", "kite_rl_validate", "kite_rl_train", "kite_rl_fork")
|
|
453
|
+
else 30.0)
|
|
413
454
|
return await _dispatch(name, arguments, client)
|
|
414
455
|
except KiteAPIError as e:
|
|
415
|
-
return _err(
|
|
456
|
+
return _err(e.message, code=e.code, status=e.status_code, details=e.details)
|
|
416
457
|
except Exception as e:
|
|
417
458
|
return _err(str(e))
|
|
418
459
|
|
|
@@ -459,14 +500,14 @@ async def _dispatch(name: str, args: dict, client: KiteClient) -> list[TextConte
|
|
|
459
500
|
]
|
|
460
501
|
return _ok(client.post("/v1/augmentations", json_data=body))
|
|
461
502
|
if name == "kite_augment_status":
|
|
462
|
-
return _ok(client.get(f"/v1/augmentations/{args['aug_id']}"))
|
|
503
|
+
return _ok(client.get(f"/v1/augmentations/{seg(args['aug_id'])}"))
|
|
463
504
|
if name == "kite_augment_list":
|
|
464
505
|
return _ok(client.get("/v1/augmentations", params={"limit": args.get("limit", 20)}))
|
|
465
506
|
if name == "kite_augment_cancel":
|
|
466
|
-
return _ok(client.post(f"/v1/augmentations/{args['aug_id']}/cancel"))
|
|
507
|
+
return _ok(client.post(f"/v1/augmentations/{seg(args['aug_id'])}/cancel"))
|
|
467
508
|
|
|
468
509
|
# --- Digital twins (public /v1 API) ---
|
|
469
|
-
from kite_cli.cli.commands.twin import twin_source
|
|
510
|
+
from kite_cli.cli.commands.twin import answer_question, twin_source
|
|
470
511
|
|
|
471
512
|
if name == "kite_twin_validate":
|
|
472
513
|
body = {"source": twin_source(args["dataset"]), **{k: args[k] for k in ("camera", "robot") if args.get(k)}}
|
|
@@ -477,13 +518,24 @@ async def _dispatch(name: str, args: dict, client: KiteClient) -> list[TextConte
|
|
|
477
518
|
headers = {"Idempotency-Key": args["idempotency_key"]} if args.get("idempotency_key") else None
|
|
478
519
|
return _ok(_twin_view(client.post("/v1/twins", json_data=body, extra_headers=headers), client))
|
|
479
520
|
if name == "kite_twin_status":
|
|
480
|
-
return _ok(_twin_view(client.get(f"/v1/twins/{args['twin_id']}"), client))
|
|
521
|
+
return _ok(_twin_view(client.get(f"/v1/twins/{seg(args['twin_id'])}"), client))
|
|
481
522
|
if name == "kite_twin_list":
|
|
482
523
|
return _ok(client.get("/v1/twins", params={"limit": args.get("limit", 20)}))
|
|
483
524
|
if name == "kite_twin_cancel":
|
|
484
|
-
return _ok(_twin_view(client.post(f"/v1/twins/{args['twin_id']}/cancel"), client))
|
|
525
|
+
return _ok(_twin_view(client.post(f"/v1/twins/{seg(args['twin_id'])}/cancel"), client))
|
|
485
526
|
if name == "kite_twin_resume":
|
|
486
|
-
|
|
527
|
+
body = {"from_round": args["from_round"]} if args.get("from_round") is not None else None
|
|
528
|
+
return _ok(_twin_view(client.post(f"/v1/twins/{seg(args['twin_id'])}/resume", json_data=body), client))
|
|
529
|
+
if name == "kite_twin_note":
|
|
530
|
+
notes = f"/v1/twins/{seg(args['twin_id'])}/notes"
|
|
531
|
+
if args.get("delete"):
|
|
532
|
+
client.delete(f"{notes}/{seg(args['delete'])}")
|
|
533
|
+
return _ok({"id": args["delete"], "deleted": True})
|
|
534
|
+
if not args.get("text"):
|
|
535
|
+
return _err("pass `text`, or `delete` with a note id")
|
|
536
|
+
return _ok(client.post(notes, json_data={k: args[k] for k in ("text", "on") if args.get(k)}))
|
|
537
|
+
if name == "kite_twin_answer":
|
|
538
|
+
return _ok(answer_question(client, args["twin_id"], args["answer"]))
|
|
487
539
|
|
|
488
540
|
# --- Evaluations (public /v1 API) ---
|
|
489
541
|
if name in ("kite_eval_validate", "kite_eval_run"):
|
|
@@ -500,17 +552,17 @@ async def _dispatch(name: str, args: dict, client: KiteClient) -> list[TextConte
|
|
|
500
552
|
headers = {"Idempotency-Key": args["idempotency_key"]} if args.get("idempotency_key") else None
|
|
501
553
|
return _ok(_eval_view(client.post("/v1/evaluations", json_data=body, extra_headers=headers), client))
|
|
502
554
|
if name == "kite_eval_status":
|
|
503
|
-
return _ok(_eval_view(client.get(f"/v1/evaluations/{args['run_id']}"), client))
|
|
555
|
+
return _ok(_eval_view(client.get(f"/v1/evaluations/{seg(args['run_id'])}"), client))
|
|
504
556
|
if name == "kite_eval_list":
|
|
505
557
|
return _ok(client.get("/v1/evaluations", params={"limit": args.get("limit", 20)}))
|
|
506
558
|
if name == "kite_eval_report":
|
|
507
|
-
return _ok(client.get(f"/v1/evaluations/{args['run_id']}/report"))
|
|
559
|
+
return _ok(client.get(f"/v1/evaluations/{seg(args['run_id'])}/report"))
|
|
508
560
|
if name == "kite_eval_logs":
|
|
509
|
-
return _ok(client.get(f"/v1/evaluations/{args['run_id']}/logs", params={"tail": args.get("tail", 200)}))
|
|
561
|
+
return _ok(client.get(f"/v1/evaluations/{seg(args['run_id'])}/logs", params={"tail": args.get("tail", 200)}))
|
|
510
562
|
if name == "kite_eval_cancel":
|
|
511
|
-
return _ok(_eval_view(client.post(f"/v1/evaluations/{args['run_id']}/cancel"), client))
|
|
563
|
+
return _ok(_eval_view(client.post(f"/v1/evaluations/{seg(args['run_id'])}/cancel"), client))
|
|
512
564
|
if name == "kite_eval_resume":
|
|
513
|
-
return _ok(_eval_view(client.post(f"/v1/evaluations/{args['run_id']}/resume"), client))
|
|
565
|
+
return _ok(_eval_view(client.post(f"/v1/evaluations/{seg(args['run_id'])}/resume"), client))
|
|
514
566
|
|
|
515
567
|
# --- RL runs (public /v1 API) ---
|
|
516
568
|
if name == "kite_rl_catalog":
|
|
@@ -519,31 +571,32 @@ async def _dispatch(name: str, args: dict, client: KiteClient) -> list[TextConte
|
|
|
519
571
|
return _ok(client.post("/v1/rl_runs/plan", json_data=args))
|
|
520
572
|
if name == "kite_rl_validate":
|
|
521
573
|
return _ok(client.post("/v1/rl_runs/validate", json_data=args))
|
|
522
|
-
if name
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
574
|
+
if name in ("kite_rl_train", "kite_rl_fork"):
|
|
575
|
+
# As `kite rl train`: a key of its own when the agent sends none, and a lost answer retried with it, so a
|
|
576
|
+
# retry never trains twice.
|
|
577
|
+
if name == "kite_rl_train":
|
|
578
|
+
body = {k: v for k, v in args.items() if k != "idempotency_key"}
|
|
579
|
+
else:
|
|
580
|
+
from kite_cli.cli.commands.rl import from_run
|
|
581
|
+
|
|
582
|
+
body = from_run(client.get(f"/v1/rl_runs/{seg(args['run_id'])}"), "fork", params=args.get("params"))
|
|
583
|
+
if args.get("seeds"):
|
|
584
|
+
body["seeds"] = args["seeds"]
|
|
585
|
+
key = args.get("idempotency_key") or str(uuid.uuid4())
|
|
586
|
+
return _ok(_rl_runs(post_create(client, "/v1/rl_runs", body, key), client))
|
|
534
587
|
if name == "kite_rl_list":
|
|
535
|
-
params = {"limit": args.get("limit", 20), **
|
|
588
|
+
params = {"limit": args.get("limit", 20), **{k: args[k] for k in ("after", "group_id") if args.get(k)}}
|
|
536
589
|
return _ok(client.get("/v1/rl_runs", params=params))
|
|
537
590
|
if name == "kite_rl_status":
|
|
538
|
-
return _ok(_rl_view(client.get(f"/v1/rl_runs/{args['run_id']}"), client))
|
|
591
|
+
return _ok(_rl_view(client.get(f"/v1/rl_runs/{seg(args['run_id'])}"), client))
|
|
539
592
|
if name == "kite_rl_report":
|
|
540
|
-
return _ok(client.get(f"/v1/rl_runs/{args['run_id']}/report"))
|
|
593
|
+
return _ok(client.get(f"/v1/rl_runs/{seg(args['run_id'])}/report"))
|
|
541
594
|
if name == "kite_rl_metrics":
|
|
542
|
-
rows = client.get(f"/v1/rl_runs/{args['run_id']}/metrics").get("data") or []
|
|
595
|
+
rows = client.get(f"/v1/rl_runs/{seg(args['run_id'])}/metrics").get("data") or []
|
|
543
596
|
step = max(1, (len(rows) + 49) // 50) # at most 50 points, counted back from the latest
|
|
544
597
|
return _ok(rows[::-1][::step][::-1])
|
|
545
598
|
if name == "kite_rl_cancel":
|
|
546
|
-
return _ok(_rl_view(client.post(f"/v1/rl_runs/{args['run_id']}/cancel"), client))
|
|
599
|
+
return _ok(_rl_view(client.post(f"/v1/rl_runs/{seg(args['run_id'])}/cancel"), client))
|
|
547
600
|
|
|
548
601
|
# --- Doctor ---
|
|
549
602
|
if name == "kite_doctor":
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|