Claudex.Tool.Dispatch (Claudex v0.6.1)

Copy Markdown View Source

Calls a registered tool function with a decoded tool_use input map.

Arguments are matched to the function's parameters by name, in the order the tool's entry declares.

Summary

Types

One dispatchable tool: its wire name, the function it calls, and that function's parameters in order.

Functions

Looks up name in entries and calls the matching function on module with args (typically a Claudex.ContentBlock.ToolUse.input map).

Types

entry()

@type entry() :: %{
  name: String.t(),
  function: atom(),
  params: [Claudex.Tool.Schema.param()]
}

One dispatchable tool: its wire name, the function it calls, and that function's parameters in order.

error()

@type error() ::
  {:unknown_tool, String.t()}
  | {:missing_args, [String.t()]}
  | {:tool_refused, String.t()}
  | {:tool_raised, String.t()}

Functions

call(module, entries, name, args)

@spec call(module(), [entry()], String.t(), map()) ::
  {:ok, term()} | {:error, error()}

Looks up name in entries and calls the matching function on module with args (typically a Claudex.ContentBlock.ToolUse.input map).

A trailing optional parameter left out of args gets the function's own default. An optional parameter left out while a later one is present can't fall back to its default — Elixir can only skip defaults from the end of the argument list — so it's called with nil instead; keep optional tool parameters to the ones you're fine skipping that way.