Writing Custom Tools

Overview

Tools are the actual actions your agents take. Rock comes with many tools out of the box that have been tested and refined, ready to use in Rock, but you're not limited to the skills and tools that come out of the box. You can write your own using native code (C#) or Lava. We provide information on each below.

Native vs. Lava Tools

Tool Security

Every tool you build inherits Rock's security. A person can only run a tool if they have access to it. When you build a tool, think about who on staff should use it and set security before you attach it to an agent. A Public agent should only carry tools you would hand to a stranger.

Don't Expose Raw Ids to the Model

Never pass a raw Rock integer Id to the model. If the model sees a raw ID, it may use it — and that leads to unpredictable behavior and potential security exposure.

Use IdKey instead. If your tool needs to map between an IdKey and an internal Id, handle that conversion inside your tool code using a dictionary. Only surface IdKey values in what you return to the model.

// Don't do this
return new { PersonId = person.Id };

// Do this
return new { PersonId = person.IdKey };

Audit your existing tool return shapes for any raw Id fields and update them to use IdKey.

Naming

Tools should be named in the pattern of Verb -> Noun. This is more natural when reading as an individual as well as for the language model when it is determining what tools are available. For example, ListConnectionRequests.

More on Tools

Types of Tools Lava Tools Native Tools Debugging Tools