building-agents
Core XMTP Agent SDK setup and patterns. Use when creating new agents, handling messages, setting up middleware, or configuring environment variables. Triggers on agent setup, XMTP configuration, message handling, or middleware implementation.
- License 许可
- MIT
- 最近更新
- 2026-08-23
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- building-agents
- license
- MIT
- metadata
- { "author": "xmtp", "version": "1.0.0" }
- description
- Core XMTP Agent SDK setup and patterns. Use when creating new agents, handling messages, setting up middleware, or configuring environment variables. Triggers on agent setup, XMTP configuration, message handling, or middleware implementation.
02 资源文件 6
- 参考文档rules/events-lifecycle.md866 B
- 参考文档rules/events-text.md913 B
- 参考文档rules/middleware-basics.md1.3 KB
- 参考文档rules/middleware-command-router.md1.2 KB
- 参考文档rules/setup-environment.md751 B
- 参考文档rules/setup-from-env.md1.1 KB
03 SKILL.md 正文
XMTP agent basics
Build event-driven, middleware-powered messaging agents on the XMTP network using the @xmtp/agent-sdk.
When to apply
Reference these guidelines when:
- Creating a new XMTP agent
- Setting up environment variables
- Handling text messages and events
- Implementing middleware
- Using filters and context helpers
Rule categories by priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Setup | CRITICAL | setup- |
| 2 | Events | HIGH | events- |
| 3 | Middleware | MEDIUM | middleware- |
| 4 | Filters | MEDIUM | filters- |
Quick reference
Setup (CRITICAL)
setup-environment- Configure environment variables for agentsetup-from-env- Create agent using Agent.createFromEnv()setup-manual- Manual agent creation with signer
Events (HIGH)
events-text- Handle text messagesevents-lifecycle- Handle start/stop eventsevents-conversation- Handle new DM and group conversationsevents-message-types- Handle different message types (reaction, reply, attachment)
Middleware (MEDIUM)
middleware-basics- Create and register middlewaremiddleware-error-handling- Handle errors in middleware chainmiddleware-command-router- Use CommandRouter for slash commands
Filters (MEDIUM)
filters-message-types- Filter by message typefilters-sender- Filter out self-messages
Installation
npm install @xmtp/agent-sdk
# or
yarn add @xmtp/agent-sdk
Quick start
import { Agent } from "@xmtp/agent-sdk";
import { getTestUrl } from "@xmtp/agent-sdk/debug";
// Create agent using environment variables
const agent = await Agent.createFromEnv();
// Handle text messages
agent.on("text", async (ctx) => {
await ctx.conversation.sendText("Hello from my XMTP Agent!");
});
// Log when ready
agent.on("start", () => {
console.log(`Agent online: ${getTestUrl(agent.client)}`);
});
await agent.start();
Environment variables
| Variable | Purpose | Example |
|---|---|---|
XMTP_WALLET_KEY |
Private key for wallet | 0x1234...abcd |
XMTP_DB_ENCRYPTION_KEY |
Database encryption key | 0xabcd...1234 |
XMTP_ENV |
Network environment | dev or production |
XMTP_DB_DIRECTORY |
Database directory | ./data |
How to use
Read individual rule files for detailed explanations:
rules/setup-environment.md
rules/events-text.md
rules/middleware-basics.md
04 同仓库更多 Skills
crowd-prompting
A marketplace where AI agents improve prompts, system instructions, tool descriptions, and other text-based content with domain expertise from real-world operations — and earn tokens for valuable contributions.
dilemm-ai
Compete in DilemmAI, the prisoner's dilemma AI arena at dilemm.ai. Use when an OpenClaw agent wants to create an account, design and submit strategy prompts for their bot, enter matchmaking, analyze historical matches and leaderboards, and iterate on bot strategy. Requires headless browser automation (no API available yet).
arxiv-paper-reviews
Interact with arXiv Crawler API to fetch papers, read reviews, and submit comments. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, or submitting paper reviews via API at http://150.158.152.82:8000.
arxiv-paper-reviews
Interact with arXiv Crawler API to fetch papers, read reviews, and submit comments. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, or submitting paper reviews via API at http://150.158.152.82:8000.
git-summary
Get a quick summary of the current Git repository including status, recent commits, branches, and contributors.
agent-constitution
Interact with AgentConstitution governance contracts on Base Sepolia. Check compliance, read rules, log actions, query governance state.