Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 279 additions & 4 deletions adapters/typescript/pi/README.md

Large diffs are not rendered by default.

846 changes: 846 additions & 0 deletions assets/pi-invocation-paths.excalidraw

Large diffs are not rendered by default.

Binary file added assets/pi-invocation-paths.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/about-nemo-fabric/supported-harnesses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NVIDIA NeMo Fabric includes adapters for the following harnesses and execution t
| [OpenClaw](../integrations/harness/openclaw/openclaw.mdx) | ✓ | ✓ | ✓ | — | ✓ |
| [OpenHands](../integrations/harness/openhands.mdx) | ✓ | ✓ | ✓ | — | — |
| [OpenCode](../integrations/harness/opencode.mdx) | — | ✓ | ✓ | — | — |
| [Pi](../integrations/harness/pi.mdx) | ✓ | — | ✓ | ✓ | — |
| [Pi](../integrations/harness/pi/pi.mdx) | ✓ | ✓ | ✓ | ✓ | ✓ |
| [Qwen Code](../integrations/harness/qwen.mdx) | ✓ | ✓ | ✓ | — | — |
| [Remote Agent](../integrations/harness/remote-agent.mdx) | — | — | — | ✓ | — |

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/install-adapters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ For a separate runtime interpreter, follow [Install an Adapter and Harness Witho
| OpenClaw | [Install the OpenClaw adapter](../integrations/harness/openclaw/openclaw.mdx#install-openclaw-and-the-adapter) |
| OpenHands | [Install the OpenHands adapter](../integrations/harness/openhands.mdx#install-the-adapter) |
| OpenCode | [Install the OpenCode adapter](../integrations/harness/opencode.mdx#install-the-adapter) |
| Pi | [Install the Pi adapter](../integrations/harness/pi.mdx#install-the-adapter) |
| Pi | [Install the Pi adapter](../integrations/harness/pi/pi.mdx#install-the-adapter) |
| Qwen Code | [Install the Qwen Code adapter](../integrations/harness/qwen.mdx#install-the-adapter) |
| Remote Agent | [Install the Remote Agent adapter](../integrations/harness/remote-agent.mdx#install-the-adapter) |

Expand Down
5 changes: 3 additions & 2 deletions docs/getting-started/install-relay.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ Set
directory; relative paths resolve from `environment.workspace`. Relay-enabled
Pi configurations must also set `runtime.artifacts` so NeMo Fabric can provide
the adapter-owned Relay configuration. Refer to the
[Pi adapter guide](../integrations/harness/pi.mdx) for the complete
configuration and the embedded collector streaming workflow. Do not set
[Pi adapter guide](../integrations/harness/pi/pi.mdx#nemo-relay) for the complete
configuration and the [Pi SDK guide](../integrations/harness/pi/pi-sdk.mdx#stream-relay-records)
for the embedded collector streaming workflow. Do not set
`launch_collector=False` for Pi streaming because the Pi extension does not
attach the NeMo Fabric request IDs required by an externally managed collector.
10 changes: 8 additions & 2 deletions docs/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,14 @@ navigation:
path: ./integrations/harness/openhands.mdx
- page: OpenCode
path: ./integrations/harness/opencode.mdx
- page: Pi
path: ./integrations/harness/pi.mdx
- section: Pi
collapsed: true
path: ./integrations/harness/pi/pi.mdx
contents:
- page: SDK
path: ./integrations/harness/pi/pi-sdk.mdx
- page: Terminal TUI
path: ./integrations/harness/pi/pi-tui.mdx
- page: Qwen Code
path: ./integrations/harness/qwen.mdx
- page: Remote Agent
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/harness/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NeMo Fabric includes the following harness integrations:
| OpenClaw | [Use the OpenClaw adapter](./openclaw/openclaw.mdx) |
| OpenHands | [Use the OpenHands adapter](./openhands.mdx) |
| OpenCode | [Use the OpenCode adapter](./opencode.mdx) |
| Pi | [Use the Pi adapter](./pi.mdx) |
| Pi | [Use the Pi adapter](./pi/pi.mdx) |
| Qwen Code | [Use the Qwen Code adapter](./qwen.mdx) |
| Remote Agent | [Use the Remote Agent adapter](./remote-agent.mdx) |

Expand Down
151 changes: 151 additions & 0 deletions docs/integrations/harness/pi/pi-sdk.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
title: Pi SDK
description: Invoke the embedded Pi session with normalized configuration and results.
slug: /integrations/harness-integrations/pi-sdk
---
{/* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0 */}

Start with [pi.mdx](./pi.mdx) for shared setup and an overview of both execution paths.

NVIDIA NeMo Fabric's Pi SDK path executes requests through an embedded Pi SDK session in the adapter's Node.js process. It returns normalized results and reuses conversation history across ordered invocations.

## Installation

Complete the [shared installation](./pi.mdx#install-the-adapter). The SDK path requires no interface-specific packages.

## Configure the Adapter

Use the [shared configuration](./pi.mdx#shared-configuration) for the model, instructions, tools, skills, extensions, MCP servers, and NeMo Relay. The SDK session is the default execution path, so an SDK runtime needs no execution-path settings.

### Pi Settings

The descriptor uses closed schemas, so unknown settings are rejected.

| Setting | Default | Behavior |
| --- | --- | --- |
| `sdk.enabled` | `true` | Initialize the embedded SDK session. Set to `false`, with the terminal interface enabled, for a [terminal TUI runtime](./pi-tui.mdx); SDK invocation then fails with `pi_sdk_disabled`, while runtime management remains available. |
| `interfaces.terminal` | Off | Offer Pi's terminal TUI instead of the SDK session. Refer to the [terminal TUI guide](./pi-tui.mdx). |
| `extensions` | `[]` | Workspace-relative Pi extension files, loaded as trusted code. |
| `relay_extension_path` | None | The NeMo Relay Pi extension; refer to [NeMo Relay](./pi.mdx#nemo-relay). |
| `insecure_http_model_hosts` | Omitted | Hosts trusted for credential-free HTTP model forwarding; refer to [Credential-Free HTTP Model Gateways](./pi.mdx#credential-free-http-model-gateways). |

## Invoke and Stream

With `config` from the [shared configuration](./pi.mdx#shared-configuration), invoke the runtime through the public SDK:

```python
from nemo_fabric import Fabric

async with await Fabric().start_runtime(config) as runtime:
result = await runtime.invoke(input="List the files in the workspace.")
print(result.output)
```

`Runtime.invoke_stream()` uses Relay-backed event streaming; retrieve its normalized result with `stream.result()`. Refer to [Stream Relay Records](#stream-relay-records) for the Pi setup and to [streaming](../../../sdk/streaming.mdx#nemo-relay-streaming) for the SDK usage pattern.

## Lifecycle and Conversations

Each NeMo Fabric runtime owns one in-memory Pi session in a persistent Node.js
adapter process. Ordered invocations reuse that session and its conversation
history until the runtime stops. Start a new runtime to change the model,
skills, extensions, custom tools, or workspace.

The session loads its settings, model catalog, and system prompt from the
runtime's [agent directory](./pi.mdx#agent-directory-and-kept-state), as the
`pi` CLI does, and gets its MCP servers and model key in memory. With
`runtime.keep_state`, each runtime starts a new conversation and writes it to
the agent's shared session store, where a later terminal TUI runtime can open
it.

The Pi adapter doesn't declare `session_resume`, so an SDK runtime can't resume
an earlier conversation: starting a runtime with a `session_ref` fails with
`session_resume_unsupported`.

Evaluation consumers, including Harbor, invoke through the SDK, so they need
the SDK session, its default. A terminal TUI runtime can't run SDK evaluation
trials.

## Invocation Usage

Each invocation reads only new entries from Pi's raw session ledger, including
retained failed attempts, compaction and branch summaries, nested tool usage,
and auxiliary usage records. Automatic cache warming is disabled so background
refresh calls cannot escape the invocation boundary. Session history and previous invocations are not
counted again. Input totals include cache reads and cache writes; output totals
already include reasoning tokens. Available breakdowns are returned through
`nemo_fabric.detailed_token_usage.v1`.

Missing or inconsistent usage leaves the complete counters unknown. Pi 1.0.3
initializes unreported provider usage to zero, so an all-zero record also remains
unknown. A failed or retried summary can omit attempt usage from the ledger;
complete counters remain unknown in that case. Nonzero records can retain real
zero input, output, or cache dimensions. Configured-rate SDK cost estimates are
not published as provider-reported `cost_usd`.

## Results and Relay

With [NeMo Relay](./pi.mdx#nemo-relay) enabled, the result includes
`relay_runtime` and `relay_artifacts` in `output`.

The matching Relay Pi extension emits `turn_end` and closes the per-turn
scope, but its local ATIF trajectory remains attached to Pi's session-level
agent scope. Relay therefore finalizes that trajectory only after the Pi session
closes. It is not included in the invocation's `relay_artifacts`. The adapter
does not wait for local ATIF during invocation. It collects per-invocation
artifacts such as ATOF and returns the result. After runtime shutdown, retrieve
the finalized file directly from the ATIF output directory. For the
[shared Relay configuration](./pi.mdx#nemo-relay) and the default filename template, it is written to
`./artifacts/relay/<runtime_id>/trajectory-<session_id>.atif.json`. Invocation
results do not prevent subsequent turns.

Pi emits its startup `model_redirect` marks before NeMo Fabric registers an
invocation, so they are not included in the per-invocation records from
`invoke_stream()`.

### Stream Relay Records

Install the matching collector for the embedded streaming path:

```bash
pip install "nemo-fabric[streaming]"
```

Start the runtime with streaming enabled to consume live model-turn ATOF
records for successful Relay redirects in one Pi invocation:

```python
from nemo_fabric import Fabric

async with await Fabric().start_runtime(config, streaming=True) as runtime:
stream = runtime.invoke_stream(input="Review the latest patch")
async for record in stream:
print(record)
result = await stream.result()
```

The terminal `RunResult` remains separate from the ATOF records. Fully consume
each stream, or call `await stream.aclose()` if iteration stops early, before
starting another invocation. The same runtime can then alternate
`invoke_stream()` and `invoke()` calls. The embedded collector serializes both
methods behind one Pi invocation lease. Streaming capture begins at the first
Pi `turn_start` and closes at `agent_settled`. If Relay output is interrupted or
late, the collector waits for a bounded interval, then admits the next native
invocation and uses Pi's cumulative turn count to discard ambiguous delayed
records until a higher `turn_start` arrives. This can thin the ATOF stream but
does not block later invocations. Increase `completion_wait_timeout` from its
one-second default when Relay delivery can take longer. Use the default embedded
collector for Pi streaming. The Pi extension does not attach NeMo Fabric
request IDs, so
`start_runtime(..., streaming=True, launch_collector=False)` cannot correlate
its records through an externally managed collector.

This Relay-backed path runs the adapter's ordinary `invoke` operation. It is
independent of native OpenAI streaming, so the adapter descriptor's
`capabilities.streaming` value remains `false`.

## Health and Limitations

Runtime health and `idle`/`busy` activity describe the SDK session; refer to
[Health Checks](../../../sdk/health-checks.mdx). Read the
[shared limitations](./pi.mdx#limitations-and-planned-work).
98 changes: 98 additions & 0 deletions docs/integrations/harness/pi/pi-tui.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: Pi Terminal TUI
description: Open Pi's own terminal UI on a managed runtime's configuration and
environment.
slug: /integrations/harness-integrations/pi-terminal-tui
---
{/* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0 */}

Start with [pi.mdx](./pi.mdx) for shared setup and an overview of both execution paths.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

NVIDIA NeMo Fabric's Pi terminal path opens Pi's own terminal UI, the stock `pi` CLI, on a runtime's configuration. Pi has no backend for a terminal client to attach to, so each terminal TUI runs the agent in its own process, which a person starts with the runtime's launcher. Unlike the Hermes and OpenClaw terminal TUIs, it takes no port.

**Experimental terminal interface:** The `interfaces.terminal` configuration, the launcher, the `interfaces/tui.json` attachment file, and the `interfaces/tui.clients` registrations may change as NeMo Fabric adopts the [launcher contract in #579](https://github.com/NVIDIA/NeMo-Fabric/issues/579). Compatibility across releases is not guaranteed for these surfaces.

## Installation

Complete the [shared installation](./pi.mdx#install-the-adapter) first. The launcher runs the `pi` CLI bundled with the adapter's Pi dependency, so the terminal TUI needs no other packages. It additionally requires:

- **Host:** POSIX, with `/proc` or `ps` to identify terminal TUI processes. Otherwise startup fails with `pi_terminal_unsupported_platform`.
- **Node.js:** the Node.js runtime that runs the adapter, which the launcher names.

## Configuration

Start from the [shared configuration](./pi.mdx#shared-configuration) and replace its `harness` with this one, which that example passes to `FabricConfig` as `harness=harness`:

```python
from nemo_fabric import HarnessConfig

harness = HarnessConfig(
adapter_id="nvidia.fabric.pi",
settings={
"sdk": {"enabled": False},
"interfaces": {"terminal": {}},
},
)
```

A runtime runs either the SDK session or terminal TUIs. Planning and startup refuse the terminal interface while `sdk.enabled` is on, its default, with `pi_execution_path_conflict`. A terminal TUI runtime still writes the agent directory and the launcher, and your application can still start, check, and stop it, but it runs no embedded session: invocation returns a failed `RunResult` with `pi_sdk_disabled`.

The same `FabricConfig` works on both paths. A setting that only the SDK session honors logs a `Pi warning:` line at startup instead of failing it; today that is only the Relay ATOF sink that `start_runtime(..., streaming=True)` adds, which delivers records through `invoke_stream()`.

With the terminal interface enabled, `api_key_env` must be a valid environment variable name that the launcher doesn't set itself (`pi_api_key_env_invalid`), and MCP headers can't reference such a variable either (`pi_mcp_header_variable_reserved`).

## Runtime Environment

A terminal TUI runs Pi itself, in a process a person starts, so it gets the runtime's environment from the running runtime rather than from a backend. The launcher holds no secrets. It runs a launch helper that fetches the runtime's `environment.env` and model key over an owner-only Unix socket and starts Pi with them, so you don't export the key before running the launcher.

- **Precedence:** The runtime's values win for their names, except the variables the launcher sets itself and those that describe your terminal, such as `TERM` and `COLUMNS`.
- **Shell variables:** Proxy or certificate variables that aren't in `environment.env` come from the environment that runs the launcher.
- **Storage:** Nothing is written to disk. Stopping the runtime closes the socket, so a launcher run after stop can't start Pi.

## Attachment File

After the runtime is ready, it publishes an owner-only `interfaces/tui.json` attachment file. It shares `version`, `mode`, and `workspace` with the Hermes adapter's `tui.json`. Its `launcher` mode names the launcher, the runtime ID, Pi's agent and session directories, and the environment socket instead of a backend port and token. The launcher refuses to start without it, or with one that another runtime of the agent published at the same path.

## Open a Terminal TUI

The runtime writes the launcher at `interfaces/terminal` in its Pi directory: `<artifact root>/.fabric/pi/runtimes/<runtime-id>`, or the agent's state folder with `runtime.keep_state`. Run it from an interactive terminal as the user that runs the runtime. In an OpenShell sandbox, run it with:

```bash
openshell sandbox exec -n SANDBOX --tty -- <launcher path>
```

The launcher passes Pi's own arguments through. Its flags reproduce the SDK session's isolation and tool policy, and it loads NeMo Fabric module tools through a generated extension, so each terminal TUI loads them in its own process.

Each launch starts a new conversation. Pass `--continue`, `--session <path|id>`, or `--resume`, or use `/resume`, to open a saved one. `--continue` opens the most recent conversation in `pi-sessions`, which can be one another terminal TUI is still writing. Pi doesn't lock conversation files, so two writers on one conversation interleave their entries; use `--resume` or `/resume` to pick a conversation. With [`runtime.keep_state`](./pi.mdx#keep-state-across-runtimes), conversations from earlier runtimes of the agent, including SDK runtimes, are listed too.

Quitting a terminal TUI ends only that `pi` process; the runtime and any other terminal TUIs keep running, and the conversation stays in `pi-sessions`.

### Credentials

Credentials entered in the terminal TUI, for example with `/login`, are saved in the runtime's agent directory, which stays after the runtime stops and, with `runtime.keep_state`, serves later runtimes of the agent. A login saved for the configured provider lasts only until the next start, which removes it so the runtime's key applies; logins for other providers stay. Supply keys through the runtime's environment instead.

## Relay

With NeMo Relay telemetry enabled, the launcher loads the Relay Pi extension on the runtime's Relay gateway, so Relay captures each terminal TUI as its own session, with its own trajectory. Terminal output is native; it is not a normalized NeMo Fabric `RunResult`.

## Stop and Health

Each terminal TUI registers itself, with its process identity, in `interfaces/tui.clients` before it fetches the runtime's environment, and closes itself when `tui.json` disappears or names another runtime. A terminal TUI that can't identify or register itself closes instead of running unmanaged.

Stopping the runtime:

1. Removes `tui.json` and closes the environment socket.
2. Sends SIGTERM to each registered terminal TUI's process group, and SIGKILL to any still running 5 seconds later. A suspended terminal TUI is stopped too.

Stop signals only processes whose recorded identity it verifies, and checks again before each signal, so a reused process ID isn't signalled. If it can't verify a terminal TUI, a signal is denied, or a terminal TUI still runs 2 seconds after SIGKILL (for example, while it waits on a slow disk), stop keeps its registration and fails with `pi_interface_cleanup_incomplete`, so a retried stop can try again. When more than one cleanup step fails, stop fails with `pi_interface_cleanup_failed` and lists each cause. In an OpenShell sandbox, which denies process-group signals, only the terminal TUI's own process is signalled.

For a terminal TUI runtime, `active` and `ready` health checks also require the launcher and `interfaces/tui.json`, and passing checks report `unknown` activity, as for Hermes. `ready` also loads `models.json` as it is at each check, as a new terminal TUI would, and requires the selected model to resolve from it.

## Try It and Review Limitations

Use the [Pi interface example](../../../../examples/interfaces/pi/README.md) to open a terminal TUI by hand or run a scripted demo across two kept-state runtimes. Read the [shared limitations](./pi.mdx#limitations-and-planned-work).

- Processes that a terminal TUI's tools start can outlive the runtime in an OpenShell sandbox, because process-group signals are denied there ([#568](https://github.com/NVIDIA/NeMo-Fabric/issues/568)).
- Terminal TUI conversations aren't collected as NeMo Fabric artifacts yet.
- Terminal TUIs share the runtime's filesystem and tools; separate conversations do not provide user isolation.
Loading
Loading