Skip to content
المشاريع

حول

ros2ai is a next-generation ROS 2 command line interface extension with LLMs

أدوات التطوير

كيف تُقاس هذه الأرقام

352 نجمة27 التفرعات +9 خلال 24 ساعة

النمو المقاس للنجوم

خلال 24 ساعة
+٩
خلال 7 أيام
+١١
خلال 15 يومًا
+١٢
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

humble jazzy kilted lyrical rolling humble-nightly jazzy-nightly kilted-nightly lyrical-nightly rolling-nightly

ros2ai 🤖

ros2ai is a next-generation ROS 2 command line interface extension with OpenAI, Anthropic and Ollama.

see overview slide deck for more information.

ros2ai Architecture Overview

Motivation

  • (Just for fun 😝)
  • Thin wrapper for ros2cli and ros2documentation.
  • Getting answers against the questions directly without browsing, clicking and typing many times.
  • Easy to use for everyone, especially for ROS 2 beginners and students who do not really know ros2cli.
  • Multiple language support.
  • Multiple LLMs support (with OpenAI Python API, any OpenAI compatible endpoint such as Anthropic and Ollama)

Demo 🖥️

See how it works 🔥

ros2ai demo

(Full quality video: ros2ai_demo.mp4)

Supported ROS Distribution

Distribution Supported Note
Rolling Ridley ✅ Development / Mainstream Branch
Lyrical Luth ✅
Kilted Kaiju ✅
Jazzy Jalisco ✅
Humble Hawksbill ✅

Installation

Binary

ros2ai is released for every supported distribution, replace <distro> with rolling, lyrical, kilted, jazzy or humble.

apt install ros-<distro>-ros2ai

Docker Container

see available images for tomoyafujita/ros2ai@dockerhub

docker run -it --rm --net=host -e ROS2AI_API_KEY=$ROS2AI_API_KEY -e ROS2AI_ENDPOINT=$ROS2AI_ENDPOINT -e ROS2AI_MODEL_NAME=$ROS2AI_MODEL_NAME tomoyafujita/ros2ai:rolling

[!NOTE] ROS2AI_API_KEY environmental variable is not required if using Ollama. And it is expecting that Ollama runs on the host system mostly, so that container is bound to the host network interface.

Required Package

Build

To use the latest development version, build it in the colcon workspace.

source /opt/ros/rolling/setup.bash
mkdir -p colcon_ws/src
cd colcon_ws/src
git clone https://github.com/fujitatomoya/ros2ai.git
cd ..
colcon build --symlink-install --packages-select ros2ai

Usage

Prerequisites

As described in overview diagram, ros2ai uses only OpenAI Python API but backend implementation can be replaced with any LLM service that provides the compatible API with OpenAI, such as Anthropic and Ollama. User need to choose which of them is used by ros2ai as following configuration, otherwise it falls back to use OpenAI.

  • OpenAI

    ros2ai requires OpenAI API key

    export ROS2AI_API_KEY='your-api-key-here'
    

    [!CAUTION] Do not share or expose your OpenAI API key.

  • Anthropic

    ros2ai requires Anthropic API key, the API is accessed via OpenAI SDK compatibility.

    export ROS2AI_API_KEY='your-api-key-here'
    export ROS2AI_ENDPOINT=https://api.anthropic.com/v1/
    export ROS2AI_MODEL_NAME=claude-opus-5-5
    

    [!CAUTION] Do not share or expose your Anthropic API key.

    [!NOTE] Anthropic accepts the temperature between 0.0 and 1.0 only, the ros2ai default (1.0) works with every Claude model.

  • Ollama

    ros2ai requires Ollama service running, see more details for How to install Ollama to Linux

    ### Install Ollama and System Service
    sudo curl -fsSL https://ollama.com/install.sh | sh
    ### Check ollama.service is up and running
    systemctl status ollama
    ### Pull llama3.1 (for example) model
    ollama pull llama3.1
    ### List available models
    ollama list
    

    [!NOTE] Ollama loads the models with a small context window (4096 tokens) by default, which is not enough for the tool calling (tool definitions, tool results) and ends up with no user query found in messages error. Set OLLAMA_CONTEXT_LENGTH=16384 (or more) in the environment of the Ollama service, see Ollama FAQ.

Optional

environmental variable default Note
ROS2AI_API_KEY None. Required for OpenAI and Anthropic
ROS2AI_MODEL_NAME 'gpt-5' AI model to be used. e.g) claude-opus-5-5 (Anthropic), llama3.1 (Ollama)
ROS2AI_ENDPOINT 'https://api.openai.com/v1' API endpoint URL. e.g) https://api.anthropic.com/v1/ (Anthropic), http://127.0.0.1:11434/v1 (Ollama)
ROS2AI_TEMPERATURE 1.0 OpenAI temperature, 0.0 - 1.0 for Anthropic
ROS2AI_ROLE_SYSTEM built-in system role System role for the prompt, {} is replaced with the ROS distribution name
ROS2AI_DOCS_CACHE '~/.cache/ros2ai/docs' Directory caching the ROS 2 documentation sources per distribution
ROS2AI_CONTEXT_LIMIT 16000 Context limit of the session in estimated tokens, the oldest requests are dropped beyond it. Lower it for the local models with a small context window (e.g Ollama num_ctx)
ROS2AI_SESSION_FILE ~/.local/state/ros2ai/session.json Session file to continue the previous requests with --continue ($XDG_STATE_HOME is honored)

[!NOTE] These are optional environmental variables. if not set, default value will be used. The legacy OPENAI_API_KEY, OPENAI_MODEL_NAME, OPENAI_ENDPOINT, OPENAI_TEMPERATURE and OPENAI_ROLE_SYSTEM are still honored when the corresponding ROS2AI_* variable is not set.

The following command line options prevail over the environmental variables, see ros2 ai -h for the complete list.

option Note
-m, --model <model> LLM model, prevails over ROS2AI_MODEL_NAME
-u, --url <url> LLM API endpoint URL, prevails over ROS2AI_ENDPOINT
-t, --token <token> Maximum number of tokens of the completion (default: no limit)
-r, --role <role> System role for the prompt, prevails over ROS2AI_ROLE_SYSTEM
-y, --yes Execute the commands that change the system without confirmation
--dry-run Print the commands that change the system instead of executing them
-c, --continue Continue the previous session with the request, see Session
-n, --nostream Disable the streaming of the answer
-T, --trace Print the trace of the request: the tool calls, the executed commands and their output
-v, --verbose Print the configuration, system role, tool calls and results (implies --trace)
-s, --status Check the LLM API status and configuration
-l, --list-models Print the available models on the endpoint

Examples

Basics

ros2 ai has no sub-command, just pass your question or request: ros2 ai "<request>". The ROS 2 assistant decides by itself whether to answer the question or to operate the ROS 2 system on your behalf.

  • configuration

    ### OpenAI configuration
    export ROS2AI_API_KEY=<YOUR_API_KEY>
    export ROS2AI_MODEL_NAME=gpt-5
    export ROS2AI_ENDPOINT=https://api.openai.com/v1
    
    ### Anthropic configuration
    export ROS2AI_API_KEY=<YOUR_API_KEY>
    export ROS2AI_MODEL_NAME=claude-opus-5-5
    export ROS2AI_ENDPOINT=https://api.anthropic.com/v1/
    
    ### Ollama
    unset ROS2AI_API_KEY
    export ROS2AI_MODEL_NAME=llama3.1
    export ROS2AI_ENDPOINT=http://127.0.0.1:11434/v1
    
  • --status (-s) to check API key and configuration are valid, --list-models (-l) prints the available models.

    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai -s -v
    ----- api_model: gpt-5
    ----- api_endpoint: https://api.openai.com/v1
    ----- api_token: None
    ----- api_temperature: 1.0
    As an artificial intelligence, I do not have a physical presence, so I can't be "in service" in the traditional sense. But I am available to assist you 24/7.
    [SUCCESS] Valid API key.
    [SUCCESS] Retrieved list of models.
    
  • ask any questions to ROS 2 assistant.

    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "Tell me how to check the available topics?"
    To check the available topics in ROS 2, you can use the following command in the terminal:
    
    ---
    ros2 topic list
    ---
    
    After you enter this command, a list of all currently active topics in your ROS2 system will be displayed. This list includes all topics that nodes in your system are currently publishing to or subscribing from.
    
  • request ROS 2 assistant to operate the ROS 2 system.

    The assistant calls the ros2cli tools (ros2 node, ros2 topic, ros2 service, ros2 param and so on) via tool calling, observes the result and iterates until the request is done. Every command is executed without shell, so that the model can only run ros2 commands. The commands that change the system are printed before they are executed, the read-only commands and their output are not printed unless --trace (-T) is given, the answer is what you get.

    Tool policy Commands Behavior
    read-only node, topic list/info/echo, service list, param get ... executed automatically
    mutating topic pub, service call, param set, action send_goal ... asks for confirmation, -y / --yes skips it
    long-running run, launch, bag record ... asks for confirmation, runs in foreground until Ctrl-C
    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "give me all topics"
    Here are all the available topics in your ROS 2 system:
    | Topic | Message Type |
    |-------|-------------|
    | `/chatter` | `std_msgs/msg/String` |
    | `/parameter_events` | `rcl_interfaces/msg/ParameterEvent` |
    | `/rosout` | `rcl_interfaces/msg/Log` |
    That's 3 topics in total. Let me know if you'd like to inspect any of them further (e.g., see publishers/subscribers, echo a message, or publish to one).
    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "publish hello message on /chatter topic" -y
    [ros2ai]: ros2 topic pub --once -w 0 /chatter std_msgs/msg/String '{data: hello}'
    Done — I published the message `hello` on `/chatter` (`std_msgs/msg/String`). Note: the topic currently shows 0 subscribers, so no node received it. Let me know if you want me to start a listener (e.g., `demo_nodes_cpp`'s `listener`) first.
    

    Without -y, the assistant asks Execute 'ros2 topic pub --once -w 0 /chatter std_msgs/msg/String '{data: hello}''? [y/N]: before publishing.

    --trace (-T) prints the trace of the request to see how the assistant completes it: the tool calls, the executed commands and their output.

    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "give me all topics" -T
    [ros2ai]: ros2 topic list -t
    /chatter [std_msgs/msg/String]
    /parameter_events [rcl_interfaces/msg/ParameterEvent]
    /rosout [rcl_interfaces/msg/Log]
    Here are all the available topics in your ROS 2 system:
    ...
    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "publish hello message on /chatter topic" -y -T
    [ros2ai]: ros2 topic info -v /chatter
    Type: std_msgs/msg/String
    ...
    Subscription count: 0
    [ros2ai]: ros2 topic pub --once -w 0 /chatter std_msgs/msg/String '{data: hello}'
    publisher: beginning loop
    publishing #1: std_msgs.msg.String(data='hello')
    Done — I published the message `hello` on `/chatter` (`std_msgs/msg/String`).
    ...
    

    --dry-run prints the commands that change the system as candidates instead of executing them (read-only commands are still executed, so that the assistant can decide the command), -v prints the system role, the tool calls and results. The answers are streamed as they arrive, -n disables the streaming (the raw completions are printed with -nv).

    Composite tools answer a diagnostic question with several ros2 commands in a single tool call, instead of one completion per command. get_node_status combines node info, lifecycle get, param list and topic hz of the published topics, get_topic_status combines topic info -v, topic hz and topic echo --once. The result is a YAML summary including the warnings found (lifecycle state not active, idle publisher, incompatible QoS and so on), with --trace the commands are printed indented under the tool call.

    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "is /lc_talker healthy?" -T
    [ros2ai]: get_node_status(node=/lc_talker)
    [ros2ai]:   ros2 node info /lc_talker
    [ros2ai]:   ros2 lifecycle get /lc_talker
    [ros2ai]:   ros2 param list /lc_talker
    node: /lc_talker
    found: true
    lifecycle: unconfigured
    publishers:
    - topic: /lc_talker/transition_event
      type: lifecycle_msgs/msg/TransitionEvent
      hz: not measured
    subscribers: {}
    service_servers: {}
    service_clients: {}
    action_servers: {}
    action_clients: {}
    parameters:
    - use_sim_time
    warnings:
    - lifecycle state is 'unconfigured', not active
    No — `/lc_talker` is not healthy. It's a **lifecycle node stuck in the `unconfigured` state**:
    ...
    So the node exists and is alive on the graph, but it has never been transitioned to an active state. If you'd like, I can transition it to `configured` → `active` via the lifecycle services (`/lc_talker/change_state`), or list the lifecycle service details first.
    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "what is the status of the /chatter topic?" -T
    [ros2ai]: get_topic_status(topic=/chatter)
    [ros2ai]:   ros2 topic info -v /chatter
    [ros2ai]:   ros2 topic hz /chatter
    [ros2ai]:   ros2 topic echo --once /chatter
    topic: /chatter
    found: true
    type: std_msgs/msg/String
    publishers:
    - node: /talker
      reliability: RELIABLE
      durability: VOLATILE
    subscribers:
    - node: /listener
      reliability: RELIABLE
      durability: VOLATILE
    hz: 1.0
    sample: 'data: ''Hello World: 108'''
    warnings: []
    The `/chatter` topic is healthy and active:
    ...
    Everything looks normal — the topic is being published at 1 Hz and received without issues.
    

    [!NOTE] If the endpoint or the model does not support tool calling, the assistant answers the request without tools, nothing is executed.

Documentation Lookup

The assistant can look up the official ROS 2 documentation of the running distribution (ROS_DISTRO) with the documentation tools, so that the answers about the ROS 2 concepts, tutorials, tools and APIs are grounded on the documentation of your distribution, and cite the page. search_ros2_docs searches the pages, read_ros2_docs reads a page, with --trace the pages found are printed under the tool call.

The documentation sources (ros2/ros2_documentation, one branch per distribution) are downloaded once into ~/.cache/ros2ai/docs/<distro> (about 5MB) on the first lookup, and refreshed when older than a week. The lookup works offline afterwards, without the cache the assistant answers from its own knowledge.

root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "what is the difference between reliable and best effort QoS?" -T
[ros2ai]: search_ros2_docs(query='quality of service reliability reliable best effort', limit=3)
[ros2ai]:   downloaded the ROS 2 rolling documentation to /root/.cache/ros2ai/docs/rolling
[ros2ai]:   https://docs.ros.org/en/rolling/ROS-Framework/interfaces/topics/About-Quality-of-Service-Settings.html
[ros2ai]:   https://docs.ros.org/en/rolling/ROS-Framework/interfaces/topics/Working-with-topics/Quality-of-Service.html
[ros2ai]:   https://docs.ros.org/en/rolling/ROS-Framework/interfaces/topics/Working-with-topics/Configuring-QoS-Overrides.html
[ros2ai]: read_ros2_docs(page=ROS-Framework/interfaces/topics/About-Quality-of-Service-Settings)
[ros2ai]:   https://docs.ros.org/en/rolling/ROS-Framework/interfaces/topics/About-Quality-of-Service-Settings.html
[ros2ai]: read_ros2_docs(page=ROS-Framework/interfaces/topics/About-Quality-of-Service-Settings, offset=3500)
[ros2ai]:   https://docs.ros.org/en/rolling/ROS-Framework/interfaces/topics/About-Quality-of-Service-Settings.html
**Reliable and best effort are the two values of the QoS reliability policy.**

- **Best effort** tries to deliver each sample but may lose it if the network is not robust. It does not retry, so it has lower latency and overhead. It is closest to UDP. The built-in **sensor data** profile uses it, because the latest reading matters more than receiving every reading.
- **Reliable** guarantees that samples are delivered and may retry several times. It is closest to TCP, but the docs note it is still implemented over UDP. It is the default for publishers and subscriptions, and also for services and parameters.

**Compatibility.** A subscription asks for a minimum quality and a publisher offers a maximum. A connection is only made if the request is not stricter than the offer:
...
A reliable subscription on a best-effort publisher gets no messages. This is a common reason a topic looks silent, for example with a camera or lidar driver that publishes best effort.

Source: https://docs.ros.org/en/rolling/ROS-Framework/interfaces/topics/About-Quality-of-Service-Settings.html

Session

ros2 ai keeps the context of the session, so that the follow-up requests can refer to the previous ones (e.g it).

  • ros2 ai without a request starts the interactive session, the context is kept until the session ends with exit or Ctrl-D. /clear forgets the context, Ctrl-C aborts the request in progress.

    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai
    ros2ai interactive session (model: gpt-5, endpoint: https://api.openai.com/v1)
    Type /help for the commands, exit or Ctrl-D to end the session.
    ros2ai> do we have /chatter topic?
    Yes, the /chatter topic (std_msgs/msg/String) is available.
    ros2ai> subscribe it
    Subscribed to /chatter and received the message 'Hello World: 12'.
    ros2ai> exit
    
  • --continue (-c) continues the previous session with a single request, every request is saved to the session file.

    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "do we have /chatter topic?"
    Yes, the /chatter topic (std_msgs/msg/String) is available.
    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai -c "subscribe it"
    Subscribed to /chatter and received the message 'Hello World: 25'.
    

[!NOTE] The messages of the previous requests are sent with every request, so the token consumption grows with the session. The oldest requests are dropped when the estimated number of tokens exceeds ROS2AI_CONTEXT_LIMIT, or when the endpoint reports that the context length is exceeded.

Multiple Language

  • Japanese (could be any language ❓)

    root@tomoyafujita:~/docker_ws/ros2_colcon# ros2 ai "パラメータのリスト取得方法を教えて"
    ROS 2のパラメータリストを取得するには、コマンドラインインターフェース(CLI)を使います。具体的には、次のコマンドを使用します:
    
    ---code
    ros2 param list
    ---
    
    このコマンドは、現在動作しているすべてのノードのパラメーターをリストアップします。特定のノードのパラメータだけを見たい場合には、以下のようにノード名を指定することもできます。
    
    ---code
    ros2 param list /node_name
    ---
    
    このようにして、ROS2のパラメータリストの取得を行うことが可能です。なお、上述したコマンドはシェルから直接実行してください。
    

Reference

Special thanks to OpenAI API, Anthropic API and Ollama 🌟🌟🌟

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…