Skip to content

refactor(tools): derive native tools from functions and bound methods - #198

Open
wilburx813 wants to merge 7 commits into
RLinf:mainfrom
wilburx813:refactor/native-tool-protocol
Open

wilburx813 wants to merge 7 commits into
RLinf:mainfrom
wilburx813:refactor/native-tool-protocol

Conversation

@wilburx813

@wilburx813 wilburx813 commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Tool definitions currently duplicate Python signatures in handwritten schemas and adapt results through provider-specific content blocks. This change derives native Tool declarations from typed functions and instance methods, and returns ToolResult(data, images, error) across robots, planners/MCP, and Dashboard.

  • Preserve existing primitive objects, robot resource ownership, recording, and cancellation callbacks. Register bound methods with iter_tools / add_tool; use with_handler for resource binding and execution guards.
  • Generate schemas and descriptions from annotations, Field constraints, and Google-style docstrings. Support @tool, @tool(), and @tool(readonly=True).
  • Validate arguments in Toolkit before execution or observation capture. Store accepted finish results on Toolkit and convert native results only at planner/MCP boundaries.
  • Move memory path authorization into MemoryManager and update the English/Chinese extension guides.

Compatibility

Custom integrations must register native declarations with add_tool / add_tools, discover them through list_tools(), and return ToolResult from handlers and observation capture. Direct Python callers use .data or .to_dict() instead of indexing the old result dictionary. Images are an ordered PNG byte list; errors use the explicit error field.

Historical schema snapshots cover common tools and all five robots (67 tools), retaining their published input schemas. Runtime validation rejects unknown arguments and non-finite numbers and applies declared constraints. Tool calls remain serialized. readonly controls automatic observation capture, including for file tools.

Adds docstring-parser and removes the direct jsonschema dependency.

Preserve the complete implementation from RLinf#173, including follow-up fixes and merge resolutions. Original head: da4abb0.
@read-the-docs-community

read-the-docs-community Bot commented Sep 17, 2026

Copy link
Copy Markdown

@read-the-docs-community

read-the-docs-community Bot commented Sep 17, 2026

Copy link
Copy Markdown

Comment thread rpent/tools/base.py Outdated
return handler


def tool(function: Callable[ParamsT, ToolResult], /) -> Tool[ParamsT]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is @tool@readonly same with @readonly@tool?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, support @tool() and @tool(readonly=True)

Comment thread rpent/tools/toolkit.py
from rpent.tools.common_tools import COMMON_TOOLS
from rpent.utils.logging import get_logger

logger = get_logger("tools")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use the same name as the filename

Comment thread rpent/tools/base.py Outdated
from rpent.session import EnvState

ParamsT = ParamSpec("ParamsT")
RobotT = TypeVar("RobotT")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use RuntimeT or RobotRuntimeT

@wilburx813 wilburx813 changed the title refactor: migrate tools and planners to the native tool protocol refactor(tools): derive native tools from functions and bound methods Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants