Jido.AI.Actions.OpenaiEx.ToolHelper (Jido AI v0.5.2)

View Source

Helper module for handling tool calling with OpenAiEx. Provides functions to convert Jido.Action to OpenAI tool format and handle tool responses.

Summary

Functions

Handles a tool call response from OpenAI. Executes the appropriate action with the given parameters.

Processes a chat completion response that may contain tool calls. If tool calls are present, executes them and returns the results.

Converts a list of Jido.Action modules to OpenAI tool format. Each action must implement the Jido.Action.Tool protocol.

Functions

handle_tool_call(tool_call, available_actions)

@spec handle_tool_call(map(), [module()]) :: {:ok, term()} | {:error, term()}

Handles a tool call response from OpenAI. Executes the appropriate action with the given parameters.

Parameters

  • tool_call: The tool call object from OpenAI response
  • available_actions: List of available Jido.Action modules

Returns

  • {:ok, result} - where result is the output of the action
  • {:error, reason} - if the tool call cannot be handled

process_response(response, available_actions)

@spec process_response(map(), [module()]) :: {:ok, map()} | {:error, term()}

Processes a chat completion response that may contain tool calls. If tool calls are present, executes them and returns the results.

Parameters

  • response: The chat completion response from OpenAI
  • available_actions: List of available Jido.Action modules

Returns

  • {:ok, %{content: content, tool_results: results}} - where content is the assistant's message
  • {:error, reason} - if tool calls cannot be processed

to_openai_tools(actions)

@spec to_openai_tools([module()]) :: {:ok, [map()]} | {:error, term()}

Converts a list of Jido.Action modules to OpenAI tool format. Each action must implement the Jido.Action.Tool protocol.

Parameters

  • actions: List of Jido.Action modules that implement Jido.Action.Tool

Returns

  • {:ok, tools} - where tools is a list of OpenAI tool specifications
  • {:error, reason} - if any action doesn't implement the protocol