diff --git a/crates/nemoclaw-e2e/cases/docker-openclaw-hermes-interfaces.yaml b/crates/nemoclaw-e2e/cases/docker-openclaw-hermes-interfaces.yaml index bd3330550ab..369d04327bc 100644 --- a/crates/nemoclaw-e2e/cases/docker-openclaw-hermes-interfaces.yaml +++ b/crates/nemoclaw-e2e/cases/docker-openclaw-hermes-interfaces.yaml @@ -2,16 +2,19 @@ # SPDX-License-Identifier: Apache-2.0 # OpenClaw's Control UI and Hermes's API server and dashboard behind a managed -# Docker gateway, on a stub model that answers every chat completion with the -# same reply, followed by the skills whose markers the request holds, and -# refuses any request without the run's key. Apply reports each interface; a -# person reaches it with the pinned OpenShell CLI's forward and the token -# apply names. cargo ci live-docker gives each run a fresh identity, gateway -# port and subnet, stub address, volume names, and agent images. Only claw -# grants python3 the stub's /health, which the managed inference grant leaves -# out. Each agent's skills.directories lists a writable folder of skills and +# Docker gateway, on a stub model that answers every chat completion and +# Anthropic Messages request with the same reply, followed by the skills whose +# markers the request holds, and refuses any request without the run's key. +# A second Hermes agent, in hermes-messages, reaches the stub through an +# anthropic provider: Hermes calls the Messages API, and the provider places +# the key in x-api-key. Apply reports each interface; a person reaches it with +# the pinned OpenShell CLI's forward and the token apply names. cargo ci +# live-docker gives each run a fresh identity, gateway port and subnet, stub +# address, volume names, and agent images. Only claw grants python3 the +# stub's /health, which the managed inference grant leaves out. The claw and +# hermes agents' skills.directories each list a writable folder of skills and # a skill on its own volume, read-only for claw and writable for hermes, and -# refuses duplicate names; Hermes's folder is empty. +# refuse duplicate names; Hermes's folder is empty. apiVersion: nemoclaw.nvidia.com/v1alpha1 kind: NemoClawConfig metadata: @@ -36,6 +39,17 @@ spec: endpoint: http://172.30.123.1:17699/v1 credential: env: NEMOCLAW_TEST_INTERFACES_MODEL_KEY + # The stub serves the Messages API under /anthropic, as Anthropic-compatible + # gateways do. Hermes calls https://api.anthropic.com instead of an + # anthropic provider's endpoint unless the endpoint's host is an + # Anthropic, Claude, or Azure host or its path ends in /anthropic or + # /anthropic/v1. + messages: + provider: anthropic + api: anthropic-messages + endpoint: http://172.30.123.1:17699/anthropic/v1 + credential: + env: NEMOCLAW_TEST_INTERFACES_MODEL_KEY sandboxes: claw: image: @@ -125,3 +139,22 @@ spec: providerRef: model overrides: model: fixture-model + hermes-messages: + image: + ref: nc-fabric-hermes@sha256:0000000000000000000000000000000000000000000000000000000000000000 + network: + tier: isolated + harness: + kind: nvidia.fabric.hermes + settings: + interfaces: + api: + port: 8642 + agent: + name: hermes-messages + inference: + routes: + - name: primary + providerRef: messages + overrides: + model: fixture-model diff --git a/crates/nemoclaw-e2e/tests/e2e/hcl/model/main.tf b/crates/nemoclaw-e2e/tests/e2e/hcl/model/main.tf index 1879b90f046..41606049ebc 100644 --- a/crates/nemoclaw-e2e/tests/e2e/hcl/model/main.tf +++ b/crates/nemoclaw-e2e/tests/e2e/hcl/model/main.tf @@ -1,14 +1,17 @@ # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# A stub OpenAI-compatible model for a Docker case, run with the bundled -# Docker provider on the case's engine before its first apply: the pinned -# nginx-unprivileged image the development issuer runs, on the host network -# at the port the case's `model` provider names. It lists one model and -# answers every chat completion with `reply`, streamed when the request asks, -# followed by the name of each of `markers` that the request holds, so a -# test can see what an agent sent the model. It refuses any request without -# `Authorization: Bearer KEY`. The test runner removes it after the case. +# A stub model for a Docker case, run with the bundled Docker provider on the +# case's engine before its first apply: the pinned nginx-unprivileged image +# the development issuer runs, on the host network at the port the case's +# `model` provider names. It lists one model and answers every OpenAI chat +# completion, and every Anthropic Messages request at /anthropic/v1/messages +# as Anthropic-compatible gateways serve them, with `reply`, streamed when the +# request asks, followed by the name of each of `markers` that the request +# holds, so a test can see what an agent sent the model. It refuses a +# Messages request without `x-api-key: KEY`, where Anthropic's API takes the +# key, and any other request without `Authorization: Bearer KEY`. The test +# runner removes it after the case. terraform { required_version = "= 1.13.9" @@ -33,7 +36,7 @@ variable "key" { } variable "reply" { - description = "The text that starts every completion." + description = "The text that starts every completion and message." type = string # nginx puts the reply in a header and in the completion's JSON unescaped. validation { @@ -43,7 +46,7 @@ variable "reply" { } variable "markers" { - description = "By name, text to look for in each chat completion request. The completion names each marker its request holds, in name order, after the reply." + description = "By name, text to look for in each chat completion or Messages request. The completion or message names each marker its request holds, in name order, after the reply." type = map(string) default = {} # nginx matches the text as a regular expression and puts the name in the @@ -94,7 +97,41 @@ locals { choices = [{ index = 0, delta = chunk.delta, finish_reason = chunk.finish }] }, chunk.usage == null ? {} : { usage = chunk.usage }))}\\n\\n" ], ["data: [DONE]\\n\\n"])) - # The request body selects a streamed reply and the completion's text. nginx + # A Messages reply, and the events that stream it. + message = jsonencode({ + id = "msg_nemoclaw_stub" + type = "message" + role = "assistant" + model = "fixture-model" + content = [{ type = "text", text = "$http_x_reply" }] + stop_reason = "end_turn" + stop_sequence = null + usage = { input_tokens = 1, output_tokens = 1 } + }) + events = [ + { + type = "message_start" + message = { + id = "msg_nemoclaw_stub" + type = "message" + role = "assistant" + model = "fixture-model" + content = [] + stop_reason = null + stop_sequence = null + usage = { input_tokens = 1, output_tokens = 0 } + } + }, + { type = "content_block_start", index = 0, content_block = { type = "text", text = "" } }, + { type = "content_block_delta", index = 0, delta = { type = "text_delta", text = "$http_x_reply" } }, + { type = "content_block_stop", index = 0 }, + { type = "message_delta", delta = { stop_reason = "end_turn", stop_sequence = null }, usage = { output_tokens = 1 } }, + { type = "message_stop" }, + ] + message_stream = join("", [ + for event in local.events : "event: ${event.type}\\ndata: ${jsonencode(event)}\\n\\n" + ]) + # The request body selects a streamed reply and the reply's text. nginx # reads the body before it sends the proxied request, so the second server # sees both as headers. config = <<-EOT @@ -116,7 +153,9 @@ locals { ${local.marker_maps} server { listen ${local.port}; - if ($http_authorization != "Bearer ${var.key}") { return 401; } + set $credential $http_authorization; + if ($uri = /anthropic/v1/messages) { set $credential "Bearer $http_x_api_key"; } + if ($credential != "Bearer ${var.key}") { return 401; } location = /v1/models { default_type application/json; return 200 '${local.models}'; @@ -128,6 +167,13 @@ locals { proxy_set_header X-Reply "${local.text}"; proxy_pass http://unix:/tmp/stub.sock:/completion; } + location = /anthropic/v1/messages { + client_body_buffer_size 1m; + client_body_in_single_buffer on; + proxy_set_header X-Reply-Kind $reply_kind; + proxy_set_header X-Reply "${local.text}"; + proxy_pass http://unix:/tmp/stub.sock:/message; + } location / { return 404; } } server { @@ -141,6 +187,15 @@ locals { default_type text/event-stream; return 200 '${local.stream}'; } + location = /message { + if ($http_x_reply_kind = stream) { rewrite ^ /message-stream last; } + default_type application/json; + return 200 '${local.message}'; + } + location = /message-stream { + default_type text/event-stream; + return 200 '${local.message_stream}'; + } } } EOT diff --git a/crates/nemoclaw-e2e/tests/e2e/hcl/tests/docker-openclaw-hermes-interfaces.tftest.hcl b/crates/nemoclaw-e2e/tests/e2e/hcl/tests/docker-openclaw-hermes-interfaces.tftest.hcl index 65ba1ee54c5..418b85fe9e3 100644 --- a/crates/nemoclaw-e2e/tests/e2e/hcl/tests/docker-openclaw-hermes-interfaces.tftest.hcl +++ b/crates/nemoclaw-e2e/tests/e2e/hcl/tests/docker-openclaw-hermes-interfaces.tftest.hcl @@ -10,7 +10,12 @@ # it. OpenClaw's terminal UI, opened with the dashboard's token through # `openshell sandbox exec --tty`, shows the stub's reply to a prompt and exits # on Ctrl-D. The stub refuses requests without the run's key, so the reply -# also shows NemoClaw sent the configured key. In each sandbox, +# also shows NemoClaw sent the configured key. In hermes-messages, whose +# agent reaches the stub through an anthropic provider, Hermes's API server +# answers a chat completion with the stub's reply too; the stub accepts a +# Messages request's key only in x-api-key, so the reply shows that Hermes +# called Anthropic's Messages API with the key where the provider places it. +# In claw and hermes, # the agent's user can write and read a file in the agent's workspace, and # the key is not in the environment a command sees. In hermes, a command can # open a pseudo-terminal, as browser chat does. In claw, python3 reaches @@ -95,6 +100,7 @@ run "apply" { "claw/dashboard/18789/token_in_url_fragment/true", "hermes/api/8642/bearer_token/true", "hermes/dashboard/9119/none/false", + "hermes-messages/api/8642/bearer_token/true", ]) error_message = "Apply must report each interface with its port, sign-in, and token file." } @@ -140,6 +146,18 @@ run "interfaces" { } answer = "nemoclaw-stub-reply notes" } + # This agent has no skills, so the reply names none. + messages_chat = { + sandbox = "hermes-messages" + port = 8642 + token_path = one([for access in run.apply.result.interfaces : access.tokenPath if access.sandbox == "hermes-messages"]) + path = "/v1/chat/completions" + body = { + model = "hermes-agent" + messages = [{ role = "user", content = "Reply to this NemoClaw live test." }] + } + answer = "nemoclaw-stub-reply" + } dashboard = { sandbox = "hermes" port = 9119 diff --git a/image/fabric/Dockerfile b/image/fabric/Dockerfile index b1496bcb3ed..9460262e698 100644 --- a/image/fabric/Dockerfile +++ b/image/fabric/Dockerfile @@ -146,6 +146,8 @@ COPY --from=hermes-assets --chmod=0644 /sources/hermes.tar.gz /opt/nemoclaw/sour COPY --from=switchyard-assets /opt/nemo-relay /opt/nemo-relay # Hermes owns its dependencies: its own lock, with the mcp extra, settles the # packages it shares with Fabric, as Fabric installs into Hermes's environment. +# Hermes needs the anthropic extra's SDK to call a model through an anthropic +# provider, and can't install it later because lazy installs are disabled. # From the messaging extra, only aiohttp, which Hermes's API server needs, is # installed; the messaging platform clients are pruned. # Hermes's lock overrides some dependencies' requirements, such as @@ -154,7 +156,7 @@ COPY --from=switchyard-assets /opt/nemo-relay /opt/nemo-relay # check failures those overrides cause, as Hermes's installer does. # Hermes resolves bundled assets relative to its source checkout. RUN --mount=from=uv,source=/uv,target=/usr/local/bin/uv --mount=type=cache,target=/root/.cache/uv \ - uv export --project /opt/hermes --frozen --no-dev --extra mcp --extra messaging \ + uv export --project /opt/hermes --frozen --no-dev --extra anthropic --extra mcp --extra messaging \ --prune discord-py --prune python-telegram-bot --prune slack-bolt --prune slack-sdk --prune qrcode --prune brotlicffi \ --no-emit-project --format requirements-txt --output-file /opt/nemoclaw/source/hermes-requirements.txt \ && uv pip install --python /opt/fabric/bin/python --require-hashes --no-deps -r /opt/nemoclaw/source/hermes-requirements.txt \ diff --git a/internal-docs/contributing/live-tests.md b/internal-docs/contributing/live-tests.md index fc306d60136..6850cdbada9 100644 --- a/internal-docs/contributing/live-tests.md +++ b/internal-docs/contributing/live-tests.md @@ -124,7 +124,7 @@ Run blocks call these modules: | `docker-openclaw-vllm` | Live / HCL, NVIDIA GPU runner | OpenClaw on a [vLLM model](#generic-models) the deployment serves; any reply. | | `docker-openclaw-vllm-shared` | Live / HCL, NVIDIA GPU runner | Two OpenClaw agents sharing one vLLM model with bearer authentication; any reply from each. | | `docker-openclaw-hermes-ollama` | Live / HCL, NVIDIA GPU runner | OpenClaw on NVIDIA hosted inference, `FOUR`; Hermes on a managed Ollama model, any reply. | -| `docker-openclaw-hermes-interfaces` | `cargo ci live-docker` | OpenClaw's Control UI and Hermes's API server and dashboard through the reported forward and token, and OpenClaw's terminal UI through `openshell sandbox exec --tty`, on a stub model that requires the run's key, with replies that name the skills each harness offers from its mounted volumes, and Hermes's dashboard opening a skill as its volume holds it; in each sandbox, a writable workspace, skill volumes that are writable or read-only as mounted, and no model key in the environment; in Hermes's sandbox, a pseudo-terminal; in OpenClaw's sandbox, a granted endpoint reached and an undeclared host refused ([Agent Interfaces](#agent-interfaces)). | +| `docker-openclaw-hermes-interfaces` | `cargo ci live-docker` | OpenClaw's Control UI and Hermes's API server and dashboard through the reported forward and token, and OpenClaw's terminal UI through `openshell sandbox exec --tty`, on a stub model that requires the run's key, with replies that name the skills each harness offers from its mounted volumes, and Hermes's dashboard opening a skill as its volume holds it; a second Hermes agent's API server answering through an `anthropic` provider, which sends the key in `x-api-key`; in OpenClaw's sandbox and the first Hermes sandbox, a writable workspace, skill volumes that are writable or read-only as mounted, and no model key in the environment; in that Hermes sandbox, a pseudo-terminal; in OpenClaw's sandbox, a granted endpoint reached and an undeclared host refused ([Agent Interfaces](#agent-interfaces)). | | `docker-dummy` | `cargo ci live-docker` | The [dummy agent](#dummy-agent-lifecycle); its configured reply before and after a redeploy that reuses the gateway's storage, a workspace file on a named volume that survives the destroy and redeploy, and sandbox requests that an external middleware allows, denies, fails on (blocked by the fail-closed binding), or, for an excluded destination, never sees. | | `kind-kubernetes-development` | `cargo ci live-kind` | One agent with the default [kubernetes runtime and development authentication profiles on kind](#kubernetes-gateway-without-the-helm-cli), applied with no `PATH`; it answers with the stub's reply before and after a redeploy that reuses the gateway's storage, and its sandbox's explicit policy lets `python3` reach the stub's `/health` and refuses an undeclared in-cluster address. | | `kind-kubernetes-oidc` | `cargo ci live-kind` | Two agents [on kind](#kubernetes-gateway-without-the-helm-cli) in a namespace with OpenShift's UID range, from a private registry's image, behind a gateway that accepts an existing OIDC issuer's tokens and that the chart's NodePort Service publishes at the node's address; apply goes through the port-forward, and each agent answers the stub's reply through the published address. | @@ -290,21 +290,23 @@ To run the scenario by hand, bind the template the same way and follow [HCL E2E The `docker-openclaw-hermes-interfaces` [HCL E2E scenario](#hcl-e2e-scenarios) deploys OpenClaw's Control UI and Hermes's API server and dashboard through one managed Docker gateway, and reaches them as [Reach an Agent Interface](../../docs/agents-inference/interfaces.md#reach-an-agent-interface) describes. `cargo ci live-docker` runs it: it installs the pinned OpenShell CLI by checksum, binds the case to a fresh UID, gateway port and subnet, stub address, and the run's OpenClaw and Hermes images, and passes a fresh model key as `NEMOCLAW_TEST_INTERFACES_MODEL_KEY` and `TF_VAR_model_key`. Before apply, the `tests/e2e/hcl/model` module runs a stub model with the bundled Docker provider: the pinned `nginx-unprivileged` image that the development issuer runs, on the host network at the port the case's `model` provider names. -It lists one model and answers every chat completion with the same reply, streamed when the request asks, and refuses any request without that key. +It lists one model and answers every OpenAI chat completion, and every Anthropic Messages request at `/anthropic/v1/messages`, as Anthropic-compatible gateways serve them, with the same reply, streamed when the request asks. +It refuses a Messages request without that key in `x-api-key`, where Anthropic's API takes it, and any other request without it as a bearer credential. Each skill's description is a marker, and the reply ends with the name of each skill whose marker the request holds. -The `tests/e2e/hcl/volume` module also creates each sandbox's two skills volumes, named for the run's UID, and writes their skills, owned by the agent image's user. -Each agent's `skills.directories` lists a writable folder of skills on one volume and one skill on another, and refuses duplicate names, as [Skills on a Mounted Volume](../../docs/agents-inference/agents.md#skills-on-a-mounted-volume) describes; OpenClaw's skill volume is read-only and Hermes's writable, OpenClaw's folder holds two skills and a file that isn't one, and Hermes's folder is empty. -Apply must start both agents with them, and report each interface's port, sign-in, and token file. +The `tests/e2e/hcl/volume` module also creates two skills volumes each for the `claw` and `hermes` sandboxes, named for the run's UID, and writes their skills, owned by the agent image's user. +Each of those agents' `skills.directories` lists a writable folder of skills on one volume and one skill on another, and refuses duplicate names, as [Skills on a Mounted Volume](../../docs/agents-inference/agents.md#skills-on-a-mounted-volume) describes; OpenClaw's skill volume is read-only and Hermes's writable, OpenClaw's folder holds two skills and a file that isn't one, and Hermes's folder is empty. +A third sandbox, `hermes-messages`, runs a second Hermes agent without skills, whose route reaches the same stub through an `anthropic` provider at `/anthropic/v1`: Hermes uses an `anthropic` provider's endpoint only when its host is an Anthropic, Claude, or Azure host or its path ends in `/anthropic` or `/anthropic/v1`, and calls `https://api.anthropic.com` otherwise. +Apply must start the three agents, and report each interface's port, sign-in, and token file. A harness offers the model the skills it finds, so each reply below must name the skills on that agent's volumes: `notes` for Hermes, and `digest`, `review`, and `translate` for OpenClaw. Whether the agent loads and follows a skill is not checked live; Fabric's tests check what each harness loads. The `tests/e2e/hcl/interface` module then runs `hcl_live::interface` once per request: it reads the reported token with `openshell sandbox exec`, forwards the port with `openshell forward service`, and sends one request with the token as a Bearer credential. Hermes's dashboard has no token file, so for a request that needs its session token, the probe first loads the page and reads the token from it, as a browser does. -OpenClaw's Control UI page must load and its configuration endpoint must accept the token; Hermes's API server must list its models and answer a chat completion with the stub's reply and its skill, which also shows that NemoClaw sent the configured key; Hermes's dashboard page must load with its session token, and with that token the dashboard's skill editor must open `notes` exactly as its volume holds it, at the volume's path. +OpenClaw's Control UI page must load and its configuration endpoint must accept the token; Hermes's API server must list its models and answer a chat completion with the stub's reply and its skill, which also shows that NemoClaw sent the configured key; the second Hermes agent's API server must answer a chat completion with the stub's reply alone, which shows that Hermes called the Messages API with the key in `x-api-key`, where the `anthropic` provider places it; Hermes's dashboard page must load with its session token, and with that token the dashboard's skill editor must open `notes` exactly as its volume holds it, at the volume's path. Reports hold status codes; tokens and response bodies stay in the run's private `work` directory. The `tests/e2e/hcl/terminal` module then runs `hcl_live::terminal`, which opens OpenClaw's terminal UI as [OpenClaw's Terminal UI](../../docs/agents-inference/interfaces.md#openclaws-terminal-ui) describes: it reads the dashboard's token with `openshell sandbox exec`, runs `openshell sandbox exec --tty -- openclaw tui --url ws://127.0.0.1:18789 --token TOKEN` in a pseudo-terminal, waits for the `connected | idle` status, and types a prompt, then Enter on its own, because a terminal UI reads a prompt and Enter that arrive together as a paste. The stub's reply, naming OpenClaw's skills, must appear, and the command must exit 0 after Ctrl-D. The report holds those results and the exit status; the screen output and the token stay in `work`. -Then the `tests/e2e/hcl/command` module runs three commands in each sandbox: one writes a marker file in `/sandbox/workspace`, the workspace that the SDK's Fabric configuration sets, and reads it back as the agent image's user, UID 10001; one lists the environment, which must include the variable that the sandbox reads the model registration's key from, `NEMOCLAW_INFERENCE_MODEL_..._KEY`, but not the run's model key; and one creates a file in each of the sandbox's skill volumes, which every volume must accept except OpenClaw's read-only review skill, which must refuse it with `EROFS`. +Then the `tests/e2e/hcl/command` module runs three commands in each of the `claw` and `hermes` sandboxes: one writes a marker file in `/sandbox/workspace`, the workspace that the SDK's Fabric configuration sets, and reads it back as the agent image's user, UID 10001; one lists the environment, which must include the variable that the sandbox reads the model registration's key from, `NEMOCLAW_INFERENCE_MODEL_..._KEY`, but not the run's model key; and one creates a file in each of the sandbox's skill volumes, which every volume must accept except OpenClaw's read-only review skill, which must refuse it with `EROFS`. Two more commands in OpenClaw's sandbox check its network policy with `python3`, which the images have instead of curl. Each sandbox's managed inference grant already gives the image's executables, `python3` among them, the model's `/v1/**` paths, so only OpenClaw's document also grants `python3` the stub's `/health`. A request there must get the stub's 401, which shows that it reached the stub; without the grant, OpenShell's proxy answers 403.