Skip to main content
A 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

A data.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 a data.thread gets a messages value, each message built from one item of the thread:
  • attributes.id is the item’s id, and attributes.created_at its time.
  • metadata.role is the item’s role, absent for an item posted without one.
  • role, content and the rest of metadata follow the mapping.
What a read sees is the items posted before its execution started, plus the items that execution posted itself. A message posted by someone else mid-run waits for the next run. Two branches of one run answering one thread see each other’s posts. A part is read as one message. A message too long for one item is posted as consecutive parts, and a read joins them back into the message that was written. The joined message has the first part’s id and time. A part that is not found is marked: its number is in 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

A message 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’s content 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

A genai.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 current is left unwired. The answer is posted to the thread, streamed there first as a partial message, and nothing else writes the conversation.
  • When output is wired to anything else, chat writes its answer as a value, and nothing is posted.
  • A logic.code on the same thread reads it with thread_messages(alias) and posts with post_message(alias, message), or through ports wired to the data.thread (Code Component); the tool loop works this way (Tool Calling).
  • Reading a thread and posting to another is a run of logic.copy between two data.thread components.
How chat chooses what to send is on Selecting a History, and the component itself on Chat Component.