Jido.Action.Tool (Jido v1.1.0-rc.2)

View Source

Provides functionality to convert Jido Execs into tool representations.

This module allows Jido Execs to be easily integrated with AI systems like LangChain or Instructor by converting them into a standardized tool format.

Summary

Functions

Builds a parameters schema for the tool based on the action's schema.

Executes an action and formats the result for tool output.

Converts a NimbleOptions type to a JSON Schema type.

Converts a NimbleOptions parameter definition to a JSON Schema representation.

Converts a Jido Exec into a tool representation.

Types

tool()

@type tool() :: %{
  name: String.t(),
  description: String.t(),
  function: (map(), map() -> {:ok, String.t()} | {:error, String.t()}),
  parameters_schema: map()
}

Functions

build_parameters_schema(schema)

@spec build_parameters_schema(keyword()) :: map()

Builds a parameters schema for the tool based on the action's schema.

Arguments

  • schema - The NimbleOptions schema from the action.

Returns

A map representing the parameters schema in a format compatible with LangChain.

convert_params_using_schema(params, schema)

execute_action(action, params, context)

@spec execute_action(module(), map(), map()) ::
  {:ok, String.t()} | {:error, String.t()}

Executes an action and formats the result for tool output.

This function is typically used as the function value in the tool representation.

nimble_type_to_json_schema_type(arg1)

@spec nimble_type_to_json_schema_type(atom()) :: String.t()

Converts a NimbleOptions type to a JSON Schema type.

Arguments

  • type - The NimbleOptions type.

Returns

A string representing the equivalent JSON Schema type.

parameter_to_json_schema(opts)

@spec parameter_to_json_schema(keyword()) :: %{
  type: String.t(),
  description: String.t()
}

Converts a NimbleOptions parameter definition to a JSON Schema representation.

Arguments

  • opts - The options for a single parameter from the NimbleOptions schema.

Returns

A map representing the parameter in JSON Schema format.

to_tool(action)

@spec to_tool(module()) :: tool()

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: %{...}
}