# Coinbase AgentKit

SpriusAI integrates with Coinbase AgentKit by implementing a custom action provider that calls the SpriusAI HTTP API. This adds vault payment capabilities — policy-governed, settled on Solana — to any AgentKit-based agent.

***

## Setup

```typescript
import { AgentKit, ActionProvider, Action, CdpWalletProvider } from "@coinbase/agentkit";
import { getLangChainTools } from "@coinbase/agentkit-langchain";
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { z } from "zod";

const BASE = "https://api.spriusai.com/v1";
const spriusHeaders = {
  "Authorization": `Bearer ${process.env.SPRIUS_API_KEY}`,
  "Content-Type": "application/json",
};
const WALLET_ID = process.env.SPRIUS_WALLET_ID!;

class SpriusAIActionProvider implements ActionProvider {
  getActions(): Action[] {
    return [
      {
        name: "sprius_pay",
        description: "Send USDC from the agent's SpriusAI wallet to a recipient address or domain.",
        schema: z.object({
          to: z.string().describe("Recipient Solana address or domain"),
          amount: z.string().describe("USDC amount as a decimal string"),
          memo: z.string().optional().describe("Payment description"),
        }),
        invoke: async ({ to, amount, memo }) => {
          const res = await fetch(`${BASE}/payments`, {
            method: "POST",
            headers: spriusHeaders,
            body: JSON.stringify({ walletId: WALLET_ID, to, amount, currency: "USDC", memo }),
          });
          const tx = await res.json();
          return JSON.stringify({ status: "confirmed", tx_signature: tx.txSignature, amount, recipient: to });
        },
      },
      {
        name: "sprius_balance",
        description: "Get current USDC balance of the agent's SpriusAI wallet.",
        schema: z.object({}),
        invoke: async () => {
          const res = await fetch(`${BASE}/wallets/${WALLET_ID}`, { headers: spriusHeaders });
          const wallet = await res.json();
          return JSON.stringify({ usdc_balance: wallet.balance });
        },
      },
      {
        name: "sprius_transactions",
        description: "List recent transactions from the agent's SpriusAI wallet.",
        schema: z.object({}),
        invoke: async () => {
          const res = await fetch(`${BASE}/wallets/${WALLET_ID}/transactions`, { headers: spriusHeaders });
          return JSON.stringify(await res.json());
        },
      },
      {
        name: "sprius_pay_agent",
        description: "Initiate an A2A escrow payment to another SpriusAI agent wallet.",
        schema: z.object({
          toWalletId: z.string().describe("Recipient agent wallet ID"),
          amount: z.string().describe("USDC amount"),
          taskDescription: z.string().describe("Description of the task being paid for"),
        }),
        invoke: async ({ toWalletId, amount, taskDescription }) => {
          const res = await fetch(`${BASE}/payments/a2a`, {
            method: "POST",
            headers: spriusHeaders,
            body: JSON.stringify({ fromWalletId: WALLET_ID, toWalletId, amount, currency: "USDC", taskDescription }),
          });
          return JSON.stringify(await res.json());
        },
      },
    ];
  }
}
```

***

## Example with LangChain + AgentKit

```typescript
const spriusProvider = new SpriusAIActionProvider();

const agentKit = await AgentKit.from({
  walletProvider: await CdpWalletProvider.configureWithWallet({ /* ... */ }),
  actionProviders: [spriusProvider],
});

const tools = getLangChainTools(agentKit);

const agent = createReactAgent({
  llm: new ChatAnthropic({ model: "claude-opus-4-6" }),
  tools,
});

await agent.invoke({
  messages: [{ role: "user", content: "Search for the latest AI research papers and pay for API access if needed." }],
});
```

***

## Environment variables

| Variable           | Description                       |
| ------------------ | --------------------------------- |
| `SPRIUS_API_KEY`   | Your SpriusAI API key             |
| `SPRIUS_WALLET_ID` | SpriusAI wallet ID for this agent |

***

## Notes

The `SpriusAIActionProvider` is independent of AgentKit's built-in CDP wallet. It does not replace the CDP wallet — it adds SpriusAI vault payment actions alongside AgentKit's existing on-chain capabilities. The two coexist in the same agent.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.spriusai.com/integrations/coinbase-agentkit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
