Repository navigation
docs: document Pi's terminal TUI and split the Pi guide #745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yczhang-nv
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
yczhang-nv:docs/pi-terminal-interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,633
−146
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5536dc8
docs: describe Pi's terminal TUI and kept state
yczhang-nv d2c4488
docs: split the Pi guide into overview, SDK and terminal TUI pages
yczhang-nv 5677879
docs: describe Pi stop's SIGKILL confirmation and the terminal ready …
yczhang-nv 553e9b3
docs: correct Pi guide details found in review
yczhang-nv bc62402
docs: pass the Pi execution-path harness to the shared FabricConfig
yczhang-nv c9cc6a9
docs: align the Pi guide with the Hermes and OpenClaw guides
yczhang-nv dcf8feb
docs: bind the Pi diagram's arrows and name NeMo Fabric
yczhang-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| 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. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.