Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ authentication, and execution details.
- **Profiles:** named variations of the base config. Use profiles to vary the
harness, model, MCP, tools, skills, telemetry, or environment context without
editing `agent.yaml`.
- **Tools policy:** use top-level `tools.blocked` for harness-neutral blocked
tool policy. Names are interpreted by the selected adapter:

```yaml
tools:
blocked:
- browser
- shell
```

Hermes maps these names to disabled toolsets, Claude maps them to
`disallowed_tools`, Deep Agents enforces them with middleware, and adapters
without a native deny mechanism route the policy as unsupported.
- **Adapters:** harness-specific integrations selected by `harness.adapter_id`.
The Hermes SDK and CLI adapters live under `adapters/hermes-sdk/` and
`adapters/hermes-cli/`; the Codex CLI adapter lives under
Expand Down
7 changes: 5 additions & 2 deletions adapters/claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ Configure portable capabilities through the normalized `FabricConfig` fields:
`provider="anthropic"`; normalized hosted/custom provider resolution is
tracked in [FABRIC-64](https://linear.app/nvidia/issue/FABRIC-64/add-normalized-model-provider-resolution-and-harness-compatibility).
- `environment.workspace` sets the Claude working directory.
- `tools` sets the base Claude tool list.
- `tools.blocked` maps to Claude `disallowed_tools` using Claude-native tool
names. Adapter-specific `harness.settings.disallowed_tools` remains supported;
when both are present, the effective deny-list is the union.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
- `mcp` configures stdio, HTTP, streamable HTTP, or SSE servers. For stdio,
Fabric parses `url` as a command plus arguments.
- `skills.paths` names skill directories that contain `SKILL.md`. The adapter
Expand Down Expand Up @@ -79,6 +81,7 @@ from nemo_fabric import (
ModelConfig,
RuntimeConfig,
SkillConfig,
ToolsConfig,
)

base_dir = Path("/workspace/review-agent")
Expand All @@ -102,7 +105,7 @@ config = FabricConfig(
},
runtime=RuntimeConfig(artifacts="./artifacts"),
environment=EnvironmentConfig(provider="local", workspace="."),
tools=["Read", "Glob", "Grep"],
tools=ToolsConfig(blocked=["WebFetch"]),
mcp=McpConfig(
servers={
"repo": McpServerConfig(
Expand Down
126 changes: 35 additions & 91 deletions adapters/claude/src/nemo_fabric_adapters/claude/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,23 @@
import os
import shlex
import shutil
from dataclasses import asdict, is_dataclass
from dataclasses import asdict
from dataclasses import is_dataclass
from hashlib import sha256
from pathlib import Path
from typing import Any

from claude_agent_sdk import (
CLIConnectionError,
CLIJSONDecodeError,
CLINotFoundError,
ClaudeAgentOptions,
ClaudeSDKError,
Message,
ProcessError,
ResultMessage,
query,
)
from claude_agent_sdk._errors import MessageParseError

import nemo_fabric_adapters.common.utils as common_utils

from claude_agent_sdk import ClaudeAgentOptions
from claude_agent_sdk import ClaudeSDKError
from claude_agent_sdk import CLIConnectionError
from claude_agent_sdk import CLIJSONDecodeError
from claude_agent_sdk import CLINotFoundError
from claude_agent_sdk import Message
from claude_agent_sdk import ProcessError
from claude_agent_sdk import ResultMessage
from claude_agent_sdk import query
from claude_agent_sdk._errors import MessageParseError

PERMISSION_MODES = {"default", "acceptEdits", "bypassPermissions", "plan", "dontAsk", "auto"}
SETTING_SOURCES = {"user", "project", "local"}
Expand Down Expand Up @@ -106,9 +103,7 @@ def _string_list(value: Any, *, name: str) -> list[str]:
if value is None:
return []
if not isinstance(value, list) or any(not isinstance(item, str) or not item for item in value):
raise AdapterConfigError(
"claude_invalid_configuration", f"{name} must be a list of non-empty strings"
)
raise AdapterConfigError("claude_invalid_configuration", f"{name} must be a list of non-empty strings")
return list(value)


Expand Down Expand Up @@ -190,9 +185,7 @@ def selected_model(payload: dict[str, Any]) -> str | None:


def _mcp_servers(payload: dict[str, Any]) -> dict[str, Any]:
native = _mapping(
common_utils.capability_plan(payload), name="capability_plan"
).get("native") or {}
native = _mapping(common_utils.capability_plan(payload), name="capability_plan").get("native") or {}
servers = _mapping(native, name="capability_plan.native").get("mcp_servers") or {}
result: dict[str, Any] = {}
for name, raw in sorted(_mapping(servers, name="native MCP servers").items()):
Expand All @@ -211,47 +204,22 @@ def _mcp_servers(payload: dict[str, Any]) -> dict[str, Any]:
elif transport == "sse":
result[name] = {"type": "sse", "url": url}
else:
raise AdapterConfigError(
"claude_invalid_configuration", f"unsupported MCP transport: {transport}"
)
raise AdapterConfigError("claude_invalid_configuration", f"unsupported MCP transport: {transport}")
return result


def _normalized_tools(
payload: dict[str, Any], *, include_skills: bool
) -> list[str] | dict[str, Any] | None:
native = _mapping(
common_utils.capability_plan(payload), name="capability_plan"
).get("native") or {}
if not _mapping(native, name="capability_plan.native").get("tools_configured"):
return None
tools = common_utils.fabric_config(payload).get("tools")
if tools is not None and not isinstance(tools, (list, dict)):
raise AdapterConfigError("claude_invalid_configuration", "tools is invalid")
if isinstance(tools, list):
normalized = _string_list(tools, name="tools")
if include_skills and "Skill" not in normalized:
normalized.append("Skill")
return normalized
if isinstance(tools, dict) and tools != {"type": "preset", "preset": "claude_code"}:
raise AdapterConfigError(
"claude_invalid_configuration",
"tools preset must be {'type': 'preset', 'preset': 'claude_code'}",
)
return tools
def _disallowed_tools(payload: dict[str, Any], settings: dict[str, Any]) -> list[str]:
return common_utils.merge_unique(
common_utils.blocked_tools(payload),
_string_list(settings.get("disallowed_tools"), name="disallowed_tools"),
)


def _native_skill_paths(payload: dict[str, Any]) -> list[Path]:
native = _mapping(
common_utils.capability_plan(payload), name="capability_plan"
).get("native") or {}
native = _mapping(common_utils.capability_plan(payload), name="capability_plan").get("native") or {}
values = _mapping(native, name="capability_plan.native").get("skill_paths") or []
if not isinstance(values, list) or any(
not isinstance(value, (str, Path)) for value in values
):
raise AdapterConfigError(
"claude_invalid_configuration", "native skill_paths must be a list of paths"
)
if not isinstance(values, list) or any(not isinstance(value, (str, Path)) for value in values):
raise AdapterConfigError("claude_invalid_configuration", "native skill_paths must be a list of paths")
return [_resolve_path(payload, value) for value in values]


Expand All @@ -270,9 +238,7 @@ def _stage_skill_plugin(payload: dict[str, Any]) -> list[dict[str, str]]:
)
name = skill_path.name
if name in names:
raise AdapterConfigError(
"claude_invalid_configuration", f"Fabric skill names must be unique: {name}"
)
raise AdapterConfigError("claude_invalid_configuration", f"Fabric skill names must be unique: {name}")
names.add(name)
skills.append((name, skill_path))

Expand Down Expand Up @@ -311,9 +277,7 @@ def build_options(payload: dict[str, Any], *, resume: str | None) -> ClaudeAgent
if permission_mode is not None and permission_mode not in PERMISSION_MODES:
raise AdapterConfigError("claude_invalid_configuration", "permission_mode is invalid")
max_turns = settings.get("max_turns")
if max_turns is not None and (
isinstance(max_turns, bool) or not isinstance(max_turns, int) or max_turns <= 0
):
if max_turns is not None and (isinstance(max_turns, bool) or not isinstance(max_turns, int) or max_turns <= 0):
raise AdapterConfigError("claude_invalid_configuration", "max_turns must be positive")
max_budget = settings.get("max_budget_usd")
if max_budget is not None:
Expand All @@ -336,9 +300,9 @@ def build_options(payload: dict[str, Any], *, resume: str | None) -> ClaudeAgent
cwd=resolve_cwd(payload),
model=selected_model(payload),
system_prompt=system_prompt,
tools=_normalized_tools(payload, include_skills=bool(plugins)),
tools=None,
allowed_tools=_string_list(settings.get("allowed_tools"), name="allowed_tools"),
disallowed_tools=_string_list(settings.get("disallowed_tools"), name="disallowed_tools"),
disallowed_tools=_disallowed_tools(payload, settings),
permission_mode=permission_mode,
max_turns=max_turns,
max_budget_usd=max_budget,
Expand Down Expand Up @@ -386,14 +350,10 @@ def load_claude_session_id(payload: dict[str, Any], fabric_runtime_id: str) -> s
raise ValueError("missing Claude session")
return session_id
except (OSError, ValueError, json.JSONDecodeError) as error:
raise AdapterStateError(
"claude_invalid_runtime_state", "Claude runtime state is invalid"
) from error
raise AdapterStateError("claude_invalid_runtime_state", "Claude runtime state is invalid") from error


def save_claude_session_id(
payload: dict[str, Any], fabric_runtime_id: str, claude_session_id: str
) -> None:
def save_claude_session_id(payload: dict[str, Any], fabric_runtime_id: str, claude_session_id: str) -> None:
if not claude_session_id:
raise AdapterStateError("claude_invalid_runtime_state", "Claude session ID is missing")
path = runtime_state_path(payload, fabric_runtime_id)
Expand Down Expand Up @@ -428,13 +388,9 @@ def normalize_message(message: Message) -> dict[str, Any]:
return {"type": type(message).__name__, "message": _json_safe(message)}


def normalize_result(
payload: dict[str, Any], messages: list[Message], result: ResultMessage
) -> dict[str, Any]:
def normalize_result(payload: dict[str, Any], messages: list[Message], result: ResultMessage) -> dict[str, Any]:
del payload
failed = bool(result.is_error) or (
isinstance(result.subtype, str) and result.subtype.startswith("error_")
)
failed = bool(result.is_error) or (isinstance(result.subtype, str) and result.subtype.startswith("error_"))
error = None
if failed:
error = {
Expand Down Expand Up @@ -504,22 +460,14 @@ def sdk_failure(error: BaseException) -> dict[str, Any]:

def child_environment(payload: dict[str, Any]) -> dict[str, str]:
values = {name: "" for name in os.environ}
values.update(
{
name: value
for name in INHERITED_ENV_NAMES
if (value := os.environ.get(name))
}
)
values.update({name: value for name in INHERITED_ENV_NAMES if (value := os.environ.get(name))})
model = _selected_model_config(payload)
api_key_env = model.get("api_key_env")
if isinstance(api_key_env, str) and api_key_env in os.environ:
values[api_key_env] = os.environ[api_key_env]
configured = _mapping(_settings(payload).get("env"), name="harness.settings.env")
if any(not isinstance(key, str) or not isinstance(value, str) for key, value in configured.items()):
raise AdapterConfigError(
"claude_invalid_configuration", "harness.settings.env must contain strings"
)
raise AdapterConfigError("claude_invalid_configuration", "harness.settings.env must contain strings")
values.update(configured)
return values

Expand Down Expand Up @@ -559,18 +507,14 @@ def run(payload: dict[str, Any]) -> dict[str, Any]:
except ClaudeAdapterError as error:
return adapter_failure(error)
except Exception: # Adapter boundary must always return normalized JSON.
return _failure(
"claude_adapter_internal_error", "Claude adapter failed unexpectedly"
)
return _failure("claude_adapter_internal_error", "Claude adapter failed unexpectedly")


def main() -> None:
try:
payload = common_utils.load_payload()
except Exception: # Malformed invocation input must still satisfy the process contract.
output = _failure(
"claude_adapter_internal_error", "Claude adapter failed unexpectedly"
)
output = _failure("claude_adapter_internal_error", "Claude adapter failed unexpectedly")
else:
output = run(payload)
print(json.dumps(output, sort_keys=True))
Expand Down
12 changes: 11 additions & 1 deletion adapters/common/src/nemo_fabric_adapters/common/hermes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def validate_hermes_telemetry_provider(payload: dict[str, Any]) -> None:
raise ValueError("only relay telemetry is supported for Hermes")


def disabled_toolsets(payload: dict[str, Any]) -> list[str]:
settings = common_utils.settings_payload(payload)
return common_utils.merge_unique(
common_utils.blocked_tools(payload),
settings.get("disabled_toolsets"),
)


def build_hermes_config(payload: dict[str, Any], *, relay_enabled: bool = False) -> dict[str, Any]:
settings = common_utils.settings_payload(payload)
model_config = selected_model_config(payload)
Expand All @@ -55,6 +63,7 @@ def build_hermes_config(payload: dict[str, Any], *, relay_enabled: bool = False)
provider = settings.get("provider") or model_config.get("provider")
base_url = get_base_url(settings, model_config)

blocked_toolsets = disabled_toolsets(payload)
config: dict[str, Any] = {
"model": without_none(
{
Expand All @@ -66,7 +75,7 @@ def build_hermes_config(payload: dict[str, Any], *, relay_enabled: bool = False)
"agent": without_none(
{
"max_turns": settings.get("max_iterations"),
"disabled_toolsets": settings.get("disabled_toolsets"),
"disabled_toolsets": blocked_toolsets or None,
}
),
"terminal": without_none(
Expand Down Expand Up @@ -144,6 +153,7 @@ def summarize_hermes_config(config: dict[str, Any]) -> dict[str, Any]:
"mcp_servers": sorted((config.get("mcp_servers") or {}).keys()),
"plugins": (config.get("plugins") or {}).get("enabled", []),
"platform_toolsets": config.get("platform_toolsets", {}),
"disabled_toolsets": (config.get("agent") or {}).get("disabled_toolsets", []),
}


Expand Down
23 changes: 20 additions & 3 deletions adapters/common/src/nemo_fabric_adapters/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def virtualenv_subprocess_env() -> dict[str, str]:
scripts = virtualenv / ("Scripts" if os.name == "nt" else "bin")
path = env.get("PATH")
env["VIRTUAL_ENV"] = str(virtualenv)
env["PATH"] = os.pathsep.join(
part for part in (str(scripts), path) if part
)
env["PATH"] = os.pathsep.join(part for part in (str(scripts), path) if part)
env.pop("PYTHONHOME", None)
return env

Expand Down Expand Up @@ -133,6 +131,16 @@ def capability_plan(payload: dict[str, Any]) -> dict[str, Any]:
return payload.get("capability_plan") or payload.get("capabilities") or {}


def tools_config(payload: dict[str, Any]) -> dict[str, Any]:
tools = fabric_config(payload).get("tools") or {}
return tools if isinstance(tools, dict) else {}


def blocked_tools(payload: dict[str, Any]) -> list[str]:
blocked = tools_config(payload).get("blocked")
return normalize_list(blocked)


def normalize_list(value: Any) -> list[str]:
if value is None:
return []
Expand All @@ -143,6 +151,15 @@ def normalize_list(value: Any) -> list[str]:
return [str(item) for item in value if str(item)]


def merge_unique(*values: Any) -> list[str]:
merged: list[str] = []
for value in values:
for item in normalize_list(value):
if item not in merged:
merged.append(item)
return merged


def dump_yaml(value: dict[str, Any]) -> str:
try:
import yaml
Expand Down
13 changes: 5 additions & 8 deletions adapters/deepagents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ Fabric maps the following into the harness:
- Configured MCP servers are loaded as Deep Agents tools via
`langchain-mcp-adapters`. A misconfigured server (non-mapping, empty target,
unsupported transport) is a normalized configuration failure, not a silent drop.
- `tools` (Fabric's `config.tools` allow-list) is enforced by a gating middleware
across the full tool surface — Deep Agents built-ins (including `task`), MCP
tools, and **delegated subagents** alike; tool calls whose name is not on the
list are blocked, so tools routed through the `task` tool cannot run ungated. A
non-list `tools` value is a normalized configuration failure rather than a
silently disabled allow-list.
- `tools.blocked` is enforced by middleware across the full tool surface — Deep
Agents built-ins (including `task`), MCP tools, and **delegated subagents**
alike. Use Deep Agents/native tool names in the blocked list.
- `harness.settings.deepagents` forwards a small set of **documented,
JSON-serializable** `create_deep_agent` options (currently `subagents` and
`interrupt_on`). It is not a general Python-object escape hatch: the SDK config
Expand All @@ -72,7 +69,7 @@ Fabric maps the following into the harness:

Deep Agents can delegate to subagents through its built-in `task` tool. Subagents
**inherit** the parent run's model, tools, skills, workspace, telemetry, and
permissions — in particular, the parent `config.tools` allow-list applies to
permissions — in particular, the parent `tools.blocked` policy applies to
delegated execution, so a subagent cannot broaden capabilities beyond the parent.
Independently configured subagent tools, skills, models, MCP servers, middleware,
or permissions are **not** exposed through the Fabric SDK yet; a `subagents`
Expand All @@ -85,7 +82,7 @@ per-step events, LangGraph thread id, token usage (and cost when the provider
reports it), and errors. Usage aggregates the current turn across the main agent
and any delegated subagents (streamed with `subgraphs=True`). Configuration and
preflight failures (a missing credential, an absent `deepagents` package, an
invalid allow-list, MCP server, or passthrough option) are returned as a
invalid MCP server, or passthrough option) are returned as a
normalized failure result rather than a raw traceback.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

## Runtime Modes
Expand Down
Loading
Loading