User-Defined Agent Tools
Define custom tools for the RAG Agent
There are many cases where it is helpful to define custom tools for the RAG Agent. R2R allows for users to define custom tools, passing these definitions into the Agent at server start.
Defining New Tools
There is a directory in the R2R repository, /docker/user_tools
, which is mounted to the R2R docker container. It is here that we will place our custom tool files.
There, we will find a README.md file, which includes a template for our new tool:
Python
This template has two basic methods:
__init__
is where we define the tool. The description that we make here is shown to the agent.execute
is where we define any custom tool logic and interact with the inputs.
Writing our new tool
Below, we have an example of a toy tool, which takes an integer and string input, returning a silly message to the agent. Should your tool require additional dependencies, be sure to include them in the user_requirements.txt
file located in the /docker
directory.
Python
Finally, we can modify our configuration file’s agent
section to include our new tool:
Finally, we can run the following and see that our agent called our new method, passed the required parameters, and understood its output: