A powerful XMTP agent that integrates with the IntentKit Agent API to provide AI-powered messaging capabilities. This agent receives messages via XMTP, forwards them to IntentKit for processing, and streams responses back to users with support for different content types including markdown formatting.
- π XMTP Integration: Connects to XMTP network for decentralized messaging
- π€ IntentKit AI: Leverages IntentKit Agent API for intelligent responses
- π‘ Streaming Support: Real-time streaming of AI responses
- π¬ Multiple Response Types: Handles agent, system, and skill responses differently
- π Markdown Support: Rich text formatting for agent responses
- πΎ Chat Management: Automatic chat ID creation and caching per user
- π Auto-Retry: Built-in retry mechanism for robust operation
- π‘οΈ Error Handling: Comprehensive error handling and user feedback
# Clone and install dependencies
yarn install
# Generate XMTP keys and create .env file
yarn gen:keysUpdate your .env file with your IntentKit API details:
# XMTP Configuration (auto-generated)
WALLET_KEY=0x...
ENCRYPTION_KEY=...
XMTP_ENV=dev
# IntentKit API Configuration (update these)
INTENTKIT_API_URL=https://your-intentkit-api.com
INTENTKIT_API_KEY=your-api-key-here# Development mode with auto-reload
yarn dev
# Production build and run
yarn build
yarn startgraph LR
A[XMTP User] -->|Send Message| B[XMTP Agent]
B -->|Forward Message| C[IntentKit API]
C -->|Stream Response| B
B -->|Format & Send| A
subgraph "Response Types"
D[Agent Response<br/>β Markdown]
E[System Error<br/>β Text + Emoji]
F[Skill Call<br/>β Formatted Info]
end
C -.-> D
C -.-> E
C -.-> F
- Receive: Agent listens for incoming XMTP messages
- Validate: Filters out self-messages and non-text content
- Forward: Sends message to IntentKit API with user's inbox ID
- Stream: Processes streaming responses from IntentKit
- Format: Handles different response types appropriately:
- Agent responses: Sent as markdown for rich formatting
- System messages: Sent as plain text with error emoji (π¨)
- Skill calls: Formatted to show which skills were executed
- Reply: Sends each response individually back to the user
- Automatic Chat Creation: Creates a unique chat ID for each XMTP user
- Memory Caching: Caches chat IDs in memory to avoid repeated API calls
- User Identification: Uses XMTP sender inbox ID as the user ID for IntentKit
| Variable | Description | Required | Example |
|---|---|---|---|
WALLET_KEY |
XMTP wallet private key | β | 0x1234... |
ENCRYPTION_KEY |
Local database encryption key | β | abcd1234... |
XMTP_ENV |
XMTP environment | β | dev, production |
INTENTKIT_API_URL |
IntentKit API endpoint | β | https://api.intentkit.com |
INTENTKIT_API_KEY |
IntentKit API authentication key | β | ik_1234... |
The agent expects the IntentKit API to support the following endpoints:
POST /chat
Content-Type: application/json
Authorization: Bearer ${INTENTKIT_API_KEY}
{
"user_id": "xmtp_inbox_id"
}
Response:
{
"chat_id": "uuid_string",
"success": true
}POST /chat/{chat_id}/message
Content-Type: application/json
Accept: text/event-stream
Authorization: Bearer ${INTENTKIT_API_KEY}
{
"message": "user message",
"user_id": "xmtp_inbox_id",
"stream": true
}
Response (SSE format):
data: {"data": {"message": "AI response", "author_type": "agent"}}
data: {"data": {"message": "Skill executed", "author_type": "skill", "skill_calls": [...]}}
data: [DONE]{
"message": "This is the AI agent's response with **markdown** support",
"author_type": "agent"
}{
"message": "An error occurred while processing your request",
"author_type": "system"
}{
"message": "Skills were executed",
"author_type": "skill",
"skill_calls": [
{
"name": "web_search",
"parameters": {"query": "blockchain news"},
"result": "Found 10 articles about blockchain"
}
]
}intentkit-xmtp-agent/
βββ src/
β βββ helpers/
β β βββ client.ts # XMTP client utilities
β β βββ intentkit.ts # IntentKit API client
β βββ index.ts # Main agent logic
βββ scripts/
β βββ generateKeys.ts # Key generation utility
βββ package.json
βββ tsconfig.json
βββ README.md
src/helpers/client.ts: XMTP client setup, signing, and environment validationsrc/helpers/intentkit.ts: IntentKit API client with streaming support and chat managementsrc/index.ts: Main agent logic that ties everything togetherscripts/generateKeys.ts: Secure key generation following XMTP best practices
| Script | Description |
|---|---|
yarn gen:keys |
Generate new XMTP wallet and encryption keys |
yarn dev |
Run in development mode with auto-reload |
yarn build |
Build TypeScript to JavaScript |
yarn start |
Run the built application |
yarn clean |
Clean build artifacts |
- π Private Keys: Never commit private keys to version control
- π‘οΈ API Keys: Keep IntentKit API keys secure and rotate regularly
- π Database Encryption: Local XMTP database is encrypted using the encryption key
- π HTTPS: Ensure IntentKit API endpoint uses HTTPS in production
- π Input Validation: Messages are validated before forwarding to IntentKit
Agent not receiving messages
- Check XMTP environment matches your test setup
- Verify wallet has been used to send/receive messages before
- Ensure conversations are synced properly
IntentKit API errors
- Verify API URL and key are correct
- Check API endpoint is accessible
- Review API response format matches expected structure
Streaming issues
- Ensure API supports Server-Sent Events (SSE)
- Check network connectivity and timeouts
- Verify response format includes proper
data:prefixes
Enable debug logging by setting environment variables:
DEBUG=1 yarn devThe agent provides detailed logging including:
- π Startup and configuration
- π¨ Message reception and processing
- π IntentKit API interactions
- π€ Response formatting and sending
- β Error details and recovery attempts
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Create an issue on GitHub
- Check existing documentation
- Review IntentKit API documentation