# Nested LLM node content

An expanded LLM node shows everything displayable in execution order. No fixed Reply or Reasoning sections. The stream itself: [agentic LLM streaming](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/agent/agentic-llm-streaming.html).

| Block, in order | Shown as |
| --- | --- |
| `reasoning_summary` | Folded row, where it occurred; only when the model returned one, never generated |
| `text` | Markdown, no heading |
| `parallel_group` | `read_config` Completed, `run_tests` Running: one group, invocation order |
| `text` | Continues after the group as a new block |
| `tool_ref` | `analyze_repository`; expands to its own inner LLM content |
| `text` | The final text |

## Tree and content

| View | Answers |
| --- | --- |
| Execution tree | Call relationships, parallel branches, status, duration, failure location |
| Node content | Ordered text, reasoning and function references inside one LLM node |
| Collapsed card | Name, status, duration, short preview |
| Expanded card, right-side details | One component, `LlmNodeContent` |

- A function row appears at invocation and reads arguments, progress, results and errors from its DAG node. Clicking it finds that node in the tree. An early finish never moves a row.
- Internal signatures are not content.
- All displayable content stays reachable. Large results may fold or load on demand, but a truncated preview is never the only copy.

## Model calls inside functions

- **Default**: The selected LLM open; its functions as summary rows
- **Limit**: Eight inline levels (`MAX_LLM_CONTENT_DEPTH`), then an explicit boundary with an action that opens the node as a new content root in details. The tree, tool state and history do not change
- **Expansion state**: Kept by node, attempt and block, so streaming and remounts do not reset it
- **Code functions**: Arguments, status, logs, return value; model content only if they called a model

## Block protocol

Each LLM node keeps ordered `blocks` per attempt on `execution_stream.v1`. Execution sets the order through `block_id` and `block_index`; WebSocket arrival time does not.

| Kind | Fields | Meaning |
| --- | --- | --- |
| `text` | `block_id`, content, status | Streaming Markdown |
| `reasoning_summary` | As `text`, plus retention | Policy may omit it from persistence |
| `tool_ref` | `block_id`, `tool_call_id`, `occurrence_id`, `ref_node_id`, optional `group_id` | A pointer to a DAG node; no inline result |
| `tool_arguments` | Argument delta | Preview while arguments generate; terminal display uses the tree |
| `parallel_group` | `group_id`, ordered `tool_ref` ids | Explicit concurrent batch only |
| `refusal`, `unsupported` | Existing | Shown as themselves |

**Example event**

```
{
  "type": "execution_stream",
  "schema_version": 1,
  "op": "block_started",
  "node_id": "call_9f3e",
  "attempt_id": "att_2",
  "block_id": "blk_tool_7",
  "block_index": 4,
  "kind": "tool_ref",
  "tool_call_id": "call_abc",
  "occurrence_id": "occ_7e4c",
  "ref_node_id": "exec_read_file_01",
  "group_id": "par_1"
}
```

### Tool identity

- One qualified `occurrence_id` is exactly one row. A raw `tool_call_id` may repeat across provider rounds; a duplicate event adds no row. A missing occurrence is accepted only for old records.
- A DAG tool node stores both ids; the stream publishes `occurrence_id → ref_node_id`. If the node is not visible yet, a placeholder with a stable id comes first and the same `block_id` is filled in later. No second row, no fabricated completion.

### Attempts

| Event | Result |
| --- | --- |
| Model request after normal tool results | Same attempt, more blocks. `turn_end` ends one provider round only |
| Transport or structured-output failure | `start_attempt(reason=...)`: a visible boundary; earlier attempts stay folded; new output never joins the incomplete Markdown |

### Parallel calls

- A group needs a real concurrent batch with known members. The Python dispatcher runs calls one by one, so it publishes no `group_id`; the frontend never infers a group from adjacent rows.
- Every member carries the id from its first event; an id created late is re-published for earlier members.
- Order is invocation order. Completion changes status only.

## Streaming and scrolling

- Reuse the chat's `renderMarkdown`, ThinkingStep and FunctionStep presentation and safety policy.
- Update the active block only. Unclosed fences, tables or links never blank the region.
- Virtualize or load large content by block.
- Follow at the bottom; scrolling up stops it. Expansion and highlighting keep the reading position.
- Copy text is not Copy full execution record, which may include reasoning and tool arguments.

## Refresh and failure

| Case | Result |
| --- | --- |
| Refresh, owner gone, worker restart | Same order, references and terminal states, from checkpoint, `metadata.stream` and snapshots. Never a model call |
| Incomplete text | Kept and marked interrupted, cancelled or failed |
| Reasoning not saved | “This content was not saved”, not an empty success |
| Old records | One legacy attempt from `metadata.blocks`; an unresolved reference shows as unresolved and keeps `tool_call_id` |

Live and durable snapshots hold complete block content; only compatibility preview fields may be cut.

**Acceptance scenario**

The model emits Markdown, calls two functions in parallel, one calls an inner model with `read_file`, the outer model continues. Disconnect and refresh during it. Afterwards:

- Block order, function states and hierarchy match the live view; tool state comes from persistent DAG nodes.
- No Reply or Reasoning header bars.
- Parallel members are not reordered by completion.
- Retries show boundaries without joining incomplete Markdown.
- `tool_ref` and tree nodes match one to one, with no duplicated results.

## Implementation status

| Status | Items |
| --- | --- |
| Implemented | Ordered blocks, `tool_ref`, attempts and version recovery (`CallStreamState`, the reducer); `LlmNodeContent` for cards and details; authority filtering before projection, so `io/llm` shows permitted descendants only; expansion state and the depth limit; persistent recovery |
| Not yet | The acceptance scenario with a real model in the default App. Concurrent dispatch, so `parallel_group` has no producer |
