Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3d8703f
Implement automatic tool registration on import
openhands-agent Oct 22, 2025
eb4aa7e
Move automatic registration tests to tests/cross/
openhands-agent Oct 22, 2025
8af24d1
Fix formatting issues from pre-commit hooks
openhands-agent Oct 22, 2025
c0b6545
Fix formatting after pre-commit hooks
openhands-agent Oct 22, 2025
f630648
Fix preset file to use tool_name instead of name attribute
openhands-agent Oct 22, 2025
65708ba
Implement automatic tool naming using __init_subclass__
openhands-agent Oct 22, 2025
ae802db
Merge branch 'main' into openhands/simplify-tool-registration
malhotra5 Oct 30, 2025
9f89653
Merge branch 'main' into openhands/simplify-tool-registration
malhotra5 Nov 3, 2025
0e49991
merge main
malhotra5 Nov 3, 2025
f374924
automatic name field detection
malhotra5 Nov 3, 2025
de32a05
rename tool_name attribs
malhotra5 Nov 3, 2025
23883b1
Fix all .tool_name references to .name on ToolDefinition subclasses
openhands-agent Nov 3, 2025
4de50d9
Fix mock tool tests to work with ClassVar name attribute
openhands-agent Nov 3, 2025
1d8295a
Fix agent tool initialization test for ClassVar name attribute
openhands-agent Nov 3, 2025
da445b5
Fix security policy test to use correct tool name
openhands-agent Nov 3, 2025
d84e61e
Fix remaining test files with name= parameters and MCP tool property …
openhands-agent Nov 3, 2025
285698e
Fix failing unit tests by correcting tool registration names
openhands-agent Nov 4, 2025
1586ce5
Move test_automatic_naming.py to tests/cross/
openhands-agent Nov 4, 2025
ba99a58
Fix finish tool name consistency across agent and tests
openhands-agent Nov 4, 2025
d0a25c0
Fix tool name assertions in glob and grep tests
openhands-agent Nov 4, 2025
cf97f12
Merge branch 'main' into openhands/simplify-tool-registration
malhotra5 Nov 4, 2025
726e2c2
Apply suggestion from @malhotra5
malhotra5 Nov 4, 2025
abbbfde
Merge branch 'main' into openhands/simplify-tool-registration
malhotra5 Nov 4, 2025
d6f3395
Fix agent status reference to use ConversationExecutionStatus.FINISHED
openhands-agent Nov 4, 2025
97a6991
Fix failing tests after implementing _tool suffix removal
openhands-agent Nov 4, 2025
cc879f5
Fix failing tests for new tool naming convention
openhands-agent Nov 4, 2025
25758e3
Merge branch 'main' into openhands/simplify-tool-registration
malhotra5 Nov 4, 2025
dfd39c2
add warning
malhotra5 Nov 4, 2025
709ad78
Merge branch 'main' into openhands/simplify-tool-registration
malhotra5 Nov 4, 2025
97047d4
fix circular import
malhotra5 Nov 4, 2025
efce165
Merge branch 'openhands/simplify-tool-registration' of https://github…
malhotra5 Nov 4, 2025
adeae66
Update registry.py
malhotra5 Nov 4, 2025
9418487
replace hard coded string
malhotra5 Nov 4, 2025
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
4 changes: 1 addition & 3 deletions examples/01_standalone_sdk/02_custom_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

logger = get_logger(__name__)


# --- Action / Observation ---


Expand Down Expand Up @@ -149,11 +148,10 @@ def _make_bash_and_grep_tools(conv_state) -> list[ToolDefinition]:
return [bash_tool, grep_tool]


register_tool("FileEditorTool", FileEditorTool)
register_tool("BashAndGrepToolSet", _make_bash_and_grep_tools)

tools = [
Tool(name="FileEditorTool"),
Tool(name=FileEditorTool.tool_name),
Tool(name="BashAndGrepToolSet"),
]

Expand Down
12 changes: 4 additions & 8 deletions examples/01_standalone_sdk/03_activate_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
KeywordTrigger,
Skill,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand All @@ -34,15 +34,13 @@
api_key=SecretStr(api_key),
)

# Tools
# Tools (automatically registered on import)
cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
),
Tool(name="FileEditorTool"),
Tool(name=FileEditorTool.tool_name),
]

agent_context = AgentContext(
Expand Down Expand Up @@ -73,11 +71,9 @@
user_message_suffix="The first character of your response should be 'I'",
)


# Agent
agent = Agent(llm=llm, tools=tools, agent_context=agent_context)


llm_messages = [] # collect raw LLM messages


Expand Down
5 changes: 2 additions & 3 deletions examples/01_standalone_sdk/05_use_llm_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
TextContent,
get_logger,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool


Expand Down Expand Up @@ -42,8 +42,7 @@

# Tools
cwd = os.getcwd()
register_tool("BashTool", BashTool)
tools = [Tool(name="BashTool")]
tools = [Tool(name=BashTool.tool_name)]

# Agent
agent = Agent(llm=llm, tools=tools)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
LLMConvertibleEvent,
get_logger,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool


Expand All @@ -30,10 +30,9 @@

# Tools
cwd = os.getcwd()
register_tool("BashTool", BashTool)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
params={"no_change_timeout_seconds": 3},
)
]
Expand Down
8 changes: 3 additions & 5 deletions examples/01_standalone_sdk/07_mcp_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
get_logger,
)
from openhands.sdk.security.llm_analyzer import LLMSecurityAnalyzer
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand All @@ -31,11 +31,9 @@
)

cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(name="BashTool"),
Tool(name="FileEditorTool"),
Tool(name=BashTool.tool_name),
Tool(name=FileEditorTool.tool_name),
]

# Add MCP Tools
Expand Down
8 changes: 3 additions & 5 deletions examples/01_standalone_sdk/08_mcp_with_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
LLMConvertibleEvent,
get_logger,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand All @@ -30,13 +30,11 @@
)

cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
),
Tool(name="FileEditorTool"),
Tool(name=FileEditorTool.tool_name),
]

mcp_config = {
Expand Down
10 changes: 3 additions & 7 deletions examples/01_standalone_sdk/09_pause_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Agent,
Conversation,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand All @@ -27,20 +27,17 @@
)

# Tools
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
),
Tool(name="FileEditorTool"),
Tool(name=FileEditorTool.tool_name),
]

# Agent
agent = Agent(llm=llm, tools=tools)
conversation = Conversation(agent, workspace=os.getcwd())


print("=" * 60)
print("Pause and Continue Example")
print("=" * 60)
Expand Down Expand Up @@ -75,7 +72,6 @@
print(f"Agent status after pause: {conversation.state.agent_status}")
print()


# Phase 3: Send a new message while paused
print("Phase 3: Sending a new message while agent is paused...")
conversation.send_message(
Expand Down
8 changes: 3 additions & 5 deletions examples/01_standalone_sdk/10_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LLMConvertibleEvent,
get_logger,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand All @@ -32,11 +32,9 @@

# Tools
cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(name="BashTool"),
Tool(name="FileEditorTool"),
Tool(name=BashTool.tool_name),
Tool(name=FileEditorTool.tool_name),
]

# Add MCP Tools
Expand Down
11 changes: 4 additions & 7 deletions examples/01_standalone_sdk/11_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
get_logger,
)
from openhands.sdk.conversation.types import ConversationCallbackType
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.sdk.utils.async_utils import AsyncCallbackWrapper
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool
Expand All @@ -41,15 +41,12 @@

# Tools
cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
register_tool("TaskTrackerTool", TaskTrackerTool)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
),
Tool(name="FileEditorTool"),
Tool(name="TaskTrackerTool"),
Tool(name=FileEditorTool.tool_name),
Tool(name=TaskTrackerTool.tool_name),
]

# Agent
Expand Down
8 changes: 3 additions & 5 deletions examples/01_standalone_sdk/12_custom_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Conversation,
)
from openhands.sdk.conversation.secret_source import SecretSource
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand All @@ -26,11 +26,9 @@
)

# Tools
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(name="BashTool"),
Tool(name="FileEditorTool"),
Tool(name=BashTool.tool_name),
Tool(name=FileEditorTool.tool_name),
]

# Agent
Expand Down
8 changes: 3 additions & 5 deletions examples/01_standalone_sdk/13_get_llm_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
LLMConvertibleEvent,
get_logger,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand All @@ -30,11 +30,9 @@
)

cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(name="BashTool"),
Tool(name="FileEditorTool"),
Tool(name=BashTool.tool_name),
Tool(name=FileEditorTool.tool_name),
]

# Add MCP Tools
Expand Down
13 changes: 4 additions & 9 deletions examples/01_standalone_sdk/14_context_condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
get_logger,
)
from openhands.sdk.context.condenser import LLMSummarizingCondenser
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool
from openhands.tools.task_tracker import TaskTrackerTool
Expand All @@ -40,15 +40,12 @@

# Tools
cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
register_tool("TaskTrackerTool", TaskTrackerTool)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
),
Tool(name="FileEditorTool"),
Tool(name="TaskTrackerTool"),
Tool(name=FileEditorTool.tool_name),
Tool(name=TaskTrackerTool.tool_name),
]

# Create a condenser to manage the context. The condenser will automatically truncate
Expand Down Expand Up @@ -105,7 +102,6 @@ def conversation_callback(event: Event):
)
conversation.run()


print("=" * 100)
print("Conversation finished. Got the following LLM messages:")
for i, message in enumerate(llm_messages):
Expand All @@ -129,7 +125,6 @@ def conversation_callback(event: Event):
conversation.send_message("Finally, clean up by deleting both files.")
conversation.run()


print("=" * 100)
print("Conversation finished with LLM Summarizing Condenser.")
print(f"Total LLM messages collected: {len(llm_messages)}")
Expand Down
12 changes: 4 additions & 8 deletions examples/01_standalone_sdk/15_browser_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
LLMConvertibleEvent,
get_logger,
)
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.browser_use import BrowserToolSet
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool
Expand All @@ -32,15 +32,12 @@

# Tools
cwd = os.getcwd()
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
register_tool("BrowserToolSet", BrowserToolSet)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
),
Tool(name="FileEditorTool"),
Tool(name="BrowserToolSet"),
Tool(name=FileEditorTool.tool_name),
Tool(name=BrowserToolSet.tool_name),
]

# If you need fine-grained browser control, you can manually register individual browser
Expand Down Expand Up @@ -68,7 +65,6 @@ def conversation_callback(event: Event):
)
conversation.run()


print("=" * 100)
print("Conversation finished. Got the following LLM messages:")
for i, message in enumerate(llm_messages):
Expand Down
8 changes: 3 additions & 5 deletions examples/01_standalone_sdk/16_llm_security_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from openhands.sdk.conversation.state import AgentExecutionStatus, ConversationState
from openhands.sdk.security.confirmation_policy import ConfirmRisky
from openhands.sdk.security.llm_analyzer import LLMSecurityAnalyzer
from openhands.sdk.tool import Tool, register_tool
from openhands.sdk.tool import Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool

Expand Down Expand Up @@ -101,13 +101,11 @@ def run_until_finished_with_security(
)

# Tools
register_tool("BashTool", BashTool)
register_tool("FileEditorTool", FileEditorTool)
tools = [
Tool(
name="BashTool",
name=BashTool.tool_name,
),
Tool(name="FileEditorTool"),
Tool(name=FileEditorTool.tool_name),
]

# Agent with security analyzer
Expand Down
Loading
Loading