Jido. Action. Tool
(Jido Action v2.3.0)
View Source
Provides functionality to convert Jido Actions into generic tool representations.
This module allows Jido Actions to be converted into standardized tool maps that can be used by various AI integration layers.
Tool execution preserves the legacy {:ok, json} / {:error, json} contract.
Successful results are sanitized before JSON encoding, and failures still
serialize as %{"error" => binary} payloads with sanitizer-backed fallback
when raw inspection is unsafe.
Tool Formats
to_tool/1- Returns a generic tool map with name, description, function, and schemato_tool/2- Same asto_tool/1with JSON schema options (e.g., strict mode)
Utility Functions
convert_params_using_schema/2- Normalizes LLM arguments (string keys → atom keys, type coercion)build_parameters_schema/1- Converts action schema to JSON Schema formatbuild_parameters_schema/2- Same asbuild_parameters_schema/1with schema optionsexecute_action/3- Executes an action with schema-based param conversion
Summary
Functions
Builds a parameters schema for the tool based on the action's schema.
Helper function to convert params using schema information.
Executes an action and formats the result for tool output.
Converts a Jido Exec into a tool representation.
Types
Functions
@spec build_parameters_schema(Jido.Action.Schema.t()) :: map()
Builds a parameters schema for the tool based on the action's schema.
Arguments
schema- The NimbleOptions or Zoi schema from the action.
Returns
A map representing the parameters schema in a format compatible with LangChain.
@spec build_parameters_schema( Jido.Action.Schema.t(), keyword() ) :: map()
Helper function to convert params using schema information.
Converts string keys to atom keys and handles type conversion based on schema. Supports both atom and string input keys, and preserves unknown keys (open validation).
Executes an action and formats the result for tool output.
This function is typically used as the function value in the tool representation.
Error payloads intentionally remain the legacy %{"error" => binary} JSON
shape for compatibility.
Converts a Jido Exec into a tool representation.
Arguments
action- The module implementing the Jido.Action behavior.
Returns
A map representing the action as a tool, compatible with systems like LangChain.
Examples
iex> tool = Jido.Action.Tool.to_tool(MyExec)
%{
name: "my_action",
description: "Performs a specific task",
function: #Function<...>,
parameters_schema: %{...}
}