Agents
In this document, you'll learn about the structure and components of an agent project. We'll cover the following sections:
- Project files: Understand the basic file structure of an agent project.
- Agent: Learn how to set up and run an agent using XMTP's message-kit.
- Skills: Discover how to define the actions your agent can perform.
- Plugins: Learn about plugins that can enhance the capabilities of your agent's skills.
- Vibes: Understand how to define the personality and style of your agent.
Project files
Each agent project consists of the following basic structure:
agent/
├── src/
│ └── index.ts
│ └── skills/
│ └── ...
├── tsconfig.json
├── package.json
└── .envAgent
This is the main function that runs the listener.
import { agentReply, Context, createAgent } from "@xmtp/message-kit";
export const agent = createAgent({
name: "GPT Bot",
description: "Use GPT to generate text responses.",
tag: "@bot",
onMessage: async (context: Context) => {
await agentReply(context);
},
}).run();Config
config: {
/* Optional properties */
}privateKey: the private key of the agent wallet, like any normal wallet private key.experimental: experimental features like logging all group messages. Default isfalse.attachments: to receive attachments. Default isfalse.gptModel: model to be used. Default isgpt-4o.client: Optional parameters to pass to the XMTP client.agent: Custom agent to be used. Default is to create the skills in thesrc/skills.tsfile.hideInitLogMessage: hide the init log message with messagekit logo and stuffmemberChange: if true, member changes will be enabled, like adding members to the group
Skills
Skills are the actions that the agent can perform. They are defined in the src/skills/your-skill.ts file.
import { Skill } from "@xmtp/message-kit";
export const skills: Skill[] = [
{
skill: // name of the skill
handler: handler(context)
examples: // examples of the skill
description: // description of the skill
params: // params of the skill
},
];Learn more about skills in the Skills section.
Plugins
Plugins are the plugins that the Skills can use. They are defined in the plugins/your-plugin.ts file.
import { createClient } from "@redis/client";
import type { RedisClientType } from "@redis/client";
export const getRedisClient = async () => {
const client = createClient({
url: process.env.REDIS_CONNECTION_STRING,
});
client.on("error", (err) => {
console.error("Redis client error:", err);
});
await client.connect();
return client as RedisClientType;
};See Plugins for more information.
Vibes
Vibes are the personalities of the agent. They are defined in the src/vibes/your-vibe.ts file.
import { Vibe } from "@xmtp/message-kit";
export const chill: Vibe = {
vibe: // name of the vibe
description: // description of the vibe
tone: // tone of the vibe
style: // style of the vibe
};See Vibes for more information.