Skip to content

Runnable As Tool

Runnable As Tool is a helper that turns any runnable piece of code into a reusable tool for your Nappai workflows.
It automatically figures out what data the runnable expects and what it returns, so you can plug it into other components without writing extra code.

How it Works

When you drop a runnable into the Runnable field, the component wraps that runnable in a tool interface.
It inspects the runnable’s signature to guess the names of the input and output keys.
The guessed keys are then used by the tool when it is called from other parts of your dashboard.
If you want more control, you can override the guesses by providing a custom Tool Arguments Schema and Tool Description.

Inputs

  • Runnable: The code or function you want to turn into a tool.
  • Input: The data you want to pass to the tool. Provide it in JSON format.
  • Return Direct: If checked, the component will return the tool itself instead of running it immediately.
  • Tool Description: A short explanation of what the tool does.
  • Tool Arguments Schema: A JSON schema that describes the arguments the tool expects.
  • Tool Name: The name you want to give to the created tool.
  • Verbose: If checked, the tool’s output will be printed to the console for debugging.

Outputs

  • Result: The output of the runnable, returned as a Message.
  • Tool: The created tool object (BaseTool) that can be used elsewhere in your workflow.

Usage Example

  1. Create a simple addition runnable

    def add_numbers(a: int, b: int) -> int:
    return a + b
  2. Configure the component

    • Runnable: add_numbers
    • Input: {"a": 5, "b": 7}
    • Tool Name: AddNumbersTool
    • Tool Description: Adds two integers together.
    • Tool Arguments Schema:
      {
      "type": "object",
      "properties": {
      "a": {"type": "integer"},
      "b": {"type": "integer"}
      },
      "required": ["a", "b"]
      }
    • Return Direct: unchecked
    • Verbose: checked
  3. Run the component
    The Result output will be 12, and the Tool output can be connected to other components that need an addition tool.

  • BaseRunnableToolComponent – The parent class that provides the core logic for wrapping runnables.
  • Runnable – The component that lets you define and test runnables before turning them into tools.
  • Tool Builder – A higher‑level component that can create tools from multiple runnables at once.

Tips and Best Practices

  • Keep the runnable’s input and output types simple (e.g., primitives or plain objects) to avoid serialization issues.
  • Use the Tool Arguments Schema to enforce validation and help the system guess the correct keys.
  • Turn on Verbose only when debugging; it can clutter logs in production.
  • If you need the tool to be reused in many places, set Return Direct so you can store the tool object and call it later.

Security Considerations

  • The runnable code is executed on the same machine that runs Nappai.
  • Avoid inserting untrusted code into the Runnable field, as it could execute arbitrary commands.
  • Use the Tool Arguments Schema to restrict the types of inputs the tool can accept, reducing the risk of injection attacks.