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

Copy Markdown View Source

Wraps any function as a tool with declaration metadata.

The func field accepts:

  • An anonymous function (arity 1 or 2) — for runtime use
  • An MFA tuple {Module, :function, extra_args} — compile-time safe
  • A plain MF tuple {Module, :function} — shorthand for {Module, :function, []}

MFA tuples are called as Module.function(ctx, args, ...extra_args) (arity 2+) or Module.function(args, ...extra_args) if the function has no context parameter.

Examples

# Anonymous function (runtime only)
tool = ADK.Tool.FunctionTool.new(:greet,
  description: "Greet someone",
  func: fn _ctx, %{"name" => name} -> {:ok, "Hello, #{name}!"} end,
  parameters: %{
    type: "object",
    properties: %{name: %{type: "string"}},
    required: ["name"]
  }
)

# MFA tuple (compile-time safe, works in Plug init/1)
tool = ADK.Tool.FunctionTool.new(:greet,
  description: "Greet someone",
  func: {MyApp.Tools, :greet},
  parameters: %{
    type: "object",
    properties: %{name: %{type: "string"}},
    required: ["name"]
  }
)

Summary

Functions

Create a new function tool.

Execute the function tool.

Types

mfa_tuple()

@type mfa_tuple() :: {module(), atom(), list()} | {module(), atom()}

t()

@type t() :: %ADK.Tool.FunctionTool{
  description: String.t(),
  func: function() | mfa_tuple(),
  name: String.t(),
  parameters: map()
}

Functions

new(name, opts)

@spec new(
  atom() | String.t(),
  keyword()
) :: t()

Create a new function tool.

run(function_tool, ctx, args)

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

Execute the function tool.