data.thread names a thread of the session by alias,
and turns it into a value and back. Read, the thread is a messages value. Written, it posts. It is the only component
that knows threads; every other component reads one through an input that takes messages and writes one through an
output that carries a message or messages
(Messages and Threads).
Ports
Adata.thread has one data input, alias, and the data reference every data component has, which other components
connect to. It has no value and no persistence port: a thread always lives in the session.
A
data.thread without an alias fails the definition’s check with Thread component needs an alias. It is never a
step: no flow route enters or leaves it.
Read
A component that reads adata.thread gets a messages value, each message built from one item of the thread:
attributes.idis the item’s id, andattributes.created_atits time.metadata.roleis the item’s role, absent for an item posted without one.role,contentand the rest ofmetadatafollow the mapping.
metadata.missing_parts, and a text block reading
[Part N of T of this message is missing.] stands in its place ([Part N of this message is missing.] when the
parts name no usable total). A part can be missing because it was lost, or because its writer has not stored it
yet.
Where a component selects what it reads, the selection applies as the thread is read, newest first, so a long
thread is not read whole unless keep is set: genai.chat’s history and logic.copy’s input take the
history selection. Everywhere else the read is the visible
thread, whole, with the default selection: items whose role is note are left out.
A thread that does not exist yet reads as an empty history. An alias that holds another kind of object fails the node.
Write
Amessage posts one item, and a messages value one item per message, in order. Any other value type fails the node
with A thread takes a message or messages, not <type>.
A message whose attributes.id already names an item of that thread is skipped. This is what lets a component hand
back the history it read with its own messages added: only what was added is posted. A genai.chat that reads a thread
on history and writes it on output posts only its answer.
What a post records on the item:
The first post creates the thread. A
data.thread whose alias holds nothing creates the thread with its first
post. An alias that holds another kind of object fails the node, as a post there is refused
(invalid_thread_envelope), and a post never replaces an existing thread.
A message over the item limit is posted in parts. An item holds up to 262,144 bytes (256 KiB)
(workflow.thread_item_bytes). A longer message is cut into the fewest consecutive items
that fit, in block order, each carrying metadata.part with index (from 1), total, of (the first part’s id) and
continues (true when the part ends in a piece of text that the next part carries on). A text block too long for a
part on its own is cut between characters. Any other single block over the limit fails the post with
thread_item_too_large. A message that fits takes no part.
A message of 2 to 9 parts is stored in one transaction, so a post that stops partway leaves all of its parts or
none. A longer one is stored a part at a time, in order, and a post that stops partway leaves its first parts.
A message already stored is not stored again. A post that finds any part of its message stored stores nothing and
returns the oldest part present, so a retry that regenerated the message keeps the stored one, and a part deleted from
it stays deleted. The one exception is a retry that regenerates the message into fewer parts after the stored one lost
its first two parts and every part the regenerated message is now cut into: those parts are posted under their ids. A
genai.chat retried leg finds its stored answer by any of its first 100 parts.
A split message raises one thread.item_posted once its parts
are stored: its item block names the first part’s id and lists every part’s id in parts, in order. A retry that
finds a message of more than 9 parts without its last part stores nothing and raises the event with the oldest part
present, the present ids in parts and the absent numbers in missing_parts, again on each such retry. A message
that carries a part or missing_parts of its own is posted without it, and split afresh if it needs to be.
The mapping
A message becomes an item with the message’scontent unchanged, and an item becomes a message by the rules below,
the same on every turn, so a stored thread renders identically each time it is read.
A person’s post through the conversation widget is a
request. An item whose metadata.role is reply and that holds
no tool_result block reads back as assistant; every other item reads back as user.
A chat on a thread
Agenai.chat reads and answers a thread through its ports, with no thread port and no thread mode. One data.thread
is wired to history, and output is wired to the same data.thread. The conversation widget
(widget.thread) shows the thread, and a post in it starts the run:
In the stored definition these are two connections between the same two components:
- What the widget shows is what chat read and wrote. The person’s post is already in the thread when the run
starts, so
currentis left unwired. The answer is posted to the thread, streamed there first as a partial message, and nothing else writes the conversation. - When
outputis wired to anything else, chat writes its answer as a value, and nothing is posted. - A
logic.codeon the same thread reads it withthread_messages(alias)and posts withpost_message(alias, message), or through ports wired to thedata.thread(Code Component); the tool loop works this way (Tool Calling). - Reading a thread and posting to another is a run of
logic.copybetween twodata.threadcomponents.

