Developing Custom Tools#

The Squirro agent framework allows you to create and deploy custom tools using the LangChain framework. LLM agents can use these tools to perform actions in response to user input.

There are two supported approaches for registering tools:

  1. Recommended method, integrated with the GenAI UI and simplified deployment.

  2. Legacy method, using manual configuration of a YAML file.

Legacy Configuration#

Although a new approach is now available, the legacy method is still currently supported to cover some advanced use cases. However, to ensure future compatibility and avoid potential disruptions, developers are advised to gradually plan their transition to the new method. As the technology continues to evolve, the new approach is likely to become even more suitable for advanced use cases, offering improved performance, features, and capabilities.

Overview#

  • You register tools with @register_component.

  • You reference the tools with a string identifiers in the YAML config files.

  • You manually create the plugin and deployment folders.

Tool Example#

import random
from langchain_core.tools import tool, BaseTool
from squirro.service.genai.components.registry import ToolBase, register_component

DAD_JOKES = [
    "I'm reading a book on anti-gravity. It's impossible to put down!",
    ...
]

@tool
async def random_dad_joke_tool() -> str:
    return random.choice(DAD_JOKES)

@register_component(name="examples/tools/dad_joke")
class RandomDadJokeToolFactory(ToolBase):
    def create_runnable(self) -> BaseTool:
        return random_dad_joke_tool

Note

For advanced use cases, you can apply both @deploy_as_agent_tool and @register_component to the same factory class. It allows the tool to be available in the GenAI UI for interactive selection and accessible via the YAML deployment configuration.

@deploy_as_agent_tool(
    "greeter",
    tagline="Greeter with UI and YAML support",
    material_icon="public",
    category="retriever",
)
@register_component(name="examples/tools/greeter")
class GreeterFactory(ToolBase):
    ...

Referencing in YAML#

After placing your plugin in /var/lib/squirro/genai/plugins, reference it in the deployment config:

tools:
  - $runnable: "examples/tools/dad_joke"

Platform Setup#

sudo mkdir -p /var/lib/squirro/genai/plugins
sudo mkdir -p /etc/squirro/genai.d/deployments

sudo chown -R sqgenai:squirro /var/lib/squirro/genai/plugins
sudo chown -R sqgenai:squirro /etc/squirro/genai.d/deployments

sudo systemctl restart sqgenaid
Versions prior to 3.10.6...

Edit /etc/squirro/genai.d/run.sh and add volume mounts for plugins and deployments.

--volume /var/lib/squirro/genai/plugins/:... \
--volume /etc/squirro/genai.d/deployments/:... \

Accessing Authenticated User Context#

The agent framework makes authenticated user information available to tools via the squirro_client_args variable. It can be useful when tools require authorization or access control logic based on the current user.

In the legacy configuration, you must explicitly wire this context through the deployment YAML and your tool factory.

...
extra_input_mapping:
    /retriever/input_model/client_args: squirro_client_args
...
        auth_kwargs:
            $placeholder: squirro_client_args
...

Then, in your factory class, define a matching argument and forward it to your tool:

class MyToolFactory(ToolBase):
    auth_kwargs: dict[str, Any] | None = None

    def create_runnable(self) -> Runnable:
        return my_tool(auth=self.auth_kwargs)

Troubleshooting#

To troubleshoot issues or unexpected results, the first step is to check the logs of the genai service. You can do that by running the following command in a terminal connected to the Squirro instance:

sudo docker logs -f squirro-service-genai

To open a shell in the container for further investigation or debugging, use the following command:

sudo docker exec -it squirro-service-genai /bin/bash

Getting Assistance#

For assistance with Squirro-specific topics, contact Squirro Support and submit a technical support request. To learn more about LangChain tools, visit the LangChain documentation.