Skip to content
Merged
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
2 changes: 1 addition & 1 deletion agents/langchain-deepagents-code/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ RUN test -f /usr/local/bin/nemoclaw-managed-bootstrap \
&& cmp -s /usr/local/lib/nemoclaw/dcode-launcher.sh /usr/local/lib/nemoclaw/dcode-managed-exec \
&& chmod -R a+rX /opt/nemoclaw-blueprint \
&& test "$(find /opt/nemoclaw-deepagents-profile-plugin -type f -print | LC_ALL=C sort)" = "$(printf '%s\n' '/opt/nemoclaw-deepagents-profile-plugin/pyproject.toml' '/opt/nemoclaw-deepagents-profile-plugin/src/nemoclaw_deepagents_profile/__init__.py')" \
&& printf '%s %s\n' '6bb8dc8108c5dd7e7f71c39aacfb0da07d285b7a324eecd691177a9ca460cfc0' '/opt/nemoclaw-deepagents-profile-plugin/src/nemoclaw_deepagents_profile/__init__.py' '7be3f7972d7cd78d3ddaf66e2ff8b07a5e6af3611034b956cf0475ba78f5a576' '/opt/nemoclaw-deepagents-profile-plugin/pyproject.toml' | sha256sum -c - \
&& printf '%s %s\n' '97eaed5781f9c7df4478c96263b0742fb545b322846fe0c73c39a3bfba4553a9' '/opt/nemoclaw-deepagents-profile-plugin/src/nemoclaw_deepagents_profile/__init__.py' '7be3f7972d7cd78d3ddaf66e2ff8b07a5e6af3611034b956cf0475ba78f5a576' '/opt/nemoclaw-deepagents-profile-plugin/pyproject.toml' | sha256sum -c - \
&& /opt/venv/bin/pip3 install --no-index --no-cache-dir --no-deps --no-build-isolation /opt/nemoclaw-deepagents-profile-plugin \
&& /opt/venv/bin/python3 -I -c 'import nemoclaw_deepagents_profile; print("NEMOCLAW_DCODE_PROFILE_" + "IMPORT_GATE", flush=True); import deepagents; import deepagents_code' \
&& /opt/venv/bin/pip3 check \
Expand Down
55 changes: 44 additions & 11 deletions agents/langchain-deepagents-code/dependency-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ NemoClaw no longer vendors or overlays that source.
- Native profile SHA-256: `3b95b118e90c4ae19890c611cc7e1e85261217f971496e9bb7508142133c7d9a`
- Unmodified built-in bootstrap SHA-256: `005a91e7fc4ca6b21220673dd9d02d6686bf63e1e4f1102d124b01f96886efcf`
- First-party adapter: `nemoclaw-deepagents-profile==0.1.0`
- Adapter module SHA-256: `6bb8dc8108c5dd7e7f71c39aacfb0da07d285b7a324eecd691177a9ca460cfc0`
- Adapter module SHA-256: `97eaed5781f9c7df4478c96263b0742fb545b322846fe0c73c39a3bfba4553a9`
- Adapter project metadata SHA-256: `7be3f7972d7cd78d3ddaf66e2ff8b07a5e6af3611034b956cf0475ba78f5a576`
- Adapter wheel license expression: `Apache-2.0`
- Adapter dependency audit result: `No known vulnerabilities found`. Its only
Expand Down Expand Up @@ -189,17 +189,19 @@ without consulting an index. Its `deepagents.harness_profiles` entry
point runs after built-in profiles are registered, reads the reviewed canonical
profile through one exact-version/hash-gated private registry lookup, and uses
Deep Agents' public registration API to map it to the two exact `openai:` model
keys used by NemoClaw's managed OpenAI-compatible `ChatOpenAI` route. It layers
one first-party middleware onto those aliases that rejects only a
case-insensitive `[content]` value, with optional whitespace around the token
and brackets, passed as the complete `execute` command;
the canonical NVIDIA profile and unrelated models remain unchanged. The
released SDK has no public profile getter or alias API. The adapter does not add
keys used by NemoClaw's managed OpenAI-compatible `ChatOpenAI` route. It adds one
first-party middleware that rejects only a case-insensitive `[content]` value,
with optional whitespace around the token and brackets, passed as the complete
`execute` command. It also replaces the native policy-nudge instance at the
same middleware position on the OpenAI aliases. The adapted instance removes
`nemotron_` control names only from copied provider requests. OpenRouter retains
the native nudge and the managed execute guard. The canonical NVIDIA profile
and unrelated models remain unchanged. The released SDK has no public profile getter or alias API. The adapter does not add
a provider-wide OpenAI profile.

### Managed Ultra compatibility workarounds

Two localized behaviors close separate invalid states on the managed Ultra
Four localized behaviors close separate invalid states on the managed Ultra
aliases. They are not a new provider profile and do not modify the reviewed
canonical NVIDIA profile.

Expand All @@ -215,6 +217,18 @@ The focused profile-plugin suite extracts the identifiers from every production
consumer and requires the exact sets to match, preventing drift without adding
another mutable build artifact.

For OpenAI prompt-cache affinity, Deep Agents Code `0.1.55` defaults
`models.openai_prompt_cache_key` to enabled for every model whose provider
resolves to `openai`, including compatible endpoints. It adds the thread ID as
a top-level `prompt_cache_key`. NVIDIA Endpoints rejects that OpenAI-specific
field. The managed package patch overrides the upstream config decision to
false, so `ConfigurableModelMiddleware` does not inject the field. The provider
request otherwise remains unchanged. Focused generated-package tests and the
isolated image validator require the opt-out. The live DCode E2E proves the
managed request returns assistant text. Remove the override only after NVIDIA
Endpoints accepts `prompt_cache_key` or a reviewed Deep Agents release scopes
the default by endpoint capability.

For `force_nonempty_content`, the invalid state originates in the NVIDIA Ultra
chat template/serving path: a Chat Completions response that combines reasoning
and tool calls can otherwise carry empty assistant content. That response shape
Expand All @@ -235,6 +249,24 @@ produces nonempty assistant content for reasoning-plus-tool-call turns without
it, and the live DCode Ultra E2E passes for both managed model IDs with both
supply points deleted.

For internal control names, the invalid state originates in the managed
OpenAI-compatible request path. The native Ultra profile inserts local
`HumanMessage` controls with `nemotron_` names. NVIDIA Endpoints accepts the
streaming HTTP request but returns an in-stream bad-request event instead of
assistant text when those names reach its chat template. Deep Agents then wraps
the event in `RemoteException`, so managed `dcode -n` exits 1 with no response
(#10549). Deep Agents merges middleware overrides by exact type, so the adapter
wraps a new native policy-nudge instance and replaces the original at the same
position for OpenAI aliases. OpenRouter aliases retain the native policy nudge. The wrapper repairs the request after the native nudge runs. It clears
only copied `nemotron_` names and preserves content, graph-state metadata,
user-supplied names, plain messages, the canonical profile, and unrelated
models. Focused fixture tests and the isolated image validator cover sync and
async calls, graph-state preservation, unrelated-message identity, and the
native appended nudge. The Deep Agents E2E repeats the installed contract. Remove this
middleware only after a reviewed NVIDIA serving-template or Deep Agents update
accepts the named native controls through the managed `ChatOpenAI` route and
the live non-interactive E2E passes without the adapter.

For the `[content]` guard, the invalid state is a model-produced tool call whose
complete `execute.command` is the placeholder, ignoring case and whitespace
around the token and brackets. The released Deep Agents parser/profile can carry that
Expand Down Expand Up @@ -265,9 +297,10 @@ upstream release moves the registry out of process. The image validator runs
under isolated Python, verifies the installed entry-point metadata and adapter
source hash before the upstream source checks, checks both upstream files again
after profile loading,
resolves the complete native middleware plus the managed guard for both aliases,
proves the canonical middleware remains unchanged, compiles a graph, exercises
sync and async placeholder rejection, proves concrete-command and parser/native
resolves the complete native middleware with the adapted policy nudge plus the
managed guard for both aliases, proves the canonical middleware remains
unchanged, compiles a graph, exercises sync and async message-name repair and placeholder rejection,
proves graph-state and unrelated-message preservation, concrete-command, and parser/native
dispatch parity through the actual graph, and confirms an unrelated OpenAI model
receives no Ultra behavior. The Docker build separately imports the adapter,
Deep Agents, and DCode under isolated Python immediately after installation;
Expand Down
15 changes: 15 additions & 0 deletions agents/langchain-deepagents-code/patch-managed-deepagents-code.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ def _parse_interpreter_ptc(raw):
return False


# Deep Agents Code 0.1.55 enables OpenAI prompt-cache affinity for every
# ChatOpenAI-compatible endpoint. NVIDIA Endpoints rejects that OpenAI-specific
# request field. Disable its dynamic injection at the final config boundary so
# managed non-interactive calls retain only supported request fields (#10549).
def is_openai_prompt_cache_key_enabled() -> bool:
return False


# Managed Ultra compatibility workaround: the NVIDIA Ultra serving template can
# return empty assistant content when a completion combines reasoning and tool
# calls, so managed Ultra requests must carry this reviewed template argument.
Expand Down Expand Up @@ -863,6 +871,7 @@ def _run_single_hook(command, event, payload_bytes) -> None:

import httpx as _nemoclaw_httpx
from deepagents_code import model_config as _nemoclaw_model_config
from langgraph.pregel import remote as _nemoclaw_langgraph_remote
from langgraph_sdk import errors as _nemoclaw_langgraph_errors

# NemoClaw-managed Deep Agents Code hardening v2.
Expand All @@ -871,6 +880,11 @@ def _run_single_hook(command, event, payload_bytes) -> None:
# `repr(exception)`, which application code can replace through `__repr__`.
# Checkpoint text is therefore not a trustworthy error-type source.
_NEMOCLAW_EXCEPTION_CLASSIFIERS = {
_nemoclaw_langgraph_remote.RemoteException: (
"RemoteError",
"agent_remote_failure",
"false",
),
_nemoclaw_langgraph_errors.RateLimitError: (
"RateLimited",
"rate_limited",
Expand Down Expand Up @@ -1951,6 +1965,7 @@ def main() -> None:
f"Managed package {boundary} patch is partial in {paths['agent']}"
)
for name, patch in (
("config", CONFIG_PATCH),
("entrypoint", ENTRYPOINT_PATCH),
("main", MAIN_PATCH),
("tools", TOOLS_PATCH),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
from collections.abc import Awaitable, Callable, MutableMapping
from pathlib import Path
from types import MethodType
from typing import Any

EXPECTED_DCODE_VERSION = "0.1.55"
Expand Down Expand Up @@ -112,13 +113,68 @@ def _require_source(path: Path, label: str, expected_sha256: str) -> None:
compile(source, str(path), "exec")


def _managed_profile_overlay() -> Any:
def _managed_profile_overlay(*, repair_names: bool) -> Any:
"""Build the NemoClaw-only middleware layered onto managed Ultra aliases."""
from deepagents.profiles.harness._nvidia_nemotron_3_ultra import ( # noqa: PLC0415
NemotronPolicyNudgeMiddleware,
)
from deepagents.profiles.harness.harness_profiles import ( # noqa: PLC0415
HarnessProfile,
)
from langchain.agents.middleware.types import AgentMiddleware # noqa: PLC0415
from langchain_core.messages import ToolMessage # noqa: PLC0415
from langchain_core.messages import HumanMessage, ToolMessage # noqa: PLC0415

def without_internal_names(request: Any) -> Any:
messages = list(request.messages or ())
repaired = []
changed = False
for message in messages:
name = getattr(message, "name", None)
if (
isinstance(message, HumanMessage)
and isinstance(name, str)
and name.startswith("nemotron_")
):
message = message.model_copy(update={"name": None})
changed = True
repaired.append(message)
return request.override(messages=repaired) if changed else request

# The native Ultra nudge inserts local `nemotron_` message names. NVIDIA's
# OpenAI-compatible stream accepts those messages, then returns an in-stream
# BadRequest instead of assistant text. Replace the exact native instance at
# its existing profile position. The wrapper preserves named graph state and
# removes only copied provider-request metadata (#10549).
policy_nudge = NemotronPolicyNudgeMiddleware()
original_wrap_model_call = policy_nudge.wrap_model_call
original_awrap_model_call = policy_nudge.awrap_model_call

def wrap_model_call(
self: Any,
request: Any,
handler: Callable[[Any], Any],
) -> Any:
del self
return original_wrap_model_call(
request,
lambda value: handler(without_internal_names(value)),
)

async def awrap_model_call(
self: Any,
request: Any,
handler: Callable[[Any], Awaitable[Any]],
) -> Any:
del self

async def repaired_handler(value: Any) -> Any:
return await handler(without_internal_names(value))

return await original_awrap_model_call(request, repaired_handler)

policy_nudge.wrap_model_call = MethodType(wrap_model_call, policy_nudge)
policy_nudge.awrap_model_call = MethodType(awrap_model_call, policy_nudge)
policy_nudge._nemoclaw_internal_name_compatibility = True

class NemoClawExecutePlaceholderGuardMiddleware(AgentMiddleware):
"""Reject Ultra's literal execute placeholder before shell dispatch."""
Expand Down Expand Up @@ -171,64 +227,78 @@ async def awrap_tool_call(
return await handler(request)

return HarnessProfile(
extra_middleware=[NemoClawExecutePlaceholderGuardMiddleware()]
extra_middleware=[
*([policy_nudge] if repair_names else []),
NemoClawExecutePlaceholderGuardMiddleware(),
]
)


def _register_aliases(
registry: MutableMapping[str, Any],
register_profile: Callable[[str, Any], None],
overlay: Any,
openai_overlay: Any,
) -> None:
native_profile = registry.get(CANONICAL_PROFILE_KEY)
if native_profile is None:
raise _fail(f"canonical profile {CANONICAL_PROFILE_KEY!r} is not registered")

existing = tuple(key in registry for key in MANAGED_PROFILE_KEYS)
if all(existing):
managed_profile = registry[NATIVE_MANAGED_PROFILE_KEY]
native_middleware = tuple(getattr(native_profile, "extra_middleware", ()))
managed_middleware = tuple(getattr(managed_profile, "extra_middleware", ()))
preserves_native_middleware = (
len(managed_middleware) == len(native_middleware) + 1
and all(
managed_item is native_item
for managed_item, native_item in zip(
managed_middleware, native_middleware, strict=False
for key in MANAGED_PROFILE_KEYS:
managed_profile = registry[key]
middleware = tuple(getattr(managed_profile, "extra_middleware", ()))
repair_names = key.startswith("openai:")
preserves_native = len(middleware) == len(native_middleware) + 1 and all(
(
type(managed) is type(native)
and getattr(managed, "_nemoclaw_internal_name_compatibility", False)
)
if repair_names and type(native).__name__ == "NemotronPolicyNudgeMiddleware"
else managed is native
for managed, native in zip(middleware, native_middleware, strict=False)
)
)
guard = managed_middleware[-1] if preserves_native_middleware else None
if (
managed_profile is not native_profile
and all(registry[key] is managed_profile for key in MANAGED_PROFILE_KEYS)
and guard is not None
and type(guard).__name__
== "NemoClawExecutePlaceholderGuardMiddleware"
and type(guard).__module__ == __name__
):
return
raise _fail("managed aliases conflict with the reviewed managed profile")
guard = middleware[-1] if preserves_native else None
peer = MANAGED_ALIAS_KEYS[0] if repair_names else NATIVE_MANAGED_PROFILE_KEY
if not (
managed_profile is not native_profile
and managed_profile is registry[peer]
and guard is not None
and type(guard).__name__ == "NemoClawExecutePlaceholderGuardMiddleware"
and type(guard).__module__ == __name__
):
raise _fail("managed aliases conflict with the reviewed managed profile")
return
expected_native_state = (True, *(False for _key in MANAGED_ALIAS_KEYS))
if existing != expected_native_state:
raise _fail("managed aliases are in a partial registration state")
if registry[NATIVE_MANAGED_PROFILE_KEY] is not native_profile:
raise _fail("built-in OpenRouter profile does not match the canonical profile")

try:
# Deep Agents already registers the native Ultra profile for its exact
# OpenRouter model spec. Layer the NemoClaw guard onto that built-in key,
# then reuse the merged profile for the remaining managed aliases.
# Keep the native OpenRouter nudge; only OpenAI aliases need name repair.
register_profile(NATIVE_MANAGED_PROFILE_KEY, overlay)
managed_profile = registry.get(NATIVE_MANAGED_PROFILE_KEY)
if managed_profile is None or managed_profile is native_profile:
raise _fail("managed profile overlay was not applied")
for alias_key in MANAGED_ALIAS_KEYS:
register_profile(alias_key, managed_profile)
first_openai = MANAGED_ALIAS_KEYS[0]
register_profile(first_openai, native_profile)
register_profile(first_openai, openai_overlay)
openai_profile = registry[first_openai]
for alias_key in MANAGED_ALIAS_KEYS[1:]:
register_profile(
alias_key,
openai_profile if alias_key.startswith("openai:") else managed_profile,
)
if registry.get(CANONICAL_PROFILE_KEY) is not native_profile:
raise _fail("canonical profile changed during managed registration")
if not all(
registry.get(key) is managed_profile for key in MANAGED_PROFILE_KEYS
registry.get(key) is (
openai_profile if key.startswith("openai:") else managed_profile
)
for key in MANAGED_PROFILE_KEYS
):
raise _fail("managed alias registration did not preserve managed identity")
except Exception:
Expand Down Expand Up @@ -266,7 +336,8 @@ def register() -> None:
_register_aliases(
_HARNESS_PROFILES,
register_harness_profile,
_managed_profile_overlay(),
_managed_profile_overlay(repair_names=False),
_managed_profile_overlay(repair_names=True),
)


Expand Down
Loading
Loading