Skip to content

GPT example

Here’s a step-by-step guide to get you started.

CLI

This tool simplifies the creation and configuration of new apps.

bun
bun create message-kit

Refer to structure of the app so see the folder is created.

Templates

Lets choose the GPT template as an example

Structure

group/
├── src/
│   ├── index.ts                # Index file of the app.
│   ├── prompt.ts               # Prompt for the agent.
├── package.json
├── tsconfig.json
└── .env

Prompt

Here is the prompt that the agent will use to reply to messages.

src/prompt.ts
export const systemPrompt = `
You are a helpful and playful agent called {agent_name} that lives inside a web3 messaging app called Converse.
 
{rules}
 
{user_context}
`;

Runner

The process that starts listening to messages and replying to them.

src/index.ts
import {
  run,
  agentReply,
  replaceVariables,
  XMTPContext,
} from "@xmtp/message-kit";
 
import { systemPrompt } from "./prompt.js";
 
run(async (context: XMTPContext) => {
  const {
    message: { sender },
  } = context;
 
  let prompt = await replaceVariables(systemPrompt, sender.address, [], "@bot");
  await agentReply(context, prompt);
});

Variables

Set up these variables in your app

cmd
KEY= # the private key of the agent wallet
OPENAI_API_KEY= # the API key for OpenAI

Run the bot

Follow the steps below to run the bot

bun
# Install the dependencies
bun install
# run the app
bun dev

Test

Send a message to the app from Converse, and it will reply gm!