dex-skills v0.1.0

Function Calling

dex-skills exports tool definitions that can be used directly with the Anthropic and OpenAI function calling APIs. This lets language models invoke dex-skills operations as part of an agentic workflow.

Importing Tool Definitions

import.ts
import { toolDefinitions } from "dex-skills";

// toolDefinitions is an array of tool objects in Anthropic format:
// { name, description, input_schema }
console.log(toolDefinitions.map(t => t.name));
// ["dex_platforms", "dex_launch", "dex_get_token", "dex_list_tokens"]

Integration Examples

The exported toolDefinitions are already in the format expected by the Anthropic API. Pass them directly as the tools parameter.

anthropic-example.ts
import Anthropic from "@anthropic-ai/sdk";
import { toolDefinitions, createSkills, getSkill } from "dex-skills";

const client = new Anthropic();
const skills = createSkills({
  wallets: {
    solana: {
      privateKey: process.env.SOLANA_PRIVATE_KEY,
      rpcUrl: "https://api.mainnet-beta.solana.com",
    },
  },
});

const response = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  tools: toolDefinitions,
  messages: [
    { role: "user", content: "What tokens were recently launched on Pump.fun?" },
  ],
});

// Handle tool_use blocks in the response
for (const block of response.content) {
  if (block.type === "tool_use") {
    // Dispatch tool calls to the appropriate skill method
    let toolResult;
    if (block.name === "dex_list_tokens") {
      const skill = getSkill(skills, block.input.platform);
      toolResult = await skill.listTokens(block.input);
    } else if (block.name === "dex_get_token") {
      const skill = getSkill(skills, block.input.platform);
      toolResult = await skill.getTokenInfo(block.input.tokenAddress);
    } else if (block.name === "dex_launch") {
      const skill = getSkill(skills, block.input.platform);
      toolResult = await skill.launch(block.input);
    }

    // Send the result back to continue the conversation
    const followUp = await client.messages.create({
      model: "claude-sonnet-4-20250514",
      max_tokens: 1024,
      tools: toolDefinitions,
      messages: [
        { role: "user", content: "What tokens were recently launched on Pump.fun?" },
        { role: "assistant", content: response.content },
        {
          role: "user",
          content: [
            {
              type: "tool_result",
              tool_use_id: block.id,
              content: JSON.stringify(toolResult),
            },
          ],
        },
      ],
    });
  }
}

OpenAI uses a slightly different format. Convert input_schema to parameters and wrap each definition in a function object.

openai-example.ts
import OpenAI from "openai";
import { toolDefinitions, createSkills, getSkill } from "dex-skills";

const client = new OpenAI();
const skills = createSkills({
  wallets: {
    base: {
      privateKey: process.env.BASE_PRIVATE_KEY,
      rpcUrl: "https://mainnet.base.org",
    },
  },
});

// Convert Anthropic tool format to OpenAI function format
const openAiTools = toolDefinitions.map((tool) => ({
  type: "function" as const,
  function: {
    name: tool.name,
    description: tool.description,
    parameters: tool.input_schema,
  },
}));

const response = await client.chat.completions.create({
  model: "gpt-4o",
  tools: openAiTools,
  messages: [
    { role: "user", content: "List the top 5 tokens on Zora by market cap" },
  ],
});

const message = response.choices[0].message;

if (message.tool_calls) {
  for (const call of message.tool_calls) {
    const args = JSON.parse(call.function.arguments);

    // Dispatch tool calls to the appropriate skill method
    let toolResult;
    const skill = getSkill(skills, args.platform);
    if (call.function.name === "dex_list_tokens") {
      toolResult = await skill.listTokens(args);
    } else if (call.function.name === "dex_get_token") {
      toolResult = await skill.getTokenInfo(args.tokenAddress);
    } else if (call.function.name === "dex_launch") {
      toolResult = await skill.launch(args);
    }

    // Send the result back
    const followUp = await client.chat.completions.create({
      model: "gpt-4o",
      tools: openAiTools,
      messages: [
        { role: "user", content: "List the top 5 tokens on Zora by market cap" },
        message,
        {
          role: "tool",
          tool_call_id: call.id,
          content: JSON.stringify(toolResult),
        },
      ],
    });
  }
}

Tool Schema Reference

Each tool definition includes a JSON Schema describing its input parameters. The four tools correspond directly to the SDK methods:

  • dex_platforms -- No parameters. Returns the list of supported platforms.
  • dex_launch -- Accepts platform, name, symbol, and optional fields. See launch().
  • dex_get_token -- Accepts platform and tokenAddress. See getTokenInfo().
  • dex_list_tokens -- Accepts platform and optional sorting/pagination. See listTokens().
Private keys in function calling
When the model calls dex_launch, your application code is responsible for injecting the private key before executing the tool. Never include private keys in the conversation context sent to the model.