> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blobhub.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Copy Component (logic.copy)

> Copies a value between two data components, selecting messages as a chat does.

A `logic.copy` is a step that reads the value of one data component and writes it to another. It is how a flow moves a
conversation between places: a thread to a `data.messages`, a `data.messages` to a thread, or one thread to another
([Messages and Threads](https://docs.blobhub.io/blob-types/workflow/workflows/messages-and-threads.md#moving-between-places)).

## Ports

A `logic.copy` has one flow input, which starts it, and the ports below.

### Flow

| Route | Category | Value | Notes |
| :- | :- | :- | :- |
| `success` | Flow output | | The value is copied. |
| `failure` | Flow output | | The copy failed ([When a copy fails](#when-a-copy-fails)). |

### Data

| Route | Category | Value | Notes |
| :- | :- | :- | :- |
| `input` | Data input | `messages` | Required. The value to copy. Wire a `data.thread` or a `data.messages` here. |
| `output` | Data output | `messages` | Required. Where the copy is written. Wire a `data.thread` or a `data.messages` here. |
| `roles` | Data input | `list` of `text` | Copy only messages of these roles. Empty, the default, copies every role. |
| `skip_roles` | Data input | `list` of `text` | Never copy messages of these roles. Defaults to `["note"]`. |
| `anchor` | Data input | `text` | A role. The newest message of this role, and what follows its edge, is copied ([Selecting a History](https://docs.blobhub.io/blob-types/workflow/workflows/selecting-a-history.md)). None by default. |
| `from` | Data input | `integer` | The start of a range over the messages after the anchor, counted as a Python slice counts. |
| `to` | Data input | `integer` | The end of that range, counted the same way. |
| `keep` | Data input | `list` of `text` | Roles that are copied even when the anchor or the range left them out. |

## What is copied

* **Any value but `messages` is copied unchanged.** It goes from `input` to `output` as it is. The ports name
  `messages`, the type the editor offers, and the copy itself does not look at the value.
* **A `messages` value is selected first.** `roles`, `skip_roles`, `anchor`, `from`, `to` and `keep` mean what a chat's
  `history_*` parameters mean, with the same rules for roles, anchors, ranges and kept roles
  ([Selecting a History](https://docs.blobhub.io/blob-types/workflow/workflows/selecting-a-history.md)). `from: -10` copies the last ten
  messages. The output is a `messages` value of the selected messages, in order.
* **A thread is selected as it is read,** newest first, so a copy anchored on a role does not read the whole thread
  ([Thread Component](https://docs.blobhub.io/blob-types/workflow/workflows/component-data-thread.md#read)).
* **A copy selects afresh each time it runs.** It does not keep the start a chat fixes for the length of an execution.
* **Anything finer is a `logic.code`:** a date, a search, a count. The copy selects by role and position only.

## Where it writes

* **To a `data.messages`,** the value is replaced by the selected messages.
* **To a `data.thread`,** the messages are posted in order, each as a new item. A copy appends and never replaces a
  thread. Each item is stamped with the run's `source`, and its role follows
  [the mapping](https://docs.blobhub.io/blob-types/workflow/workflows/component-data-thread.md#the-mapping).
* **A thread copied into itself posts nothing.** A message whose `attributes.id` already names an item of the target
  thread is skipped, and a thread's own messages carry their item ids. The same rule keeps a chat that reads a thread
  and writes it from posting its history again.
* **The first post creates the thread,** as for any write to a `data.thread`.

## Examples

Each example is a `logic.copy` between two data components. A connection from the copy to a data component takes the
form below, `input` reading the source and `output` writing the target; the flow connections that start the copy and
follow `success` are the usual ones.

```json theme={null}
[
  {"id": "<c1>", "source_id": "<copy>", "target_id": "<source component>", "route": "input",
   "source_port": "data_input", "target_port": "data_reference"},
  {"id": "<c2>", "source_id": "<copy>", "target_id": "<target component>", "route": "output",
   "source_port": "data_output", "target_port": "data_reference"}
]
```

### A thread to a `data.messages`

Corvel Freight keeps each shipment dispute in the thread `disputes/open`. When a dispute closes, a copy freezes the
conversation as a value for review, without the team's notes. `input` is wired to the `data.thread` with the alias
`disputes/open`, and `output` to a `data.messages` called `closed_dispute`. Nothing is wired to `roles`, `anchor` or
the range, so every role is copied except `note`, the default `skip_roles`. A later `genai.chat` reads
`closed_dispute` on its `history` as a worked example for its prompt.

### A `data.messages` to a thread

Halden Systems seeds each new support conversation from a stored briefing. `input` is wired to a `data.messages`
holding the briefing, and `output` to the `data.thread` with the alias `support/new`. The first copy creates the
thread, and each message becomes an item in order. Entering the same copy again posts the messages again, since the
briefing's messages carry no item ids. A retry of the same entry posts nothing new.

### A thread to another thread

Ostrava Pumps' service desk hands a conversation to the on-call engineer when the agent escalates. `input` is wired to
the `data.thread` `servicedesk/requests`, and `output` to the `data.thread` `servicedesk/escalations`. `anchor` is
set to the role `summary`, so the engineer receives the newest summary and what follows its edge rather than the whole
conversation, and `keep` takes `brief`, so the task's first post goes along as well. The engineer reads the
copy in the escalations thread and answers the requester in the original one.

## When a copy fails

A `logic.copy` whose `input` holds no value ends on `failure` with `Nothing to copy: "input" holds no value.`. A
message with a block the platform does not hold, or a block over the item limit on its own, fails the write to a thread
as any post does ([Thread Component](https://docs.blobhub.io/blob-types/workflow/workflows/component-data-thread.md#write)).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.