Skip to content

fix(tools): resolve GetGrabbingPointTool forward ref in GetObjectPositionsTool - #878

Open
RoboX2020 wants to merge 2 commits into
RobotecAI:mainfrom
RoboX2020:fix/get-object-positions-forward-ref
Open

RoboX2020 wants to merge 2 commits into
RobotecAI:mainfrom
RoboX2020:fix/get-object-positions-forward-ref

Conversation

@RoboX2020

Copy link
Copy Markdown

Purpose

Fix PydanticUserError: GetObjectPositionsTool is not fully defined raised when constructing GetObjectPositionsTool or generating its schema (for example when binding the tool to an LLM).

Proposed Changes

GetObjectPositionsTool declares get_grabbing_point_tool: "GetGrabbingPointTool", but GetGrabbingPointTool is only imported under TYPE_CHECKING (moved there to avoid a circular import). Pydantic can never resolve that forward reference at runtime, and nothing calls model_rebuild().

This adds a guarded import of GetGrabbingPointTool at the end of rai/tools/ros2/manipulation/custom.py, followed by GetObjectPositionsTool.model_rebuild(). If rai_perception is not installed, the import is skipped and behavior is unchanged.

The existing tests build this tool with model_construct(), which skips the "fully defined" check, so they could not catch the problem. A regression test now asserts GetObjectPositionsTool.__pydantic_complete__ is true.

Issues

Fixes #870

Testing

  • Added test_get_object_positions_tool_model_is_fully_defined in tests/tools/ros2/test_manipulation_custom.py. It is skipped when rai_perception is not installed.
  • CI runs the new test along with the existing suite.

…tionsTool

Call model_rebuild() after a guarded import so Pydantic can resolve the annotation. Fixes RobotecAI#870.
@RoboX2020

Copy link
Copy Markdown
Author

Verified on ROS 2 Humble with rai_core and rai_perception installed: tests/tools/ros2/test_manipulation_custom.py passes 19/19 with this change, including the new test_get_object_positions_tool_model_is_fully_defined.

With custom.py reverted to the pre-fix commit, that same test fails, so it does catch the bug from #870. I ran this one test file, not the full suite.

Note the test is skipped when rai_perception is not installed.

This branch has not been deployed

No deployments
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.

GetObjectPositionsTool cannot be constructed: get_grabbing_point_tool type is imported only under TYPE_CHECKING

1 participant