This is a basic XMTP XBT Agent that can be used to send and receive messages on the XMTP network. It uses the XMTP Agent SDK to create a basic agent that can be used to send and receive messages on the XMTP network.
It then hits the ai service to answer to dm and group messages.
- Creates an XMTP agent using
@xmtp/agent-sdk, with codecs for replies, reactions, group updates, and remote attachments configured. - Subscribes to incoming messages and filters out non-user content (no content, from self, reactions) using
filterhelpers. - Adds a temporary "thinking" reaction via middleware, extracts the text from the message (including reply content), and forwards it to your AI backend endpoint:
POST {BACKEND_URL}/api/agent/{AGENT_FID}/askwith the headerx-api-secret: {BACKEND_API_KEY}. - Replies back in the same DM or group with the backend's
answerwhen available. - Logs agent startup details and gracefully handles shutdown signals.
- Persists the XMTP local database to a file named
{XMTP_ENV}-{inboxIdPrefix}.db3. WhenRAILWAY_VOLUME_MOUNT_PATHis set (for example/data), the DB file is written there to allow persistence via a mounted volume.
- Node.js 20+
- pnpm
- Clone the repository
- Install the dependencies
- Run the agent
BACKEND_URL(required): Base URL of the AI backend (used bysrc/index.ts).BACKEND_API_KEY(required): Shared secret sent asx-api-secretto the backend.AGENT_FID(required): Agent FID used to build the/api/agent/{fid}/askURL.XMTP_MNEMONIC(required): 12/24-word mnemonic used to derive the XMTP signer.XMTP_ENV(optional):local|dev|production(defaults toproduction).XMTP_DB_ENCRYPTION_KEY(optional): Hex key to encrypt the local DB.RAILWAY_VOLUME_MOUNT_PATH(optional): Directory for the DB file (e.g./data).
Notes:
- The agent currently uses
XMTP_MNEMONICfor signing.