Skip to content

Export a run

View as Markdown

Studio exports a whole recorded run as one download: GET /api/runs/{id}/export?format=json|jsonl|otlp|wefttest. json is one document, jsonl the same records one per line, otlp the run’s records and spans as OTLP/JSON that another Studio re-ingests, and wefttest a zip of replay fixtures. Add &tree=1 to export every subagent run under it too. On a run’s page the header’s export verbs download the first three; save as test downloads the fourth. From a terminal, weft export <run id> writes the export to stdout.

Terminal window
weft export c17b44940f21af67c33a6b68daa3c40d --format jsonl | jq -r .record | uniq -c
1 run
8 event
4 messages
2 request
1 tools
4 span

weft export talks to --url, else $WEFT_STUDIO_URL, else the Studio the discovery file of a running weft studio or weft dev names, else http://127.0.0.1:7331, with --token, else $WEFT_STUDIO_TOKEN, else the discovery file’s token when that file names the same Studio. An export is data: it reads Studio’s database and never writes or runs your agent.

The run header shows export with json, jsonl and otlp (json and jsonl only for a read-scoped panel token), and, on a run with child runs, a with child runs checkbox that adds &tree=1. Each button fetches the export with the bearer in the Authorization header, never a token in a URL, and saves it under the server’s file name. A toast says saved <file>, or export refused: <reason>. save as test beside them downloads the wefttest zip (Turn a Studio run into a test). Without the export capability the verbs are not drawn.

copy as curl (0.20.0) opens one button per format; each copies a command that downloads that export, &tree=1 included when the checkbox is on. Where Studio requires a token the command carries -H "Authorization: Bearer $WEFT_STUDIO_TOKEN", naming the variable, never the token. The toast says copied a curl command, or the browser refused the clipboard.

Terminal window
curl -fsSL -OJ -H "Authorization: Bearer $WEFT_STUDIO_TOKEN" 'http://127.0.0.1:7331/api/runs/<run>/export?format=jsonl'
formatFileContent-TypeHolds
json<run>.jsonapplication/json; charset=utf-8One weft.run.export/1 document: run (as /api/runs/{id} serves it), events (with gaps), transcript (the messages batches), compactions, requests (the request records, plus the prompts and catalogs they name, keyed by hash), spans and holes
jsonl<run>.jsonlapplication/x-ndjsonThe same records, one {"record": <kind>, …} per line, in a stable order: the run (with its holes), the block badges, events by position, then gap lines for missing positions, messages by index, compactions, requests by index, prompts, catalogs (tools records), spans
otlp<run>.otlp.jsonapplication/json; charset=utf-8{"logs": ExportLogsServiceRequest, "traces": ExportTraceServiceRequest} in OTLP/JSON, ids as hex. POST /v1/logs and /v1/traces read each half back into the same run
wefttest<run>.zipapplication/zipA generated <agent>_replay_test.go beside the run’s model calls as fixtures under testdata/TestReplay_<run>/; unzipped into a package directory, go test replays the run

A whole conversation exports too (since 0.18.0): the session page’s export jsonl, or GET /api/sessions/{id}/export?format=jsonl, downloads <session>.session.jsonl, format weft.session.export/1, streamed one turn at a time. It holds a session line, every turn’s run export in turn order (at most 200 turns), the state log’s session_mark lines (at most 2,000), session_hole lines and a closing session_end line {turns_exported, marks_exported, bytes}. Past 64 MiB it stops with a truncated hole, cause response_cap (the route).

A block the run does not have is badged, never left silently empty: not_recorded for a run written before the request record, stripped for a content-off run’s prompts and catalogs, gap for records a destination dropped (Badges and holes). The otlp records are rebuilt from what Studio stored: each carries the run’s identity and metadata, and one heartbeat at the run’s last-seen time keeps its status. Their resource carries only service.name; the spans keep their own resource.

The json document’s top-level keys, from the same run:

Terminal window
weft export c17b44940f21af67c33a6b68daa3c40d | jq -c 'keys, .format, .holes'
["compactions","events","format","holes","requests","run","spans","transcript"]
"weft.run.export/1"
[]

The file name is the run id plus the extension, sent as Content-Disposition: attachment. A child run’s slashes, quotes, backslashes, control and non-ASCII characters are spelled _ in the quoted name, and a non-ASCII id adds RFC 6266’s filename*. HEAD answers the headers alone. curl -OJ saves under that name:

Terminal window
curl -sOJ -H "Authorization: Bearer $TOKEN" \
'http://127.0.0.1:7331/api/runs/c17b44940f21af67c33a6b68daa3c40d/export?format=otlp'
ls
c17b44940f21af67c33a6b68daa3c40d.otlp.json

With &tree=1, the json, jsonl and otlp exports carry the run and then every subagent run under it, breadth first, at most 200, each its own export. The file is <run>.tree.<ext>.

  • json adds subagents (each child’s document; its run block names its parent_run_id) and subagent_holes, [] when the tree is whole.
  • jsonl writes each run’s lines in turn, each starting with its own run record, then one subagent_hole line per hole.
  • otlp puts every run in the same two requests, so a re-ingest restores the tree.

subagent_holes holds truncated (cause response_cap) when the tree has more than 200 subagent runs, and hidden with a count for the runs a panel token’s public id does not reach, left out with their subtrees. format=wefttest&tree=1 is a 400: a replay of the run substitutes its subagents’ recorded answers, so it needs only the run’s own calls. weft export has no tree flag; use the route.

The lead run here delegated once, to a research agent:

Terminal window
curl -s -H "Authorization: Bearer $TOKEN" \
'http://127.0.0.1:7331/api/runs/93155b4ade161db6f7e80ee9b2ce01cb/export?format=jsonl&tree=1' \
| jq -c 'select(.record=="run") | {record, id: .run.id, parent: .run.parent_run_id}'
{"record":"run","id":"93155b4ade161db6f7e80ee9b2ce01cb","parent":""}
{"record":"run","id":"93155b4ade161db6f7e80ee9b2ce01cb/0/d1","parent":"93155b4ade161db6f7e80ee9b2ce01cb"}

Post the two halves of an otlp export to the other Studio’s OTLP ingest. Here the tree goes to a second weft studio on an empty database, at 127.0.0.1:7333, which takes OTLP from loopback without a token:

Terminal window
curl -sOJ -H "Authorization: Bearer $TOKEN" \
'http://127.0.0.1:7331/api/runs/93155b4ade161db6f7e80ee9b2ce01cb/export?format=otlp&tree=1'
jq .logs 93155b4ade161db6f7e80ee9b2ce01cb.tree.otlp.json \
| curl -s -w ' %{http_code}\n' -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:7333/v1/logs
jq .traces 93155b4ade161db6f7e80ee9b2ce01cb.tree.otlp.json \
| curl -s -w ' %{http_code}\n' -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:7333/v1/traces
{} 200
{} 200

The second Studio then lists both runs (GET /api/runs?all=1 with its own token):

{"id":"93155b4ade161db6f7e80ee9b2ce01cb/0/d1","agent":"research","status":"succeeded","steps":1}
{"id":"93155b4ade161db6f7e80ee9b2ce01cb","agent":"lead","status":"succeeded","steps":2}

A Studio built with studio.IngestToken needs Authorization: Bearer <ingest token> on both posts (Run Studio).

weft export <run id> --wefttest <dir> fetches the wefttest zip and writes its fixtures under <dir>/<test>, where wefttest.Replay reads them. --test names the test; pass a TestXxx name, since the default (the run id) is not a valid Go test name. Without --force a target directory that is not empty is an error (exit 1, weft: <dir> is not empty: --force writes into it); with it, the *.json fixtures already there are replaced, never merged. It does not write the generated test file: the Studio download carries that.

Terminal window
weft export c17b44940f21af67c33a6b68daa3c40d --wefttest ./testdata --test TestSupportReplay
weft: wrote 2 fixtures to testdata/TestSupportReplay; a test named TestSupportReplay replays them with wefttest.Replay(t, "./testdata")

--format wefttest is a usage error (exit 2): weft: --format wefttest is a zip of fixtures: use --wefttest <dir>. Turn a Studio run into a test covers the zip and the replay.

RequestAnswer
The dev token, setup A’s loopback, or a playground panel token (for the runs of its public id)Every format
A read-scoped panel token, json or jsonl200, with the request block replaced by {"badge": "hidden"}: no system prompts or tool catalogs
A read-scoped panel token, otlp or wefttest403 with the hidden badge: both carry the request records
An unknown format400 format must be json, jsonl, otlp or wefttest
An unknown run404
wefttest for a derived run (built from stock spans)400 with the derived badge
wefttest for a run whose records cannot be fixtured409 with its badge: stripped (content off), gap (no transcript, or a step whose request record was dropped), or derived (a transcript that does not fixture)
wefttest for a run that recorded no assistant turn409 with no badge: nothing is missing, there is nothing to replay

TestExportFormats in docs-site/examples/studio/export_test.go records a run into a temporary database and checks each format’s answer, the tree=1 file name, and the two 400s. Run it from docs-site/examples:

Terminal window
go test -v -run 'Export' ./studio
--- PASS: TestExportFormats (0.02s)
PASS
ok weftgo.dev/docs/examples/studio 0.049s
  • Export the tree to move a delegation. A plain export holds one run; re-ingested alone, a parent’s subagent runs are missing. (Source: studio/export.go:67-73; CHANGELOG.md:300)
  • Treat an export as the transcript. With content on it holds prompts, tool arguments and results; share it as you would the database. (Source: studio/export.go:38-44)
  • An otlp export is not the original records. Studio rebuilds them from what it stored, and the log records’ resource keeps only service.name. (Source: CHANGELOG.md:2786-2818)
  • Name the Studio when several run. With no --url or WEFT_STUDIO_URL, weft export takes the Studio the discovery file names and says so in one stderr line, weft: Studio <url> (discovery file …). A file naming a stopped Studio is ignored (its pid is not running), and the export falls back to http://127.0.0.1:7331. Point --url at the Studio that holds the run. (Source: cmd/weft/resolve.go:45-80, 106-117; internal/discovery/discovery.go:118-138)