View Source Jido.Workflow.Tool (Jido v1.0.0)

Provides functionality to convert Jido Workflows into tool representations.

This module allows Jido Workflows 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 workflow's schema.

Executes an workflow 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 Workflow 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 workflow's schema.

Arguments

  • schema - The NimbleOptions schema from the workflow.

Returns

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

execute_workflow(workflow, params, context)

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

Executes an workflow 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(workflow)

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

Converts a Jido Workflow into a tool representation.

Arguments

  • workflow - The module implementing the Jido.Action behavior.

Returns

A map representing the workflow as a tool, compatible with systems like LangChain.

Examples

iex> tool = Jido.Workflow.Tool.to_tool(MyWorkflow)
%{
  name: "my_workflow",
  description: "Performs a specific task",
  function: #Function<...>,
  parameters_schema: %{...}
}