nemo-fabric-adapters-openhands 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nemo_fabric_adapters/openhands/__init__.py +4 -0
- nemo_fabric_adapters/openhands/adapter.py +485 -0
- nemo_fabric_adapters_openhands-0.5.0.data/data/share/nemo-fabric/adapters/openhands/openhands.fabric-adapter.json +64 -0
- nemo_fabric_adapters_openhands-0.5.0.dist-info/METADATA +43 -0
- nemo_fabric_adapters_openhands-0.5.0.dist-info/RECORD +8 -0
- nemo_fabric_adapters_openhands-0.5.0.dist-info/WHEEL +5 -0
- nemo_fabric_adapters_openhands-0.5.0.dist-info/licenses/LICENSE +203 -0
- nemo_fabric_adapters_openhands-0.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""OpenHands SDK adapter for NVIDIA NeMo Fabric."""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import importlib.util
|
|
10
|
+
import os
|
|
11
|
+
import tempfile
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
from typing import NamedTuple
|
|
15
|
+
|
|
16
|
+
from nemo_fabric_adapter_contract import models as contract
|
|
17
|
+
from nemo_fabric_adapters.common import instructions as common_instructions
|
|
18
|
+
from nemo_fabric_adapters.common import lifecycle
|
|
19
|
+
from nemo_fabric_adapters.common import utils as common_utils
|
|
20
|
+
|
|
21
|
+
HARNESS = "OpenHands"
|
|
22
|
+
DEFAULT_MAX_ITERATIONS = 500
|
|
23
|
+
TOOL_ALIASES = {
|
|
24
|
+
"terminal": "terminal",
|
|
25
|
+
"bash": "terminal",
|
|
26
|
+
"file_editor": "file_editor",
|
|
27
|
+
"edit": "file_editor",
|
|
28
|
+
}
|
|
29
|
+
REMOTE_MCP_TRANSPORTS = {
|
|
30
|
+
"http": "http",
|
|
31
|
+
"streamable-http": "streamable-http",
|
|
32
|
+
"streamable_http": "streamable-http",
|
|
33
|
+
"sse": "sse",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class OpenHandsApi(NamedTuple):
|
|
38
|
+
Agent: Any
|
|
39
|
+
AgentContext: Any
|
|
40
|
+
Conversation: Any
|
|
41
|
+
ConversationExecutionStatus: Any
|
|
42
|
+
LLM: Any
|
|
43
|
+
MCPServer: Any
|
|
44
|
+
SecretStr: Any
|
|
45
|
+
Skill: Any
|
|
46
|
+
Tool: Any
|
|
47
|
+
TerminalTool: Any
|
|
48
|
+
FileEditorTool: Any
|
|
49
|
+
get_agent_final_response: Any
|
|
50
|
+
default_condenser: Any
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _load_openhands_api() -> OpenHandsApi:
|
|
54
|
+
try:
|
|
55
|
+
available = importlib.util.find_spec("openhands.sdk") is not None
|
|
56
|
+
except ModuleNotFoundError:
|
|
57
|
+
available = False
|
|
58
|
+
if not available:
|
|
59
|
+
raise lifecycle.LifecycleError(
|
|
60
|
+
"openhands_harness_unavailable",
|
|
61
|
+
"OpenHands is not installed; install compatible openhands-sdk and "
|
|
62
|
+
"openhands-tools packages.",
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
from pydantic import SecretStr
|
|
66
|
+
|
|
67
|
+
from openhands.sdk import Agent
|
|
68
|
+
from openhands.sdk import AgentContext
|
|
69
|
+
from openhands.sdk import ConversationExecutionStatus
|
|
70
|
+
from openhands.sdk import LLM
|
|
71
|
+
from openhands.sdk import Tool
|
|
72
|
+
from openhands.sdk.context.condenser import default_condenser
|
|
73
|
+
from openhands.sdk.conversation import get_agent_final_response
|
|
74
|
+
from openhands.sdk.conversation.impl.local_conversation import LocalConversation
|
|
75
|
+
from openhands.sdk.mcp import MCPServer
|
|
76
|
+
from openhands.sdk.skills import Skill
|
|
77
|
+
from openhands.tools.file_editor import FileEditorTool
|
|
78
|
+
from openhands.tools.terminal import TerminalTool
|
|
79
|
+
|
|
80
|
+
return OpenHandsApi(
|
|
81
|
+
Agent=Agent,
|
|
82
|
+
AgentContext=AgentContext,
|
|
83
|
+
Conversation=LocalConversation,
|
|
84
|
+
ConversationExecutionStatus=ConversationExecutionStatus,
|
|
85
|
+
LLM=LLM,
|
|
86
|
+
MCPServer=MCPServer,
|
|
87
|
+
SecretStr=SecretStr,
|
|
88
|
+
Skill=Skill,
|
|
89
|
+
Tool=Tool,
|
|
90
|
+
TerminalTool=TerminalTool,
|
|
91
|
+
FileEditorTool=FileEditorTool,
|
|
92
|
+
get_agent_final_response=get_agent_final_response,
|
|
93
|
+
default_condenser=default_condenser,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _selected_model(config: contract.AgentConfig) -> contract.AgentModelConfig:
|
|
98
|
+
model = config.models.get("default")
|
|
99
|
+
if model is None and len(config.models) == 1:
|
|
100
|
+
model = next(iter(config.models.values()))
|
|
101
|
+
if model is None:
|
|
102
|
+
raise lifecycle.LifecycleError(
|
|
103
|
+
"openhands_model_required",
|
|
104
|
+
"OpenHands requires a default model or exactly one configured model.",
|
|
105
|
+
)
|
|
106
|
+
return model
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _llm(api: OpenHandsApi, model: contract.AgentModelConfig) -> Any:
|
|
110
|
+
wire_model = (
|
|
111
|
+
model.model if "/" in model.model else f"{model.provider}/{model.model}"
|
|
112
|
+
)
|
|
113
|
+
kwargs: dict[str, Any] = {"model": wire_model, "usage_id": "agent"}
|
|
114
|
+
if model.api_key_env is not None:
|
|
115
|
+
api_key = os.environ.get(model.api_key_env)
|
|
116
|
+
if not api_key:
|
|
117
|
+
raise lifecycle.LifecycleError(
|
|
118
|
+
"openhands_credential_missing",
|
|
119
|
+
f"The model credential environment variable "
|
|
120
|
+
f"{model.api_key_env!r} is not set.",
|
|
121
|
+
)
|
|
122
|
+
kwargs["api_key"] = api.SecretStr(api_key)
|
|
123
|
+
if model.base_url is not None:
|
|
124
|
+
kwargs["base_url"] = model.base_url
|
|
125
|
+
if model.temperature is not None:
|
|
126
|
+
kwargs["temperature"] = model.temperature
|
|
127
|
+
if model.top_p is not None:
|
|
128
|
+
kwargs["top_p"] = model.top_p
|
|
129
|
+
if model.max_tokens is not None:
|
|
130
|
+
kwargs["max_output_tokens"] = model.max_tokens
|
|
131
|
+
return api.LLM(**kwargs)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _condenser_enabled(config: contract.AgentConfig) -> bool:
|
|
135
|
+
"""Return whether to condense history, rejecting values the descriptor forbids.
|
|
136
|
+
|
|
137
|
+
Planning already validates the setting, but a host that skips planning must
|
|
138
|
+
not turn an unknown value into model-billed summarization calls.
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
settings = config.harness.settings if config.harness is not None else {}
|
|
142
|
+
condenser = settings.get("condenser", "default")
|
|
143
|
+
if condenser not in ("default", "none"):
|
|
144
|
+
raise lifecycle.LifecycleError(
|
|
145
|
+
"openhands_condenser_invalid",
|
|
146
|
+
"The OpenHands condenser setting must be 'default' or 'none'.",
|
|
147
|
+
)
|
|
148
|
+
return condenser == "default"
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _workspace(context: contract.RuntimeContext, base_dir: str) -> Path:
|
|
152
|
+
path = Path(context.environment.workspace or base_dir)
|
|
153
|
+
if not path.is_absolute():
|
|
154
|
+
path = Path(base_dir) / path
|
|
155
|
+
path = path.resolve()
|
|
156
|
+
if not path.is_dir():
|
|
157
|
+
raise lifecycle.LifecycleError(
|
|
158
|
+
"openhands_workspace_invalid",
|
|
159
|
+
f"The OpenHands workspace is not a directory: {path}",
|
|
160
|
+
)
|
|
161
|
+
return path
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _skill_paths(config: contract.AgentConfig, base_dir: str) -> list[Path]:
|
|
165
|
+
paths: list[Path] = []
|
|
166
|
+
for value in config.skills.paths if config.skills is not None else []:
|
|
167
|
+
path = Path(value)
|
|
168
|
+
if not path.is_absolute():
|
|
169
|
+
path = Path(base_dir) / path
|
|
170
|
+
path = path.resolve()
|
|
171
|
+
if not path.is_dir() or not (path / "SKILL.md").is_file():
|
|
172
|
+
raise lifecycle.LifecycleError(
|
|
173
|
+
"openhands_skill_invalid",
|
|
174
|
+
"An OpenHands skill path must be a directory containing "
|
|
175
|
+
f"SKILL.md: {path}",
|
|
176
|
+
)
|
|
177
|
+
paths.append(path)
|
|
178
|
+
return paths
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _skills(
|
|
182
|
+
api: OpenHandsApi, config: contract.AgentConfig, base_dir: str
|
|
183
|
+
) -> list[Any]:
|
|
184
|
+
skills: list[Any] = []
|
|
185
|
+
names: set[str] = set()
|
|
186
|
+
for path in _skill_paths(config, base_dir):
|
|
187
|
+
try:
|
|
188
|
+
skill = api.Skill.load(path / "SKILL.md", strict=True, skip_mcp=True)
|
|
189
|
+
except Exception as error:
|
|
190
|
+
raise lifecycle.LifecycleError(
|
|
191
|
+
"openhands_skill_invalid",
|
|
192
|
+
f"OpenHands could not load the configured skill at {path}.",
|
|
193
|
+
) from error
|
|
194
|
+
if skill.name in names:
|
|
195
|
+
raise lifecycle.LifecycleError(
|
|
196
|
+
"openhands_skill_duplicate",
|
|
197
|
+
f"OpenHands skill names must be unique: {skill.name!r}.",
|
|
198
|
+
)
|
|
199
|
+
names.add(skill.name)
|
|
200
|
+
skills.append(skill)
|
|
201
|
+
return skills
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def _tools(api: OpenHandsApi, config: contract.AgentConfig) -> list[Any]:
|
|
205
|
+
enabled = config.tools.enabled if config.tools is not None else None
|
|
206
|
+
blocked_names = set(config.tools.blocked if config.tools is not None else [])
|
|
207
|
+
selected = ["terminal", "file_editor"] if enabled is None else enabled
|
|
208
|
+
|
|
209
|
+
native: list[str] = []
|
|
210
|
+
unknown: list[str] = []
|
|
211
|
+
blocked: set[str] = set()
|
|
212
|
+
for name in blocked_names:
|
|
213
|
+
canonical = TOOL_ALIASES.get(name)
|
|
214
|
+
if canonical is None:
|
|
215
|
+
unknown.append(name)
|
|
216
|
+
else:
|
|
217
|
+
blocked.add(canonical)
|
|
218
|
+
for name in selected:
|
|
219
|
+
canonical = TOOL_ALIASES.get(name)
|
|
220
|
+
if canonical is None:
|
|
221
|
+
unknown.append(name)
|
|
222
|
+
elif canonical not in blocked and canonical not in native:
|
|
223
|
+
native.append(canonical)
|
|
224
|
+
if unknown:
|
|
225
|
+
raise lifecycle.LifecycleError(
|
|
226
|
+
"openhands_tool_unsupported",
|
|
227
|
+
f"OpenHands does not support configured tool name {sorted(set(unknown))[0]!r}; "
|
|
228
|
+
f"supported names: {', '.join(sorted(TOOL_ALIASES))}.",
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
classes = {
|
|
232
|
+
"terminal": api.TerminalTool,
|
|
233
|
+
"file_editor": api.FileEditorTool,
|
|
234
|
+
}
|
|
235
|
+
return [api.Tool(name=classes[name].name) for name in native]
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _mcp_servers(api: OpenHandsApi, config: contract.AgentConfig) -> dict[str, Any]:
|
|
239
|
+
result: dict[str, Any] = {}
|
|
240
|
+
if config.mcp is None:
|
|
241
|
+
return result
|
|
242
|
+
if config.mcp.extensions:
|
|
243
|
+
raise lifecycle.LifecycleError(
|
|
244
|
+
"openhands_mcp_configuration_unsupported",
|
|
245
|
+
"OpenHands does not support MCP configuration extensions.",
|
|
246
|
+
)
|
|
247
|
+
servers = config.mcp.servers
|
|
248
|
+
for name, server in servers.items():
|
|
249
|
+
if server.extensions:
|
|
250
|
+
raise lifecycle.LifecycleError(
|
|
251
|
+
"openhands_mcp_configuration_unsupported",
|
|
252
|
+
f"OpenHands does not support extensions for MCP server {name!r}.",
|
|
253
|
+
)
|
|
254
|
+
if server.authentication is not None:
|
|
255
|
+
raise lifecycle.LifecycleError(
|
|
256
|
+
"openhands_mcp_auth_unsupported",
|
|
257
|
+
f"MCP authentication is not supported for server {name!r}.",
|
|
258
|
+
)
|
|
259
|
+
if server.allowed_tools is not None or server.blocked_tools:
|
|
260
|
+
raise lifecycle.LifecycleError(
|
|
261
|
+
"openhands_mcp_tool_policy_unsupported",
|
|
262
|
+
f"Per-server MCP tool policy is not supported for server {name!r}.",
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
transport = server.transport.strip().lower()
|
|
266
|
+
target = os.path.expandvars(server.url).strip()
|
|
267
|
+
if not target:
|
|
268
|
+
raise lifecycle.LifecycleError(
|
|
269
|
+
"openhands_mcp_target_invalid",
|
|
270
|
+
f"MCP server {name!r} must have a non-empty URL or command.",
|
|
271
|
+
)
|
|
272
|
+
if transport in {"stdio", "command", "process"}:
|
|
273
|
+
if server.custom_headers:
|
|
274
|
+
raise lifecycle.LifecycleError(
|
|
275
|
+
"openhands_mcp_configuration_unsupported",
|
|
276
|
+
f"OpenHands stdio MCP server {name!r} does not support "
|
|
277
|
+
"custom_headers.",
|
|
278
|
+
)
|
|
279
|
+
result[name] = api.MCPServer(
|
|
280
|
+
transport="stdio",
|
|
281
|
+
command=target,
|
|
282
|
+
args=server.args,
|
|
283
|
+
env=server.env or None,
|
|
284
|
+
)
|
|
285
|
+
continue
|
|
286
|
+
native_transport = REMOTE_MCP_TRANSPORTS.get(transport)
|
|
287
|
+
if native_transport is None:
|
|
288
|
+
raise lifecycle.LifecycleError(
|
|
289
|
+
"openhands_mcp_transport_unsupported",
|
|
290
|
+
f"MCP server {name!r} has unsupported transport {server.transport!r}.",
|
|
291
|
+
)
|
|
292
|
+
if server.args or server.env:
|
|
293
|
+
raise lifecycle.LifecycleError(
|
|
294
|
+
"openhands_mcp_configuration_unsupported",
|
|
295
|
+
f"OpenHands remote MCP server {name!r} does not support args or env.",
|
|
296
|
+
)
|
|
297
|
+
headers = None
|
|
298
|
+
if server.custom_headers:
|
|
299
|
+
try:
|
|
300
|
+
headers = common_utils.expand_http_headers(name, server.custom_headers)
|
|
301
|
+
except Exception as error:
|
|
302
|
+
raise lifecycle.LifecycleError(
|
|
303
|
+
"openhands_mcp_header_invalid",
|
|
304
|
+
f"MCP headers are invalid for server {name!r}.",
|
|
305
|
+
) from error
|
|
306
|
+
result[name] = api.MCPServer(
|
|
307
|
+
transport=native_transport,
|
|
308
|
+
url=target,
|
|
309
|
+
headers=headers,
|
|
310
|
+
)
|
|
311
|
+
return result
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def _usage(api_llm: Any, baseline: Any) -> contract.AgentUsage | None:
|
|
315
|
+
metrics = api_llm.metrics.diff(baseline)
|
|
316
|
+
tokens = metrics.accumulated_token_usage
|
|
317
|
+
if tokens is None:
|
|
318
|
+
return None
|
|
319
|
+
input_tokens = int(tokens.prompt_tokens)
|
|
320
|
+
output_tokens = int(tokens.completion_tokens)
|
|
321
|
+
return contract.AgentUsage(
|
|
322
|
+
input_tokens=input_tokens,
|
|
323
|
+
output_tokens=output_tokens,
|
|
324
|
+
total_tokens=input_tokens + output_tokens,
|
|
325
|
+
cost_usd=float(metrics.accumulated_cost),
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
class OpenHandsRuntime:
|
|
330
|
+
def __init__(self) -> None:
|
|
331
|
+
self._api: OpenHandsApi | None = None
|
|
332
|
+
self._llm_instance: Any = None
|
|
333
|
+
self._conversation: Any = None
|
|
334
|
+
self._profile_store_temp: tempfile.TemporaryDirectory[str] | None = None
|
|
335
|
+
self._runtime_id: str | None = None
|
|
336
|
+
|
|
337
|
+
async def start(self, payload: dict[str, Any]) -> None:
|
|
338
|
+
config: contract.AgentConfig = payload["config"]
|
|
339
|
+
context = contract.RuntimeContext.from_mapping(payload.get("runtime_context"))
|
|
340
|
+
base_dir = common_utils.base_dir(payload)
|
|
341
|
+
instruction = common_instructions.system_instruction(
|
|
342
|
+
config,
|
|
343
|
+
adapter=HARNESS,
|
|
344
|
+
supported_modes={"replace", "append"},
|
|
345
|
+
)
|
|
346
|
+
api = _load_openhands_api()
|
|
347
|
+
llm = _llm(api, _selected_model(config))
|
|
348
|
+
agent_context = api.AgentContext(
|
|
349
|
+
skills=_skills(api, config, base_dir),
|
|
350
|
+
system_message_suffix=(
|
|
351
|
+
instruction.content
|
|
352
|
+
if instruction is not None and instruction.mode == "append"
|
|
353
|
+
else None
|
|
354
|
+
),
|
|
355
|
+
load_user_skills=False,
|
|
356
|
+
load_public_skills=False,
|
|
357
|
+
load_project_skills=False,
|
|
358
|
+
load_memory=False,
|
|
359
|
+
)
|
|
360
|
+
agent_kwargs: dict[str, Any] = {
|
|
361
|
+
"llm": llm,
|
|
362
|
+
"tools": _tools(api, config),
|
|
363
|
+
"mcp_config": _mcp_servers(api, config),
|
|
364
|
+
"agent_context": agent_context,
|
|
365
|
+
}
|
|
366
|
+
if _condenser_enabled(config):
|
|
367
|
+
# Share the agent LLM instead of a copy so summarization calls
|
|
368
|
+
# accrue to the metrics that invoke() reports as usage.
|
|
369
|
+
agent_kwargs["condenser"] = api.default_condenser(llm)
|
|
370
|
+
if instruction is not None and instruction.mode == "replace":
|
|
371
|
+
agent_kwargs["system_prompt"] = instruction.content
|
|
372
|
+
agent = api.Agent(**agent_kwargs)
|
|
373
|
+
profile_store_temp = tempfile.TemporaryDirectory(
|
|
374
|
+
prefix="nemo-fabric-openhands-"
|
|
375
|
+
)
|
|
376
|
+
try:
|
|
377
|
+
conversation = api.Conversation(
|
|
378
|
+
agent=agent,
|
|
379
|
+
workspace=str(_workspace(context, base_dir)),
|
|
380
|
+
max_iteration_per_run=(
|
|
381
|
+
config.runtime.max_turns
|
|
382
|
+
if config.runtime is not None
|
|
383
|
+
and config.runtime.max_turns is not None
|
|
384
|
+
else DEFAULT_MAX_ITERATIONS
|
|
385
|
+
),
|
|
386
|
+
persistence_dir=None,
|
|
387
|
+
profile_store_dir=profile_store_temp.name,
|
|
388
|
+
delete_on_close=True,
|
|
389
|
+
visualizer=None,
|
|
390
|
+
)
|
|
391
|
+
except BaseException:
|
|
392
|
+
profile_store_temp.cleanup()
|
|
393
|
+
raise
|
|
394
|
+
self._api = api
|
|
395
|
+
self._llm_instance = llm
|
|
396
|
+
self._conversation = conversation
|
|
397
|
+
self._profile_store_temp = profile_store_temp
|
|
398
|
+
self._runtime_id = context.runtime_id
|
|
399
|
+
|
|
400
|
+
async def invoke(
|
|
401
|
+
self,
|
|
402
|
+
request: contract.AgentRunRequest,
|
|
403
|
+
context: contract.RuntimeContext,
|
|
404
|
+
) -> contract.AgentRunResult:
|
|
405
|
+
if (
|
|
406
|
+
self._api is None
|
|
407
|
+
or self._llm_instance is None
|
|
408
|
+
or self._conversation is None
|
|
409
|
+
):
|
|
410
|
+
raise lifecycle.LifecycleError(
|
|
411
|
+
"openhands_not_started", "The OpenHands runtime is not started."
|
|
412
|
+
)
|
|
413
|
+
if context.runtime_id != self._runtime_id:
|
|
414
|
+
raise lifecycle.LifecycleError(
|
|
415
|
+
"openhands_runtime_mismatch",
|
|
416
|
+
"OpenHands invocation does not match the active runtime.",
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
conversation = self._conversation
|
|
420
|
+
event_count = len(conversation.state.events)
|
|
421
|
+
baseline = self._llm_instance.metrics.deep_copy()
|
|
422
|
+
try:
|
|
423
|
+
conversation.send_message(common_utils.normalize_user_input(request.input))
|
|
424
|
+
await conversation.arun()
|
|
425
|
+
except Exception:
|
|
426
|
+
return contract.AgentRunResult(
|
|
427
|
+
status=contract.AgentRunStatus.FAILED,
|
|
428
|
+
output=None,
|
|
429
|
+
error=contract.AgentRunError(
|
|
430
|
+
code="openhands_invocation_failed",
|
|
431
|
+
message="OpenHands could not complete the invocation.",
|
|
432
|
+
),
|
|
433
|
+
usage=_usage(self._llm_instance, baseline),
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
status = conversation.state.execution_status
|
|
437
|
+
new_events = conversation.state.events[event_count:]
|
|
438
|
+
response = self._api.get_agent_final_response(new_events)
|
|
439
|
+
usage = _usage(self._llm_instance, baseline)
|
|
440
|
+
if status != self._api.ConversationExecutionStatus.FINISHED:
|
|
441
|
+
return contract.AgentRunResult(
|
|
442
|
+
status=contract.AgentRunStatus.FAILED,
|
|
443
|
+
output=None,
|
|
444
|
+
error=contract.AgentRunError(
|
|
445
|
+
code=f"openhands_{str(status.value).replace('-', '_')}",
|
|
446
|
+
message=f"OpenHands ended the invocation with status {status.value!r}.",
|
|
447
|
+
),
|
|
448
|
+
usage=usage,
|
|
449
|
+
)
|
|
450
|
+
if not response:
|
|
451
|
+
return contract.AgentRunResult(
|
|
452
|
+
status=contract.AgentRunStatus.FAILED,
|
|
453
|
+
output=None,
|
|
454
|
+
error=contract.AgentRunError(
|
|
455
|
+
code="openhands_no_assistant_response",
|
|
456
|
+
message="OpenHands completed without an assistant response.",
|
|
457
|
+
),
|
|
458
|
+
usage=usage,
|
|
459
|
+
)
|
|
460
|
+
return contract.AgentRunResult(
|
|
461
|
+
status=contract.AgentRunStatus.SUCCEEDED,
|
|
462
|
+
output={"response": response},
|
|
463
|
+
usage=usage,
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
async def stop(self) -> None:
|
|
467
|
+
conversation, self._conversation = self._conversation, None
|
|
468
|
+
profile_store_temp, self._profile_store_temp = self._profile_store_temp, None
|
|
469
|
+
self._api = None
|
|
470
|
+
self._llm_instance = None
|
|
471
|
+
self._runtime_id = None
|
|
472
|
+
try:
|
|
473
|
+
if conversation is not None:
|
|
474
|
+
conversation.close()
|
|
475
|
+
finally:
|
|
476
|
+
if profile_store_temp is not None:
|
|
477
|
+
profile_store_temp.cleanup()
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def main() -> None:
|
|
481
|
+
lifecycle.serve(OpenHandsRuntime, config_loader=contract.AgentConfig.from_mapping)
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
if __name__ == "__main__":
|
|
485
|
+
main()
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contract_version": "fabric.adapter/v1alpha2",
|
|
3
|
+
"adapter_id": "nvidia.fabric.openhands",
|
|
4
|
+
"adapter_kind": "python",
|
|
5
|
+
"runner": {
|
|
6
|
+
"module": "nemo_fabric_adapters.openhands.adapter"
|
|
7
|
+
},
|
|
8
|
+
"model_schema": {
|
|
9
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"provider": {"type": "string", "minLength": 1},
|
|
13
|
+
"model": {"type": "string", "minLength": 1},
|
|
14
|
+
"temperature": {"type": "number", "minimum": 0},
|
|
15
|
+
"top_p": {"type": "number", "minimum": 0, "maximum": 1},
|
|
16
|
+
"max_tokens": {"type": "integer", "minimum": 1},
|
|
17
|
+
"api_key_env": {"type": "string", "minLength": 1},
|
|
18
|
+
"base_url": {"type": "string", "minLength": 1},
|
|
19
|
+
"settings": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {},
|
|
22
|
+
"additionalProperties": false
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"required": ["provider", "model"],
|
|
26
|
+
"additionalProperties": false
|
|
27
|
+
},
|
|
28
|
+
"settings_schema": {
|
|
29
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
30
|
+
"type": "object",
|
|
31
|
+
"properties": {
|
|
32
|
+
"condenser": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"enum": ["default", "none"],
|
|
35
|
+
"default": "default",
|
|
36
|
+
"description": "OpenHands conversation history condenser. Use none to keep the full history."
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"additionalProperties": false
|
|
40
|
+
},
|
|
41
|
+
"requirements": {},
|
|
42
|
+
"config": {
|
|
43
|
+
"accepts": [
|
|
44
|
+
"models",
|
|
45
|
+
"models.base_url",
|
|
46
|
+
"models.temperature",
|
|
47
|
+
"models.top_p",
|
|
48
|
+
"models.max_tokens",
|
|
49
|
+
"instructions.system",
|
|
50
|
+
"runtime.max_turns",
|
|
51
|
+
"tools.enabled",
|
|
52
|
+
"tools.blocked",
|
|
53
|
+
"mcp",
|
|
54
|
+
"skills"
|
|
55
|
+
],
|
|
56
|
+
"system_instruction_modes": ["replace", "append"]
|
|
57
|
+
},
|
|
58
|
+
"capabilities": {
|
|
59
|
+
"service": false,
|
|
60
|
+
"streaming": false,
|
|
61
|
+
"updates": false,
|
|
62
|
+
"cancellation": false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nemo-fabric-adapters-openhands
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: OpenHands adapter for NVIDIA NeMo Fabric
|
|
5
|
+
Author: NVIDIA Corporation
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/NVIDIA/NeMo-Fabric
|
|
8
|
+
Project-URL: Homepage, https://github.com/NVIDIA/NeMo-Fabric
|
|
9
|
+
Project-URL: Issues, https://github.com/NVIDIA/NeMo-Fabric/issues
|
|
10
|
+
Project-URL: Documentation, https://docs.nvidia.com/nemo/fabric
|
|
11
|
+
Keywords: agents,ai,nemo-fabric,openhands,runtime,tools
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: nemo-fabric-adapter-contract==0.5.0
|
|
19
|
+
Requires-Dist: nemo-fabric-adapters-common==0.5.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
<!--
|
|
23
|
+
SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
24
|
+
SPDX-License-Identifier: Apache-2.0
|
|
25
|
+
-->
|
|
26
|
+
|
|
27
|
+
# OpenHands Adapter for NVIDIA NeMo Fabric
|
|
28
|
+
|
|
29
|
+
This package provides the OpenHands SDK adapter for NVIDIA NeMo Fabric. It maps
|
|
30
|
+
normalized NeMo Fabric configuration into one persistent OpenHands conversation
|
|
31
|
+
per runtime.
|
|
32
|
+
|
|
33
|
+
Install the tested OpenHands packages and the adapter:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install "openhands-sdk==1.50.0" "openhands-tools==1.50.0"
|
|
37
|
+
pip install nemo-fabric-adapters-openhands
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The 1.50.0 package pair is validated with NVIDIA NIM.
|
|
41
|
+
|
|
42
|
+
Refer to the [NVIDIA NeMo Fabric repository](https://github.com/NVIDIA/NeMo-Fabric/tree/main/adapters/python/openhands)
|
|
43
|
+
for configuration and usage instructions.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
nemo_fabric_adapters/openhands/__init__.py,sha256=Z09yjRCL1FEXYUrFAx4MfLdwSufQ3Pp0Cc-MObnC0L8,187
|
|
2
|
+
nemo_fabric_adapters/openhands/adapter.py,sha256=PdBBmid2pRAN0ZxJEpbOhn4Sgdt5s4NHnTGEvduS4_s,17941
|
|
3
|
+
nemo_fabric_adapters_openhands-0.5.0.data/data/share/nemo-fabric/adapters/openhands/openhands.fabric-adapter.json,sha256=K__t0tRhQC0HMPQ4tTWHF9Ks3FZVFbVmfFU36VJkvko,1798
|
|
4
|
+
nemo_fabric_adapters_openhands-0.5.0.dist-info/licenses/LICENSE,sha256=0HwDZ-KGHn_nD6G2efh59PovkTit5EV9ROz4suE1u0U,11431
|
|
5
|
+
nemo_fabric_adapters_openhands-0.5.0.dist-info/METADATA,sha256=L0RvYlaXpwHovPiz3JSpTsVfrowMQNO0Y5gKmm8ZX18,1590
|
|
6
|
+
nemo_fabric_adapters_openhands-0.5.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
7
|
+
nemo_fabric_adapters_openhands-0.5.0.dist-info/top_level.txt,sha256=8kkURacCI4ccfhMtH1zAy99hoopY4_ZD31HXabkCPPY,21
|
|
8
|
+
nemo_fabric_adapters_openhands-0.5.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright [yyyy] [name of copyright owner]
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nemo_fabric_adapters
|