# Agent Transcript

Reads and maintains a Session's durable transcript without sending messages or running the Agent.

- Tag: `agent_transcript`
- Input: `input`
- Output: `output`
- Operation selector: `operation.op`, one of `list`, `get`, `append`, or `delete`.
- Configured `session_id`, `entry_id`, and `limit` fields are TextBlocks supporting `{{ input.* }}` interpolation.

An Agent defines a role; a Session is an instance with its own transcript and message address.
Use this node for transcript inspection, maintenance, or input to a distillation workflow. Use
[Agent / Send Message](agent_action.md) to deliver something for the Agent to act on, and
[On Agent Message](on_agent_message.md) to subscribe to incoming messages and runtime output.

## Storage-only behavior

Every operation supports active and archived Sessions. Append and delete are allowed even while a
Run is in progress. They change durable storage only: they do not deliver a message, interrupt or
start a Run, enqueue work, emit message/run events, call a model, or recall memory.

An in-progress Run need not observe edits made after it read its history. Its completion persists
only its new entries: it does not overwrite an external append or restore an old deleted entry.
A later independently requested replay reads the resulting stored history within its normal
bounded replay window. Appending a user message is **not** equivalent to sending that message.

All operations verify the Session in the current workspace. Get and delete also verify that the
entry belongs to that Session; an ID from another Session or workspace is not found and changes
nothing. Get and delete address the actual row ID, including entries older than the newest replay
window.

## List

Config: `session_id`, optional `limit`.

An empty limit defaults to `50`. Numeric limits are bounded to `1`–`500`. The result is the newest
bounded tail, returned chronologically by creation time with ID as the tie-breaker.

```json
{
  "agent_transcript": {
    "operation": {
      "op": "list",
      "session_id": { "content": "{{ input.session_id }}" },
      "limit": { "content": "50" }
    }
  }
}
```

Output: `{"entries": [TranscriptRow, ...]}`. An empty transcript returns `{"entries": []}`.

## Get

Config: `session_id`, `entry_id`.

```json
{
  "agent_transcript": {
    "operation": {
      "op": "get",
      "session_id": { "content": "{{ input.session_id }}" },
      "entry_id": { "content": "{{ input.entry_id }}" }
    }
  }
}
```

Output: one `TranscriptRow`, not an `entries` wrapper.

## Append

Config: `session_id`. The canonical input is an object containing a nonempty `entries` array of
native `TranscriptEntryKind` objects. The whole batch is deserialized before any write; malformed
input or an empty batch writes nothing. Valid batches are inserted atomically.

```json
{
  "agent_transcript": {
    "operation": {
      "op": "append",
      "session_id": { "content": "{{ input.session_id }}" }
    }
  }
}
```

Example `input` from an upstream JavaScript node (replace the Session ID with an existing one):

```json
{
  "session_id": "01M1Z83VHQK1V0QSW30Z9PG238",
  "entries": [
    {
      "type": "user_message",
      "content": [{ "Text": { "text": "Imported conversation context" } }],
      "author": { "kind": "user" }
    },
    {
      "type": "assistant_message",
      "text": "An answer imported from that conversation."
    }
  ]
}
```

These are parsed JSON objects, never JSON-encoded strings. Entries have the flattened `type`
discriminator and payload; do not supply a full row, `id`, `timestamp`, or a `kind` wrapper.
The server assigns entry IDs and timestamps and derives the row's author, role, and text.

### Native entry format

The input accepts the native transcript kinds: `user_message`, `assistant_message`, `reasoning`,
`tool_invocation`, `human_question`, `human_response`, `compaction`, `system_notice`, and
`run_status`. The input socket describes their fields. A `run_status` `detail` is an error
`{"code":"…","message":"…"}`, a sentence, or who stopped the run: `{"kind":"user"}`,
`{"kind":"agent_session","session":"…","name":"…"}` or `{"kind":"workflow"}`.

An `assistant_message` read out of a session also carries `model` —
`{"connection":"<connection id>","model":{"provider":"openai","model":"gpt-5"}}`, the connection the
run was authorized by and what it resolved to. Absent whenever there was no connection to name, and
on entries written before it existed; never present and partly filled in. Appending it is only for
history imported from somewhere that knows; a run records its own.

User message content uses **externally tagged, capitalized** keys:

- Text: `{"Text":{"text":"..."}}`
- Context: `{"Context":{"context":{"context_type":"...","slug":"...","name":"..."}}}`
- Media: `{"Media":{"media":{"Object": ObjectDescriptor}}}` for a stored object, or
  `{"Media":{"media":{"External":{"url":"https://example.com/image.png","kind":"image","content_type":"image/png","filename":null}}}}`
  for external media. `ObjectDescriptor` is the existing structured object descriptor, not an ID string.
- Quote: `{"QuotedText":{"text":"...","author":"Sender","entry_id":"<entry id>"}}` for words quoted
  from an earlier message. `author` and `entry_id` are optional. It comes first in the content,
  and the message needs a Text of its own beside it. The model reads it between `<quote>` and
  `</quote>` tags, each on its own line.

Do not use AI Conversation's separate lowercase `{"type":"text","text":"..."}` content
adapter here. It is not the native transcript format and is refused.

`author` defaults to `{"kind":"user"}` when omitted. Other native authors are
`{"kind":"system","origin":"…","hidden":true}` and
`{"kind":"agent_session","session":"reply-address","name":"Sender"}`. Both fields of a system
author are optional: `origin` is free text naming what sent the message, which the model reads as
the `origin` attribute of its `<system>` tag and the chat shows as the message's label
(**Automation** when it is empty); `hidden: true` keeps the message out of the chat, and the agent
still reads it. How the agent should treat a system message is for its text to say. Messages read
out of a session may also carry
`{"kind":"delegation_response","session":"…","name":"…","outcome":{"status":"finished"}}`, a
helper session reporting that its work ended (`{"status":"failed","reason":"…"}` when it failed,
`{"status":"stopped","by":{"kind":"…"}}` when it was stopped, with `by` as in a `run_status`
`detail`, and `{"status":"withdrawn","reason":"…"}` when it was archived or its agent retired
before it answered, with `reason` `archived`, `archived_idle` or `retired`).

Optional `sent_at` belongs inside the `user_message` payload. It is model-facing send time,
not the outer entry's recording timestamp. Storage-only append preserves an explicit value
and leaves an omitted value absent; it does not invent delivery time for imported history.

Output: `{"entries": [TranscriptRow, ...]}` containing the newly allocated durable rows.

## Delete

Config: `session_id`, `entry_id`.

```json
{
  "agent_transcript": {
    "operation": {
      "op": "delete",
      "session_id": { "content": "{{ input.session_id }}" },
      "entry_id": { "content": "{{ input.entry_id }}" }
    }
  }
}
```

Permanently removes that one durable entry. It does not stop a Run or retract any message the
current in-memory Run has already seen. A missing or wrong-Session entry is an error, not a
successful no-op.

Output: `{"session_id":"...","entry_id":"...","deleted":true}`.

## Transcript rows

All row outputs reuse the same `TranscriptRow` shape:
`{id, session_id, created_at, author, role, text, entry}`.

- `id` is also the contained transcript entry's ID.
- `author`: `user`, `agent_session`, `system`, or `agent`.
- `role`: `user`, `assistant`, `tool`, or `status`.
- `text`: display text, or `null` for an entry without it.
- `entry`: the complete native `TranscriptEntry`, `{id, timestamp, kind}`. Its `kind` is the
  structure append accepts; its server-owned ID and timestamp are not append inputs.

[Agent / List Messages](agent_action.md#list_messages) remains available for existing workflows
and retains its `{session_id, messages}` output. This node's list output is `{entries}`.

### Recalled memory on a message

A `user_message` a Session received may carry `context`: the memories the Agent recalled for that
message when it was posted, as snapshots of how they read then.

```json
"context": [{"type": "memory", "id": "01...", "namespace": "notes", "title": "Packing habit",
  "text": "Always packs an umbrella.", "links": [], "links_truncated": false, "properties": {},
  "semantic_score": 0.81, "current_relevancy": 0.92, "matched_query_chunk": 0,
  "created_at": "...", "updated_at": "..."}]
```

`entry.kind.context` is what the runtime supplied, not what the author said, and it is not fresh
evidence: a distillation or extraction workflow must read the message `content` (or the row's
`text`, which never includes it) and ignore `context`, or it will extract a memory from its own
recall. The memory itself may have changed or been deleted since; read it by `id` for its current
state. Absent when nothing was recalled. Only the latest message's memory is shown to the model on
each turn.

When recall could not run for a message, for example because the embedding provider was out of
credit, the message was delivered without memory and its `context` holds
`{"type": "memory_recall_failed", "failure": "provider"}` instead. `failure` is `provider` (the
embedding provider refused or failed the request), `unavailable` (the embedding model could not be
reached through its connection) or `internal`. No model ever sees this item.

## Failure behavior

An operation run while the workspace's Agents tables are not set up names the missing Agents
setting. Unknown operations are explicitly refused with a prompt to choose an available
operation. Invalid IDs, malformed input, missing Sessions, and missing transcript entries fail
rather than changing a different Session's history.
