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
7 changes: 6 additions & 1 deletion openhands-sdk/openhands/sdk/tool/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ def resolve_tool(
resolver = _REG.get(tool_spec.name)

if resolver is None:
raise KeyError(f"ToolDefinition '{tool_spec.name}' is not registered")
from openhands.sdk.tool.builtins import BUILT_IN_TOOL_CLASSES

tool_class = BUILT_IN_TOOL_CLASSES.get(tool_spec.name)
if tool_class is None:
raise KeyError(f"ToolDefinition '{tool_spec.name}' is not registered")
resolver = _resolver_from_subclass(tool_spec.name, tool_class)

params = dict(tool_spec.params)
response_schema = params.pop("response_schema", None)
Expand Down
14 changes: 12 additions & 2 deletions tests/sdk/conversation/test_local_conversation_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ def test_reconciliation_targets_replaced_agent(tmp_path: Path) -> None:

client._tools_reconciled_callback(cast(MCPClient, client), [replacement])

assert set(conversation.agent.tools_map) == {"replacement"}
assert set(old_agent.tools_map) == {"initial"}
updated_mcp_tools = {
name
for name, tool in conversation.agent.tools_map.items()
if isinstance(tool, MCPToolDefinition)
}
old_mcp_tools = {
name
for name, tool in old_agent.tools_map.items()
if isinstance(tool, MCPToolDefinition)
}
assert updated_mcp_tools == {"replacement"}
assert old_mcp_tools == {"initial"}
conversation.close()


Expand Down
29 changes: 17 additions & 12 deletions tests/sdk/conversation/test_utility_llm_span_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,31 @@


def _record_observe_kwargs(unbound_method: Any) -> dict[str, Any]:
"""Trigger the lazy ``observe`` build on a method and return the observe kwargs."""
"""Return the ``observe`` kwargs declared on a lazily decorated method."""
recorded: dict[str, Any] = {}

def recorder(**kwargs: Any):
recorded.update(kwargs)
# Identity: leaves the decorated function's cached wrapper equivalent to
# the undecorated function for the rest of the process.
return lambda func: func

with (
patch("lmnr.observe", recorder),
patch(
with patch("lmnr.observe", recorder):
code = getattr(unbound_method, "__code__", None)
closure = getattr(unbound_method, "__closure__", None)
if code is not None and closure is not None:
freevars = dict(zip(code.co_freevars, closure, strict=False))
build_wrapped_cell = freevars.get("_build_wrapped")
if build_wrapped_cell is not None:
build_wrapped_cell.cell_contents(lambda: None)
return recorded

with patch(
"openhands.sdk.observability.laminar.should_enable_observability",
return_value=True,
),
):
try:
unbound_method(object())
except Exception:
pass
):
try:
unbound_method(object())
except Exception:
pass

return recorded

Expand Down
17 changes: 17 additions & 0 deletions tests/sdk/tool/test_response_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from openhands.sdk.llm import MessageToolCall
from openhands.sdk.mcp.client import MCPClient
from openhands.sdk.mcp.tool import MCPToolDefinition
from openhands.sdk.tool import registry
from openhands.sdk.tool.builtins.finish import (
FinishAction,
FinishObservation,
Expand Down Expand Up @@ -76,6 +77,22 @@ def test_finish_tool_without_schema_is_unchanged():
assert set(schema["properties"]) == {"message", "summary"}


def test_builtin_finish_tool_spec_resolves_without_registry_entry(monkeypatch):
response_schema = TaskResult.model_json_schema()
monkeypatch.delitem(registry._REG, FinishTool.__name__, raising=False)
monkeypatch.delitem(registry._USABILITY_REG, FinishTool.__name__, raising=False)

[tool] = resolve_tool(
Tool(name=FinishTool.__name__, params={"response_schema": response_schema}),
conv_state=MagicMock(),
)

assert isinstance(tool, FinishTool)
assert tool.name == "finish"
assert tool.response_schema == response_schema
assert "success" in tool._get_tool_schema()["properties"]


def test_response_schema_extends_action_schema():
tool = _finish_with_schema(TaskResult)
assert tool.response_schema is TaskResult
Expand Down
Loading