Robotics

ros2_lingua: A safe, dependency-aware grounding engine for LLMs

New Python library prevents LLM hallucinations by enforcing explicit capability contracts for ROS2 robots.

Deep Dive

Developer purahan has released ros2_lingua, an open-source grounding engine designed to safely bridge LLMs with ROS2-based robots. The project tackles a common problem: LLMs hallucinate actions or assume unmet prerequisites (e.g., trying to drive a humanoid before stabilizing it). Unlike tightly coupled scripts, ros2_lingua enforces a structured capability contract. Any ROS2 node can inherit from a LinguaMixin to self-advertise its capabilities—including name, action/service, preconditions, and postconditions. When a user gives a natural language instruction (e.g., “go to the table and pick up the bottle”), the grounding engine checks the robot's current state against the schema. If the robot isn’t balanced, the planner automatically injects a stabilize_robot step before navigation. A DispatcherNode then safely executes the validated plan over standard ROS2 actions and services.

The architecture is decoupled into two layers. ros2_lingua_core is a pure Python library containing the schema, registry, planner, and LLM backends (Ollama, OpenAI, Anthropic)—with zero ROS2 dependencies, enabling easy unit testing. ros2_lingua provides the ROS2 interface layer (GroundingNode, DispatcherNode, mixins). The prototype is currently Python-only; the roadmap includes a release-ready state and a C++ bridge for native controller nodes. The developer is seeking community feedback on the capability registry schema design and handling complex long-running action pre-emptions within the Dispatcher. A demo with a mock humanoid and local Ollama model is available on GitHub.

Key Points
  • Nodes advertise capabilities via LinguaMixin, defining actions, parameters, preconditions, and postconditions.
  • Backward-chaining planner automatically injects missing prerequisite steps (e.g., stabilize before navigation).
  • Core library (ros2_lingua_core) is pure Python with zero ROS2 dependencies, enabling testability without a robot setup.

Why It Matters

Reduces risk of LLM-driven robot accidents by enforcing structured, dependency-checked action plans.