Skip to content

Custom Agents

Rob Royce edited this page Sep 15, 2024 · 8 revisions

ROSA is designed to be easily adaptable to different robots and environments. To adapt ROSA for your robot, you can either (1) create a new class that inherits from the ROSA class, or (2) create a new instance of the ROSA class and pass in the necessary parameters. The first option is recommended if you need to make significant changes to the agent's behavior, while the second option is recommended if you want to use the agent with minimal changes.

In either case, ROSA is adapted by providing it with a new set of tools and/or prompts. The tools are used to interact with the robot and the ROS environment, while the prompts are used to guide the agents behavior.

Adding Tools

There are two methods for adding tools to ROSA:

  1. Pass in a list of LangChain @tool functions or Tool objects using the tools parameter.
  2. Pass in a list of Python packages containing LangChain @tool functions using the tool_packages parameter.

The first method is recommended if you have a small number of tools, while the second method is recommended if you have a large number of tools or if you want to organize your tools into separate packages.

Tip

Check src/turtle_agent/scripts/turtle_agent.py for examples on how to use both methods.

See Developer Documentation for best practices on creating @tool functions.

Adding Prompts

To add prompts to ROSA, you need to create a new instance of the RobotSystemPrompts class and pass it to the ROSA constructor using the prompts parameter.

See Developer Documentation for best practices on creating system prompts.

Example

Here is a quick and easy example showing how to add new tools and prompts to ROSA:

from langchain.agents import tool
from rosa import ROSA, RobotSystemPrompts

@tool
def move_forward(distance: float) -> str:
    """
    Move the robot forward by the specified distance.
    
    :param distance: The distance to move the robot forward.
    """
    # Your code here ...
    return f"Moving forward by {distance} units."

prompts = RobotSystemPrompts(
    embodiment_and_persona="You are a cool robot that can move forward."
)

llm = get_your_llm_here()
rosa = ROSA(ros_version=1, llm=llm, tools=[move_forward], prompts=prompts)
rosa.invoke("Move forward by 2 units.")