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

​Hi everyone,

​Like many of us, I’ve been experimenting with giving LLMs control over robot hardware. However, I quickly ran into the classic problems: LLMs hallucinate actions, assume prerequisites that haven’t been met (e.g., trying to drive a humanoid before stabilizing it), and most existing integrations are just tightly coupled, hardcoded scripts.

​To solve this, I built ros2_lingua — an open-source bridge that introduces a structured capability contract between ROS 2 nodes and LLMs.

​Instead of letting the LLM guess what topics or actions to call, ros2_lingua forces the LLM to output a plan based only on explicitly registered capabilities, and uses a backward-chaining planner to automatically inject missing prerequisite steps.

​How it works:

  1. ​Capability Advertisement: Any ROS 2 node can inherit from LinguaMixin to self-advertise its capabilities at boot. It defines its name, ROS action/service, parameters, preconditions, and postconditions.
  2. ​Backward-Chaining Planner: 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 capability schema. If the robot isn’t balanced, the planner automatically injects a stabilize_robot capability before the navigation step.
  3. ​Safe Dispatch: The DispatcherNode safely executes the validated plan over standard ROS 2 actions and services.

​Decoupled Architecture

​One of my main goals was to ensure the core logic was highly testable. The project is split into two layers:

​ros2_lingua_core: A pure Python library containing the schema, registry, planner, and LLM backends (Ollama, OpenAI, Anthropic). It has zero ROS 2 dependencies, meaning the grounding engine can be unit-tested purely in Python.

​ros2_lingua: The ROS 2 interface layer containing the GroundingNode, DispatcherNode, and mixins.

​Links & Demo

​You can see a demo of the engine running with a local Ollama model and a mock humanoid setup, along with the full architecture documentation here:

​Documentation & Architecture: ros2_lingua — Documentation

​GitHub Repository: GitHub - purahan/ros2_lingua: Natural language to ROS2 actions — a structured LLM grounding engine for any robot. · GitHub

​What’s Next & Feedback Request

​The project is currently a working prototype in Python. My immediate roadmap includes taking this to a release-ready state and building a C++ bridge so native controller nodes can easily advertise their capabilities.

​Since this is early development, I would love to get feedback from the community on the architecture—specifically on the schema design for the capability registry and how best to handle complex, long-running action pre-emptions within the Dispatcher.

​Thanks for your time, and I’d love to hear your thoughts!

1 Like

Hi purahan,

You asked whether grounding against a live capability registry holds up against failure modes people have hit in practice, and for real-hardware testing. I can offer one of each.

Failure mode and fix: in my own runtime, local models (Qwen, Mistral) copied a placeholder device id straight from the few-shot examples in the prompt, and the validator rejected it. Removing the device-specific examples, adding a strict “copy the exact device_id from the active list” format line, and stripping stray prefixes and quotes before validation fixed it. I’ve tested it with both local models. I deliberately don’t guess: an id that is still unknown is rejected, not replaced with a best match.

Hardware: I have a ROS 2 mobile robot on a Jetson Orin Nano with an independent safety node, and I’m happy to try ros2_lingua on it. Which ROS 2 distro do you target?

One question: when a robot’s own safety layer latches, what happens in the registry? Does the capability disappear, or does the dispatcher keep trying?

For transparency, I’m building something in the same area (xZane, runtime enforcement per device), but I’m not selling anything. I’m trying to learn what’s useful.

Cheers,
Julio

Hi Julio,

Thanks for this, it’s really useful, and thanks for being upfront about xZane.

Placeholder IDs: we’ve seen the same pattern. The model copies values from the few-shot examples instead of using the live registry. ros2_lingua already rejects any capability or parameter that isn’t registered rather than guessing a nearest match, so I fully agree with your “don’t guess” choice. Your tip about cutting device-specific examples from the prompt is a good one, and I’ll look at our prompt with that in mind.

Distro: we target Humble, and CI also runs on Jazzy. A Jetson Orin Nano with an independent safety node is exactly the kind of setup I’d love to test on. Thank you for offering.

Safety latch: honestly, today the registry doesn’t react to it. A capability stays registered until its node goes away, so the latch isn’t modelled. What happens is:

  • If the action server rejects or fails the goal, the step fails.
  • The recovery planner then retries a bounded number of times, may replan once, and falls back or aborts. The replan cap was just merged; before that it could loop.
  • We’re also changing the dispatcher to fail closed when a server is unavailable, instead of the old “demo mode” success.

So it won’t keep hammering a latched robot forever, but it also doesn’t know the robot is latched. I think the right fix is to expose the latch as state, e.g. a safety_ok precondition that the safety node publishes. Then the planner refuses to build any plan that needs motion while it’s false, and the dispatcher stops the current plan when it flips. That’s better than deregistering capabilities, because it keeps the reason visible (“blocked by safety latch”) rather than “capability not found”. I’ll open an issue for it. I’d be curious how xZane handles it, and whether your safety node exposes the latch on a topic we could subscribe to.

If you’re up for a hardware test, the dispatcher changes should land on main in the next few days. I’ll post here when they do.

Cheers,
Purahan