ADK.Tool.ModuleTool (ADK v0.0.1-alpha.1)

Copy Markdown View Source

A tool backed by a module instead of an anonymous function.

This solves the problem of tools with anonymous functions not being usable in compile-time Plug config (e.g., plug MyPlug, tools: [...]).

Usage

Define a module implementing ADK.Tool:

defmodule MyTool do
  @behaviour ADK.Tool

  @impl true
  def name, do: "my_tool"

  @impl true
  def description, do: "Does something useful"

  @impl true
  def parameters, do: %{type: "object", properties: %{input: %{type: "string"}}}

  @impl true
  def run(_ctx, args), do: {:ok, "Got: #{args["input"]}"}
end

Then wrap it:

tool = ADK.Tool.ModuleTool.new(MyTool)

Or use it directly — any module implementing ADK.Tool can be used as a tool struct via ADK.Tool.ModuleTool.new/1.

Summary

Functions

Create a tool struct from a module implementing ADK.Tool.

Execute the module tool.

Types

t()

@type t() :: %ADK.Tool.ModuleTool{
  description: String.t(),
  module: module(),
  name: String.t(),
  parameters: map()
}

Functions

new(module, opts \\ [])

@spec new(
  module(),
  keyword()
) :: t()

Create a tool struct from a module implementing ADK.Tool.

run(module_tool, ctx, args)

@spec run(t(), ADK.ToolContext.t(), map()) :: ADK.Tool.result()

Execute the module tool.