Ragex.Agent.ToolSchema (Ragex v0.8.0)

View Source

Converts MCP tool definitions to AI provider tool formats.

Supports:

  • OpenAI function calling format (also used by DeepSeek R1)
  • Anthropic tool use format

Usage

# Get all tools in OpenAI format
tools = ToolSchema.to_openai_tools()

# Get curated agent tools
tools = ToolSchema.agent_tools(:openai)

# Lookup specific tool
{:ok, tool} = ToolSchema.tool_by_name("semantic_search")

Summary

Functions

Get list of agent tool names.

Get curated subset of tools for agent use.

Get all MCP tools converted to Anthropic tool format.

Get all MCP tools converted to OpenAI function calling format.

Lookup a tool definition by name.

Convert a list of tool names to their definitions.

Get tools for a specific provider by name.

Functions

agent_tool_names()

@spec agent_tool_names() :: [String.t()]

Get list of agent tool names.

agent_tools(format \\ :openai)

@spec agent_tools(atom()) :: [map()]

Get curated subset of tools for agent use.

Parameters

  • format - Output format: :openai (default, also for DeepSeek) or :anthropic

Returns

List of tool definitions in the requested format.

to_anthropic_tools()

@spec to_anthropic_tools() :: [map()]

Get all MCP tools converted to Anthropic tool format.

Returns

List of tool definitions in Anthropic format:

[
  %{
    name: "tool_name",
    description: "Tool description",
    input_schema: %{...json_schema...}
  }
]

to_openai_tools()

@spec to_openai_tools() :: [map()]

Get all MCP tools converted to OpenAI function calling format.

This format is also compatible with DeepSeek R1.

Returns

List of tool definitions in OpenAI format:

[
  %{
    type: "function",
    function: %{
      name: "tool_name",
      description: "Tool description",
      parameters: %{...json_schema...}
    }
  }
]

tool_by_name(name, format \\ :mcp)

@spec tool_by_name(String.t(), atom()) :: {:ok, map()} | {:error, :not_found}

Lookup a tool definition by name.

Parameters

  • name - Tool name as string
  • format - Output format: :openai, :anthropic, or :mcp (default)

Returns

  • {:ok, tool} - Tool definition in requested format
  • {:error, :not_found} - Tool not found

tools_by_names(names, format \\ :openai)

@spec tools_by_names([String.t()], atom()) :: [map()]

Convert a list of tool names to their definitions.

Parameters

  • names - List of tool names
  • format - Output format

Returns

List of tool definitions (skips unknown tools).

tools_for_provider(provider, opts \\ [])

@spec tools_for_provider(
  atom(),
  keyword()
) :: [map()]

Get tools for a specific provider by name.

Parameters

  • provider - Provider atom: :deepseek_r1, :openai, :anthropic, :ollama
  • opts - Options:
    • :only - List of tool names to include (default: all agent tools)
    • :except - List of tool names to exclude

Returns

List of tool definitions in the appropriate format for the provider.