Skip to content

Commit 1fd30be

Browse files
authored
document session traces format (#2613)
1 parent 1800842 commit 1fd30be

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

docs/hub/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@
485485
title: Local Agents with llama.cpp
486486
- local: agents-libraries
487487
title: Agent Libraries
488+
- local: session-traces-format
489+
title: Session Traces Format
488490

489491
- local: other
490492
title: Other

docs/hub/agent-traces.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Each supported agent writes JSONL sessions to the following directories:
1919

2020
These trace files are supported out of the box, so you can upload them without modifying or converting them first.
2121

22+
<Tip>
23+
24+
Are you building your own harness? If your agent isn't listed above, you can make its sessions render in the trace viewer by emitting the [Session Traces Format](./session-traces-format).
25+
26+
</Tip>
27+
2228
Trace files can include prompts, tool inputs, command output, local paths, screenshots, secrets, private code, and personal data. Review and redact traces before publishing them publicly, or keep the dataset or bucket private if you are not sure what is inside.
2329

2430
For Pi Agent sessions, [`pi-share-hf`](https://github.com/badlogic/pi-share-hf) can help collect project sessions, redact known secrets, run TruffleHog and LLM review, and upload only sessions that pass checks.

docs/hub/session-traces-format.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Session Traces Format
2+
3+
Agent traces from Claude Code, Codex, and Pi are supported out of the box (see [Agent Traces](./agent-traces)). If you build your own harness, you can make its sessions render in the same viewer by writing them in the **Session Trace Simple Format (STS-Format)** described below.
4+
5+
The **Session Trace Simple Format (STS-Format)** is a [JSONL](https://jsonlines.org) file (one JSON object per line) that the Hugging Face Hub detects and renders in its trace viewer. It captures a single agent/chat session as a header line followed by message lines.
6+
7+
## 1. Session header (first line)
8+
9+
```json
10+
{ "type": "session", "harness": "my-agent", "id": "b1a2c3" }
11+
```
12+
13+
| field | required | notes |
14+
| --------- | -------- | ------------------------------------------------- |
15+
| `type` | yes | must be `"session"` |
16+
| `harness` | yes | **the id of the harness** that produced the trace |
17+
| `id` | yes | unique session id |
18+
| `name` | no | human-readable title |
19+
|| no | any extra metadata is allowed and ignored |
20+
21+
`harness` is the key field: it is **the id of the harness**, and it tells the Hub which renderer, icon, and label to use for the session. Currently recognized ids: `llama.app`. It is very easy to add a new harness identifier here.
22+
23+
> Building a harness of your own? Ping us and we'll add an icon and label for it so your sessions render with your branding.
24+
25+
## 2. Messages (every following line)
26+
27+
Each line is one message in an envelope:
28+
29+
```json
30+
{ "type": "message", "message": { "role": "assistant", "content": "" } }
31+
```
32+
33+
The `message` object:
34+
35+
| field | required | notes |
36+
| ------------------ | -------- | ------------------------------------------------------------------------------------------------------ |
37+
| `role` | yes | `"user"` · `"assistant"` · `"system"` · `"tool"` |
38+
| `content` | yes | text (may be empty) |
39+
| `reasoningContent` | no | model reasoning, shown as a separate thinking block |
40+
| `toolCalls` | no | assistant tool calls: `[{ "id", "function": { "name", "arguments" } }]` (`arguments` is a JSON string) |
41+
| `toolCallId` | no | on a `role: "tool"` message, links the result to the `toolCalls[].id` it answers |
42+
| `timestamp` | no | epoch milliseconds |
43+
| `model` | no | model name |
44+
45+
Tool results are messages with `role: "tool"` carrying a `toolCallId`; the viewer stitches each result next to the call that produced it.
46+
47+
### Example
48+
49+
```jsonl
50+
{"type":"session","harness":"my-agent","id":"abc123","name":"what time is it"}
51+
{"type":"message","message":{"role":"user","content":"what time is it?"}}
52+
{"type":"message","message":{"role":"assistant","content":"","toolCalls":[{"id":"t1","function":{"name":"get_time","arguments":"{}"}}]}}
53+
{"type":"message","message":{"role":"tool","toolCallId":"t1","content":"2026-07-01T15:00:00Z"}}
54+
{"type":"message","message":{"role":"assistant","content":"it is 15:00 UTC"}}
55+
```
56+
57+
Upload the resulting `.jsonl` to a [Dataset](https://huggingface.co/datasets) or a [Storage Bucket](./storage-buckets) to open it in the trace viewer.
58+
59+
## Alternative: Pi's session format
60+
61+
If you'd rather not adopt the shape above, you can emit **Pi's session format** ([session-format.md](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/session-format.md)), which the Hub already supports. In that case, add a `harness: "..."` field to Pi's session-header line as well, so the Hub can attribute the trace to your harness.

0 commit comments

Comments
 (0)