ADK.Tool behaviour (adk_ex v1.1.0)

Copy Markdown View Source

Behaviour for ADK tools.

Tools are functions that agents can call during execution. Each tool provides a declaration (JSON Schema) for the LLM, and a run/3 function for actual execution.

Summary

Callbacks

Returns the tool's function declaration for the LLM.

Returns a human-readable description of the tool.

Returns whether this tool is long-running (async).

Returns the tool's unique name.

Executes the tool with the given context and arguments.

Functions

Calls declaration/1 on any tool struct via its implementing module.

Calls description/1 on any tool struct via its implementing module.

Returns whether a tool is long-running.

Calls name/1 on any tool struct via its implementing module.

Calls run/3 on any tool struct via its implementing module.

Callbacks

declaration(tool)

@callback declaration(tool :: struct()) :: map()

Returns the tool's function declaration for the LLM.

Returns a map with "name", "description", and "parameters" (JSON Schema).

description(tool)

@callback description(tool :: struct()) :: String.t()

Returns a human-readable description of the tool.

long_running?(tool)

(optional)
@callback long_running?(tool :: struct()) :: boolean()

Returns whether this tool is long-running (async).

name(tool)

@callback name(tool :: struct()) :: String.t()

Returns the tool's unique name.

run(tool, context, args)

@callback run(tool :: struct(), context :: ADK.Tool.Context.t(), args :: map()) ::
  {:ok, map()} | {:error, term()}

Executes the tool with the given context and arguments.

Returns {:ok, result_map} on success or {:error, reason} on failure.

Functions

declaration(tool)

@spec declaration(struct()) :: map()

Calls declaration/1 on any tool struct via its implementing module.

description(tool)

@spec description(struct()) :: String.t()

Calls description/1 on any tool struct via its implementing module.

long_running?(tool)

@spec long_running?(struct()) :: boolean()

Returns whether a tool is long-running.

name(tool)

@spec name(struct()) :: String.t()

Calls name/1 on any tool struct via its implementing module.

run(tool, context, args)

@spec run(struct(), ADK.Tool.Context.t(), map()) :: {:ok, map()} | {:error, term()}

Calls run/3 on any tool struct via its implementing module.