# Sui Agent Building

\
\&#xNAN;*Prerequisite: `make-agent` v0.3.1+ installed*

***

#### 1. Clone the Boilerplate & Install

```bash
git clone https://github.com/BitteProtocol/agent-next-boilerplate.git
cd agent-next-boilerplate
pnpm install
```

This gives you the core agent framework, UI sandbox, and plugin manifest support.

***

#### 2. Configure Your Bitte API Key

1. Visit 🔑 <https://key.bitte.ai> and generate a key.
2. Copy `.env.example → .env` and insert:

   ```dotenv
   dotenvCopyEditBITTE_API_KEY="bitte_YOUR_KEY_HERE"
   ```

***

#### 3. Wire Up Sui: Add Your Transaction Tool

In `tools/`, change any of the routes to return a sui transaction, check the sui ts sdk for more information on how to create Sui Transactions:

```ts

  const { senderAddress, recipientAddress, amountInSui, network } = args;
  const tx = new Transaction();
  const MIST_PER_SUI = 1e9;
  const amountInMist = Math.floor(amountInSui * MIST_PER_SUI);

  if (amountInMist > Number.MAX_SAFE_INTEGER) {
    throw new Error('Amount exceeds safe integer limit');
  }
  
  const [coin] = tx.splitCoins(tx.gas, [tx.pure.u64(BigInt(amountInMist))]);
  tx.setSender(senderAddress);
  tx.transferObjects([coin], tx.pure.address(recipientAddress));

  const txBytes = await tx.build({ client: suiClientFor(network) });
  return { data: { suiTransactionBytes: Buffer.from(txBytes).toString('base64') } };
```

***

#### 4. Declare Your Tool in the Plugin Manifest

Open `ai-plugin/manifest.json` (or wherever your manifest lives) and add the corresponding spec for your endpoint\
\
Since this is a next js project the route path will correspond to the folder&#x20;

```jsonc
'/api/send-sui': {
  post: {
    summary: 'Send a Sui tokens',
    description: 'Accept the args and return a valid sui transaction in bytes to send tokens to an address',
    operationId: 'generateSuiTx',
    requestBody: {
      required: true,
      content: {
        'application/json': {
          schema: {
            type: 'object',
            properties: {
              senderAddress: {
                type: 'string',
                description: 'Address sending SUI',
              },
              recipientAddress: {
                type: 'string',
                description: 'Address receiving SUI',
              },
              amountInSui: {
                type: 'number',
                description: 'Amount of SUI to send',
              },
              network: {
                type: 'string',
                enum: ['mainnet', 'testnet', 'devnet'],
                default: 'mainnet',
                description: 'Which Sui network to use',
              },
            },
            required: ['senderAddress', 'recipientAddress', 'amountInSui'],
          },
        },
      },
    },
    responses: {
      '200': {
        description: 'Successful response',
        content: {
          'application/json': {
            schema: {
              type: 'object',
              properties: {
                success: {
                  type: 'boolean',
                  description: 'Whether the transaction was successfully built or validated',
                },
                data: {
                  type: 'object',
                  description: 'Additional result data',
                },
              },
            },
          },
        },
      },
      '500': {
        description: 'Error response',
        content: {
          'application/json': {
            schema: {
              type: 'object',
              properties: {
                error: {
                  type: 'string',
                  description: 'Error message',
                },
              },
            },
          },
        },
      },
    },
  },
},
```

***

#### 5. Add `generate-sui-tx` to the Tools Array

To enable the review transaction component in the frontend, add the `generate-sui-tx` primitive to the tools array in your configuration file:

```jsonc
{
  "tools": [
 tools: [
          { type: 'get-sui-balances' },
          { type: 'generate-sui-tx' },
        ],
```

This update ensures that the frontend can display the transaction review component appropriately.

#### 6. Define Behaviour

To control how your agent behaves, customize its **instructions**—this is the equivalent of setting the system prompt. Use this to tailor the agent’s behavior to your tool’s needs. For example, you might instruct it to confirm addresses or amounts, adopt a specific tone or personality, or behave deterministically in certain scenarios.

If the transaction review screen isn’t appearing as expected, you can explicitly instruct the agent to show it after your tool call.

#### 7. Run Locally & Test

```bash
pnpm dev
```

* The console UI opens your chat sandbox.
* Ask the agent to build the transaction related to your tool
* The agent will call your `tool` and then call `generate-sui-tx` to display the transaction signing component so you can try sending your transaction

***

#### 7. Deploy Your Agent

1. Push to GitHub.
2. Deploy to vercel or any provider
3. Update your URL env or hard code it in the spec

   ```bash
   BITTE_AGENT_URL="https://my-sui-agent.vercel.app"
   ```
4. Run:

   ```bash
   make-agent deploy
   ```

This validates your key, registers your plugin URL, and you’re live!


---

# 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.bitte.ai/agents/sui-agent-building.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.
