> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arcenpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Framework Adapters

> First-class adapters for LangChain, Vercel AI SDK, OpenAI function calling, and Anthropic Claude tool use.

The `@arcenpay/agent` SDK provides pre-built, schema-compliant tool adapters for leading AI agent frameworks. These adapters expose ArcenPay's autonomous payment, balance checking, session vault funding, and checkout capabilities directly to LLMs without requiring manual schema definitions.

## Available Agent Tools

Every framework adapter exposes the standard set of 6 core agent actions:

| Tool Name                       | Description                                                                              |
| ------------------------------- | ---------------------------------------------------------------------------------------- |
| `arcenpay_check_balance`        | Checks available on-chain balance (Session Vault, direct wallet token, or native gas).   |
| `arcenpay_fund_session`         | Deposits USDC into an ArcenPay session vault for autonomous micro-payments.              |
| `arcenpay_resolve_payment_link` | Discovers and inspects a payment link slug or URL without spending funds.                |
| `arcenpay_pay_payment_link`     | Executes autonomous crypto payment for an ArcenPay payment link within safety limits.    |
| `arcenpay_create_payment_link`  | Programmatically creates a payment link so the agent can charge other agents or humans.  |
| `arcenpay_fetch`                | Makes an autonomous HTTP request that auto-negotiates `402 Payment Required` challenges. |

***

## 1. OpenAI, Kilocode & OpenAI-Compatible APIs

Use `toOpenAITools(agent)` to generate tool definitions compliant with the OpenAI Chat Completions API format. Works with OpenAI (`gpt-4o`, `gpt-4o-mini`), Kilocode (`kilo-auto/free`), Groq, Together, and OpenRouter.

```ts theme={null}
import { ArcenAgent, toOpenAITools, executeOpenAITool } from "@arcenpay/agent";
import OpenAI from "openai";

const agent = new ArcenAgent({
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  chainId: 5042002, // Arc Testnet (or 8453 for Base, 677 for BOT Chain)
  maxAutoApprove: "5.00",
});

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

// 1. Convert ArcenPay tools to OpenAI format
const tools = toOpenAITools(agent);

const messages: any[] = [
  { role: "user", content: "Check my agent balance and pay for https://app.arcenpay.com/pay/dataset-01" },
];

// 2. Call LLM with tools
const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages,
  tools,
});

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

// 3. Handle and execute tool calls
if (choice.tool_calls) {
  for (const toolCall of choice.tool_calls) {
    const result = await executeOpenAITool(
      agent,
      toolCall.function.name,
      JSON.parse(toolCall.function.arguments)
    );

    messages.push(choice);
    messages.push({
      role: "tool",
      tool_call_id: toolCall.id,
      content: JSON.stringify(result),
    });
  }

  // 4. Get final response from model
  const finalResponse = await openai.chat.completions.create({
    model: "gpt-4o",
    messages,
  });

  console.log(finalResponse.choices[0].message.content);
}
```

***

## 2. LangChain & LangGraph

Use `toLangChainTools(agent)` to instantiate LangChain-compatible tool instances. These can be passed directly to LangChain agents, `createReactAgent`, or LangGraph `ToolNode`.

```ts theme={null}
import { ArcenAgent, toLangChainTools } from "@arcenpay/agent";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const agent = new ArcenAgent({
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  chainId: 8453,
  maxDailySpend: 50.00,
});

// Generate LangChain tools
const tools = toLangChainTools(agent);

const model = new ChatOpenAI({ model: "gpt-4o" });
const app = createReactAgent({ llm: model, tools });

const result = await app.invoke({
  messages: [{ role: "user", content: "Check my ArcenPay session vault balance." }],
});

console.log(result.messages[result.messages.length - 1].content);
```

***

## 3. Vercel AI SDK

Use `toVercelTools(agent)` with `generateText` or `streamText` from the `ai` package.

```ts theme={null}
import { ArcenAgent, toVercelTools } from "@arcenpay/agent";
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";

const agent = new ArcenAgent({
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  chainId: 5042002,
  maxAutoApprove: "2.00",
});

const result = await generateText({
  model: openai("gpt-4o"),
  tools: toVercelTools(agent),
  maxSteps: 5, // Allows autonomous multi-step execution
  prompt: "What is my agent's treasury balance, and can I afford a $1.00 API inference?",
});

console.log(result.text);
```

***

## 4. Anthropic Claude (Messages API)

Use `toAnthropicTools()` and `executeAnthropicTool(agent, name, input)` for direct integration with the Anthropic Messages API.

```ts theme={null}
import { ArcenAgent, toAnthropicTools, executeAnthropicTool } from "@arcenpay/agent";
import Anthropic from "@anthropic-ai/sdk";

const agent = new ArcenAgent({
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  chainId: 8453,
});

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const tools = toAnthropicTools();

const response = await anthropic.messages.create({
  model: "claude-3-5-sonnet-20241022",
  max_tokens: 1024,
  tools: tools as any,
  messages: [{ role: "user", content: "Check my agent's on-chain balance." }],
});

for (const block of response.content) {
  if (block.type === "tool_use") {
    const toolResult = await executeAnthropicTool(agent, block.name, block.input as any);
    console.log("Tool Result:", toolResult);
  }
}
```

***

## Package Reference

```ts theme={null}
import {
  // Tool Schemas & Generic Dispatcher
  ARCENPAY_AGENT_TOOL_SCHEMAS,
  executeArcenAgentTool,

  // LangChain
  createArcenAgentLangChainTools,
  toLangChainTools,

  // Vercel AI SDK
  createArcenAgentVercelAITools,
  toVercelTools,

  // OpenAI & Kilocode
  createArcenAgentOpenAITools,
  toOpenAITools,
  executeOpenAITool,

  // Anthropic Claude
  createArcenAgentAnthropicTools,
  toAnthropicTools,
  executeAnthropicTool,
} from "@arcenpay/agent";
```
