> For the complete documentation index, see [llms.txt](https://krynix.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krynix.gitbook.io/docs/reference/trace-format.md). Agents can also search and read this documentation through its [MCP server](https://krynix.gitbook.io/docs/~gitbook/mcp).

# Trace format

The record format behind every session, in the hosted service and in trace files written by the Krynix packages. Read this if you send records yourself, verify evidence with your own tools, or work with trace files. For a shorter guide to reading a session, see [Event types](https://krynix.gitbook.io/docs/reference/event-types.md).

**Schema version:** `1.1.0`. Version `1.1.0` adds the optional `policy_decision` object to `decision` events; every addition is optional, so `1.0.0` records stay valid.

## The event

A session is an ordered list of events. Every event has these fields:

| Field            | Type                   | Required | Description                                                                                                                  |
| ---------------- | ---------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `event_id`       | string (UUID)          | yes      | Unique id for this event.                                                                                                    |
| `session_id`     | string                 | yes      | The session the event belongs to. In the hosted API any stable string works; trace files written by the packages use a UUID. |
| `sequence_num`   | integer                | yes      | Position in the session, from 0, with no gaps. Assigned by Krynix in the hosted service.                                     |
| `timestamp`      | string (RFC 3339, UTC) | yes      | For example `2026-03-15T14:22:03.847Z`.                                                                                      |
| `event_type`     | string                 | yes      | One of the eight types below.                                                                                                |
| `parent_id`      | string or `null`       | no       | The `event_id` that caused this one, such as the `tool_call` a `tool_result` answers.                                        |
| `agent_id`       | string                 | yes      | The agent that produced the event.                                                                                           |
| `payload`        | object                 | yes      | Depends on the event type.                                                                                                   |
| `redacted`       | boolean                | yes      | `true` if values were removed from the payload before sending.                                                               |
| `prev_hash`      | string                 | yes      | The previous event's `event_hash`; `""` for the first event. Assigned by Krynix in the hosted service.                       |
| `event_hash`     | string                 | yes      | SHA-256 of this event (see [The hash chain](#the-hash-chain)). Assigned by Krynix in the hosted service.                     |
| `metadata`       | object                 | no       | Free-form context. Krynix adds where the record came from here.                                                              |
| `schema_version` | string                 | yes      | `"1.1.0"`. `"1.0.0"` is also accepted.                                                                                       |

## Event types

### `tool_call`

The agent invoking a tool.

```json
{
  "tool_name": "file_write",
  "arguments": { "path": "/tmp/output.txt", "content": "hello" }
}
```

| Field             | Type                         | Required | Description                               |
| ----------------- | ---------------------------- | -------- | ----------------------------------------- |
| `tool_name`       | string                       | yes      | The tool, such as `Bash` or `file_write`. |
| `arguments`       | object                       | yes      | The tool's arguments.                     |
| `approval_status` | `auto`, `manual` or `denied` | no       | Present when a policy required approval.  |
| `approved_by`     | string                       | no       | Who approved the call.                    |
| `approval_reason` | string                       | no       | Why.                                      |

### `tool_result`

What the tool returned.

```json
{ "tool_name": "file_write", "output": { "bytes_written": 5 }, "exit_code": 0, "duration_ms": 12 }
```

| Field         | Type    | Required | Description                                                                          |
| ------------- | ------- | -------- | ------------------------------------------------------------------------------------ |
| `tool_name`   | string  | yes      | Matches the `tool_call`.                                                             |
| `output`      | any     | yes      | The tool's return value.                                                             |
| `exit_code`   | integer | no       | For shell-like tools. Absent when the tool did not report one; never `0` by default. |
| `duration_ms` | integer | yes      | How long the call took. `-1` when it was not measured.                               |

### `llm_request`

A request sent to a model.

| Field        | Type   | Required | Description                         |
| ------------ | ------ | -------- | ----------------------------------- |
| `model`      | string | yes      | The model id.                       |
| `messages`   | array  | yes      | The prompt messages.                |
| `parameters` | object | yes      | Temperature, token limit and so on. |

### `llm_response`

The model's answer.

| Field           | Type    | Required | Description                                                                               |
| --------------- | ------- | -------- | ----------------------------------------------------------------------------------------- |
| `model`         | string  | yes      | The model id.                                                                             |
| `content`       | string  | yes      | The response text.                                                                        |
| `usage`         | object  | yes      | `prompt_tokens`, `completion_tokens`, and optionally `total_tokens` and `estimated_cost`. |
| `finish_reason` | string  | yes      | `stop`, `max_tokens` or `tool_use`.                                                       |
| `is_streaming`  | boolean | no       | Whether the response was streamed.                                                        |

### `decision`

A decision. Two kinds share this type: a policy decision from Krynix, the SDK or the gateway, which carries `policy_decision`; and a reasoning step an agent records about itself, which does not.

```json
{
  "action": "deny",
  "reasoning": "Recursive force-delete is not permitted.",
  "policy_decision": { "verdict": "fail", "rule_id": "no-recursive-delete", "latency_ms": 3 }
}
```

| Field             | Type      | Required | Description                                                                    |
| ----------------- | --------- | -------- | ------------------------------------------------------------------------------ |
| `action`          | string    | yes      | What was decided. For a policy decision, the matched rule's action, or `pass`. |
| `reasoning`       | string    | yes      | The rule's message for a policy decision; the agent's reasoning otherwise.     |
| `confidence`      | number    | no       | 0 to 1. Agent reasoning steps only.                                            |
| `alternatives`    | string\[] | no       | Agent reasoning steps only.                                                    |
| `policy_decision` | object    | no       | Present on policy decisions.                                                   |

`policy_decision`:

| Field        | Type                                           | Required      | Description                                                                                                                                                                                        |
| ------------ | ---------------------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `verdict`    | `pass`, `fail`, `redact` or `require-approval` | yes           | A deny is written as `fail`.                                                                                                                                                                       |
| `rule_id`    | string                                         | no            | The rule that matched, including an `allow` rule. `__default_deny__` when the policy's default denied the call. Absent only when nothing matched and the call passed.                              |
| `redactions` | array                                          | when `redact` | Each item is `{ "path", "value_redacted" }`, where `value_redacted` is the replacement written in place of the original, never the original. Required and non-empty on `redact`, absent otherwise. |
| `latency_ms` | number                                         | yes           | How long the policy took to decide.                                                                                                                                                                |

### `observation`

Something the agent observed, or context Krynix recorded, such as a prompt or a loaded plugin.

| Field     | Type   | Required | Description         |
| --------- | ------ | -------- | ------------------- |
| `source`  | string | yes      | Where it came from. |
| `content` | any    | yes      | What was observed.  |

### `error`

| Field         | Type    | Required | Description                                      |
| ------------- | ------- | -------- | ------------------------------------------------ |
| `code`        | string  | yes      | A machine-readable code, such as `TOOL_TIMEOUT`. |
| `message`     | string  | yes      | What happened.                                   |
| `recoverable` | boolean | yes      | Whether the agent could carry on.                |

### `lifecycle`

The start and end of a session.

| Field     | Type                                           | Required | Description                                                                                                                          |
| --------- | ---------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `action`  | `session_start`, `session_end` or `checkpoint` | yes      |                                                                                                                                      |
| `context` | object                                         | no       | On `session_start`, optional details such as the CI run and git commit. On `session_end`, summary figures and how the session ended. |

## The hash chain

1. The first event's `prev_hash` is `""`. Every later event's `prev_hash` is the previous event's `event_hash`.
2. To compute `event_hash`, take the whole event with `event_hash` set to `""`, serialise it as canonical JSON, and take the hex-encoded SHA-256.

**Canonical JSON** (RFC 8785): keys sorted by Unicode code point, no whitespace, UTF-8, no trailing newline, and numbers written the way `JSON.stringify` writes them (`1.0` becomes `1`, `0.10` becomes `0.1`). `NaN` and infinities are not allowed.

**To verify a session**, recompute each `event_hash`, check each `prev_hash` against the previous event, and check that the first `prev_hash` is `""`. The first mismatch is where the chain breaks.

The chain on its own proves the records are consistent, not who wrote them: anyone who can rewrite every record can build a new consistent chain. The Ed25519 signature over the end of the chain is what proves the records are the ones Krynix received. See [Evidence and custody](https://krynix.gitbook.io/docs/using-the-dashboard/evidence-and-custody.md).

## Trace files

The Krynix packages write sessions as **`.trace.jsonl`** files: UTF-8 JSON Lines, one event per line, optionally gzipped. A complete trace file starts with `lifecycle: session_start`, ends with `lifecycle: session_end`, and has contiguous sequence numbers from 0. A whole file can be uploaded to Krynix with `POST /v1/traces`.

Trace files written by the packages have fields whose names end in `_key`, `_secret`, `_token`, `_password` or `_credential` (any depth, any case) redacted before hashing. The value becomes `[REDACTED:` followed by the first 8 hex characters of its SHA-256 and `]`, so the same secret can be matched across events without being stored, and `redacted` is set to `true`. The hosted service does not do this; see [How your data is protected](https://krynix.gitbook.io/docs/security-and-data/data-and-security.md).

A signature made with `krynix sign` is written beside the trace as a `.sig` file. See [Command line](https://krynix.gitbook.io/docs/reference/cli.md).
