View Source SwarmEx.Tool behaviour (SwarmEx v0.2.0)

DEPRECATED: This module is deprecated. Tools should be implemented as regular modules with functions instead.

Migration Guide

Instead of using the Tool behavior, define your tools as regular modules with functions:

Before:

defmodule MyTool do
  @behaviour SwarmEx.Tool

  @impl true
  def execute(args) do
    # Perform tool operation
    {:ok, result}
  end

  @impl true
  def validate(args) do
    # Validate incoming arguments
    :ok
  end

  @impl true
  def cleanup(args) do
    # Cleanup any resources
    :ok
  end
end

After:

defmodule MyTool do
  def process(args) do
    # Validate args if needed
    with :ok <- validate_args(args),
         {:ok, result} <- do_process(args) do
      cleanup(args)
      {:ok, result}
    end
  end

  defp validate_args(args) do
    # Optional validation
    :ok
  end

  defp do_process(args) do
    # Main processing logic
    {:ok, result}
  end

  defp cleanup(args) do
    # Optional cleanup
    :ok
  end
end

The new approach:

  • Is simpler and more idiomatic Elixir
  • Gives more flexibility in function naming and implementation
  • Allows for better integration with other libraries
  • Reduces boilerplate code
  • Makes testing easier

Summary

Functions

DEPRECATED: Use direct function calls instead.

get_config(tool) deprecated

DEPRECATED: Use regular module configuration instead.

DEPRECATED: Use regular module configuration instead.

validate_tool(tool) deprecated

DEPRECATED: Use regular module definition instead.

Types

@type args() :: term()
@type cleanup_result() :: :ok | {:error, term()}
@type options() :: [
  timeout: non_neg_integer(),
  retries: non_neg_integer(),
  validate_args: boolean()
]
@type result() :: {:ok, term()} | {:error, term()}
@type t() :: module()
@type validation_result() :: :ok | {:error, term()}

Callbacks

@callback cleanup(args()) :: cleanup_result()
@callback execute(args()) :: result()
@callback validate(args()) :: validation_result()

Functions

Link to this function

execute(tool, args, opts \\ [])

View Source
This function is deprecated. Tools should be implemented as regular modules with functions.
@spec execute(t(), args(), options()) :: result()

DEPRECATED: Use direct function calls instead.

Safely executes a tool with the given arguments and options.

Options

  • :timeout - Maximum time in milliseconds to wait (default: 5000)
  • :retries - Number of retry attempts (default: 3)
  • :validate_args - Whether to validate arguments (default: true)
This function is deprecated. Tools should be implemented as regular modules with functions.
@spec get_config(t()) :: {:ok, keyword()} | {:error, term()}

DEPRECATED: Use regular module configuration instead.

Retrieves the configuration for a registered tool.

Link to this function

register(tool, config \\ [])

View Source
This function is deprecated. Tools should be implemented as regular modules with functions.
@spec register(
  t(),
  keyword()
) :: :ok | {:error, term()}

DEPRECATED: Use regular module configuration instead.

Registers a tool configuration in the runtime.

This function is deprecated. Tools should be implemented as regular modules with functions.
@spec validate_tool(t()) :: :ok | {:error, term()}

DEPRECATED: Use regular module definition instead.

Validates that a module implements the Tool behavior correctly.