-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Problem
PR #1125 fixed an issue where creating a new conversation with planning agent tools would fail. However, the solution hardcodes tool registration on the server side by calling register_planning_tools() during server initialization in tool_router.py:
tool_router = APIRouter(prefix="/tools", tags=["Tools"])
register_default_tools(enable_browser=True)
register_planning_tools() # Hardcoded registrationWhy this is not ideal:
- Server code needs to be modified every time we want to use a different set of tools
- Not scalable - doesn't work for custom tool sets
- Tight coupling between server and specific tool implementations
- Clients cannot dynamically register their own tools
Proposed Solution
Instead of hardcoding tool registrations on the server side, we should implement automatic tool registration when creating a RemoteConversation:
-
Client-side: When
RemoteConversation.__init__()creates a new conversation, automatically detect all tools registered in the client'sToolRegistryusinglist_registered_tools() -
Send to server: Include the list of tool qualified names (qualnames) in the conversation creation payload
-
Server-side: Dynamically register those tools on the server when the conversation is created
This approach provides:
- ✅ Flexibility - clients can use any tool set without server changes
- ✅ Scalability - works with custom tools automatically
- ✅ Loose coupling - server doesn't need to know about specific tools in advance
- ✅ Better developer experience - tools "just work" when registered on the client
Implementation Details
Client Side (RemoteConversation.__init__)
In openhands-sdk/openhands/sdk/conversation/impl/remote_conversation.py around line 454-476:
# Current code:
payload = {
"agent": agent.model_dump(mode="json", context={"expose_secrets": True}),
"initial_message": None,
"max_iterations": max_iteration_per_run,
"stuck_detection": stuck_detection,
"workspace": LocalWorkspace(working_dir=self.workspace.working_dir).model_dump(),
}
# Proposed change:
from openhands.sdk.tool.registry import list_registered_tools
payload = {
"agent": agent.model_dump(mode="json", context={"expose_secrets": True}),
"initial_message": None,
"max_iterations": max_iteration_per_run,
"stuck_detection": stuck_detection,
"workspace": LocalWorkspace(working_dir=self.workspace.working_dir).model_dump(),
"registered_tools": list_registered_tools(), # Add tool qualnames
}Server Side
-
API Model (
openhands-agent-server/openhands/agent_server/models.py): Update the conversation creation request model to acceptregistered_toolsfield -
Conversation Router (
openhands-agent-server/openhands/agent_server/conversation_router.py): Process theregistered_toolslist and dynamically register them -
Tool Registration: Need a mechanism to register tools by their qualified name (qualname) - may need to implement a tool import/registration utility
Additional Considerations
- Tool Discovery: Need to ensure tools can be imported/registered by their qualname on the server side
- Security: Validate that only allowed tools can be registered (prevent arbitrary code execution)
- Backward Compatibility: Ensure this works with existing code that doesn't send tool lists
- Error Handling: Handle cases where tools can't be registered on the server
Related Files
openhands-sdk/openhands/sdk/tool/registry.py- Tool registry withlist_registered_tools()openhands-sdk/openhands/sdk/conversation/impl/remote_conversation.py- RemoteConversation implementationopenhands-agent-server/openhands/agent_server/tool_router.py- Current hardcoded tool registrationopenhands-agent-server/openhands/agent_server/conversation_router.py- Conversation creation endpointopenhands-tools/openhands/tools/glob/definition.py- Example of tool auto-registration pattern
Acceptance Criteria
- Client automatically sends list of registered tools when creating RemoteConversation
- Server dynamically registers tools from the client's tool list
- Planning agent tools work without hardcoded
register_planning_tools()call - Custom tools can be used with RemoteConversation without server modifications
- Backward compatibility maintained for existing code
- Security considerations addressed (tool allowlist/validation)
- Tests added for dynamic tool registration
- Documentation updated
References
- PR fix(backend): unable to create a new conversation using the planning agent’s tools. #1125: "fix(backend): unable to create a new conversation using the planning agent's tools"