An open-source agent framework for building conversational AI agents on XMTP.
Hybrid makes it easy for developers to create intelligent agents that can understand natural language, process messages, and respond through XMTP's decentralized messaging protocol.
See hybrid.dev for more information.
Getting started with Hybrid is simple:
npm create hybrid my-agent
cd my-agent
This creates all the necessary files and configuration for your agent.
Visit OpenRouter, create an account and generate an API key
Add it to your .env
file:
OPENROUTER_API_KEY=your_openrouter_api_key_here
hybrid keys
or automatically add it to your .env
file:
hybrid keys --write
hybrid register
This generates secure wallet and encryption keys for your XMTP agent.
hybrid dev
Your agent will start listening for XMTP messages and you're ready to build!
Go to https://xmtp.chat/dm/ and send a message to your agent.
hybrid
comes with a set of behaviors that you can use to customize your agent's behavior. Behaviors are executed before or after the agent responds.
Here's a basic agent implementation:
import { createOpenRouter } from "@openrouter/ai-sdk-provider"
import { Agent } from "hybrid"
import { filterMessages, reactWith, threadedReply } from "hybrid/behaviors"
export const openrouter = createOpenRouter({
apiKey: process.env.OPENROUTER_API_KEY
})
const agent = new Agent({
name: "Basic Agent",
model: openrouter("x-ai/grok-4"),
instructions:
"You are a XMTP agent that responds to messages and reactions. Be conversational."
})
await agent.listen({
port: process.env.PORT || "8454"
})
By default, the agent will process all messages in the conversation. You can filter messages by using the filterMessages
behavior.
import { filterMessages } from "hybrid/behaviors"
await agent.listen({
port: process.env.PORT || "8454",
behaviors: [
filterMessages((filter) =>
filters.isReply() || filters.isDM() || filters.hasMention("@agent")
)
]
})
The filter function receives a filter
object with methods that return boolean values. Return true
to process the message, false
to filter it out.
Available filter methods:
filter.isText()
- Message is text contentfilter.isReply()
- Message is a replyfilter.isReaction()
- Message is a reactionfilter.isReaction(emoji, action?)
- Message is a reaction with specific emoji and/or action ("added" | "removed")filter.isDM()
- Message is a direct messagefilter.fromSelf()
- Message is from the agent itselffilter.hasMention(mention:string)
- Message contains a mentionfilter.hasContent()
- Message has contentfilter.isGroup()
- Message is in a group conversationfilter.isGroupAdmin()
- Message sender is group adminfilter.isGroupSuperAdmin()
- Message sender is group super adminfilter.isRemoteAttachment()
- Message has remote attachmentfilter.isTextReply()
- Message is a text reply
See XMTP Agent SDK filter docs for all filtering options: XMTP Agent SDK β Built-in filters.
A common behavior for agents is to react to the inbound message to let others know the agent is aware of the message and will reply.
import { reactWith } from "hybrid/behaviors"
await agent.listen({
port: process.env.PORT || "8454",
behaviors: [reactWith("π")]
})
By default, the agent will reply to the dm / group message in a top-level manner. You can change this to a threaded manner by using the threadedReply
behavior. This will have the agent reply to the original message and start a thread.
import { threadedReply } from "hybrid/behaviors"
await agent.listen({
port: process.env.PORT || "8454",
behaviors: [threadedReply()]
})
Hybrid includes a comprehensive standard library of tools for building crypto-enabled agents:
import { Agent } from "hybrid"
import { blockchainTools } from "hybrid/tools"
const agent = new Agent({
name: "my-agent",
model: myModel,
tools: blockchainTools,
// Expose runtime configuration used by blockchain tools
createRuntime: () => ({
rpcUrl: process.env.RPC_URL,
privateKey: process.env.PRIVATE_KEY as `0x${string}` | undefined,
defaultChain: "mainnet" as const
}),
instructions: "You can check balances, send transactions, and interact with the blockchain."
})
Available Tools:
getBalance
- Get native token balance for any addresssendTransaction
- Send native tokens to another addressgetTransaction
- Get transaction details by hashgetBlock
- Get blockchain block informationgetGasPrice
- Get current gas pricesestimateGas
- Estimate gas costs for transactions
Supported Chains: Ethereum, Polygon, Arbitrum, Optimism, Base, and Sepolia testnet
import { xmtpTools } from "hybrid/tools"
const agent = new Agent({
name: "messaging-agent",
model: myModel,
tools: xmtpTools,
instructions: "You can send messages, replies, and reactions in XMTP conversations."
})
Available Tools:
sendMessage
- Send messages to XMTP conversationssendReply
- Reply to specific messagessendReaction
- Send emoji reactionsgetMessage
- Retrieve message details by ID
import { Agent } from "hybrid"
import { blockchainTools, xmtpTools } from "hybrid/tools"
const agent = new Agent({
name: "combo-agent",
model: myModel,
tools: {
...blockchainTools,
...xmtpTools
}
})
The Hybrid CLI provides several commands to manage your agent development workflow:
# Initialize a new agent project
npm create hybrid@latest my-agent
# Use the CLI
hybrid keys
hybrid dev
hybrid build
hybrid clean
hybrid upgrade
hybrid register
hybrid revoke <inboxId>
hybrid revoke:all
# Or use project scripts generated by create-hybrid
pnpm dev
pnpm build
pnpm start
If you want to work with the source code or contribute to Hybrid:
- Node.js: Version 22 or higher
- pnpm: Package manager
- Git: Version control
git clone <repository-url>
cd hybrid
pnpm install
Create a .env.local
file in the root directory:
# AI Configuration
OPENROUTER_API_KEY="your_openai_api_key"
# XMTP Configuration
XMTP_WALLET_KEY="0x..." # Private key for XMTP agent
XMTP_DB_ENCRYPTION_KEY="..." # Database encryption key
XMTP_ENV="dev" # dev, production
# Start the agent
pnpm dev
This starts the agent and begins listening for XMTP messages on the configured port (default: 8454).
# Development
pnpm build # Build all packages
pnpm build:watch # Build all packages in watch mode
pnpm test # Run tests across all packages
pnpm typecheck # Type checking across all packages
# Code Quality
pnpm lint # Lint all packages
pnpm lint:fix # Fix linting issues
pnpm format # Format code (handled by Biome)
# Maintenance
pnpm clean # Clean build artifacts
pnpm nuke # Remove all node_modules (nuclear option)
pnpm bump # Bump version (patch by default)
pnpm bump:patch # Bump patch version
pnpm bump:minor # Bump minor version
pnpm bump:major # Bump major version
# Release
pnpm release # Build and publish all packages
Hybrid is designed as a framework for developers to build XMTP agents:
- Message Processing: Handle incoming XMTP messages with custom filters
- AI Integration: Connect any AI model for natural language understanding
- Agent Configuration: Simple setup with instructions and behavior
- XMTP Listening: Built-in server to listen for messages on any port
- core/: Main agent framework library (published as "hybrid")
- Agent runtime and plugin system
- Type-safe message handling
- Flexible filtering and processing
- Integration with AI providers and XMTP
- cli/: Command-line interface for agent management
- Project initialization and setup
- XMTP key generation and management
- Development server and build tools
- utils/: Common utilities and helpers (@hybrd/utils)
- Array, string, and object utilities
- Date and UUID helpers
- Markdown processing utilities
- xmtp/: XMTP client and messaging utilities (@hybrd/xmtp)
- Client initialization and management
- Message sending and receiving
- Address resolution (ENS, BaseName, XMTP)
- Content type handling and encryption
- Core: Node.js 22+, TypeScript, pnpm workspace
- Build: Turbo for monorepo orchestration and caching
- Messaging: XMTP Protocol for decentralized messaging
- AI: OpenRouter API and Vercel AI SDK for natural language processing
- Web3: Viem for Ethereum interactions, Coinbase AgentKit for DeFi
- Development: Biome for linting and formatting
- Testing: Vitest for fast unit and integration tests
Key environment variables for agent operation:
# Required
OPENROUTER_API_KEY="your_openai_api_key" # For AI integration
XMTP_WALLET_KEY="0x..." # XMTP wallet private key
XMTP_ENV="dev" # dev or production
# Optional
PORT="8454" # Port for the agent server
XMTP_DB_ENCRYPTION_KEY="..." # For secure data encryption
Deploy your Hybrid agent anywhere Node.js runs:
- Build the project:
pnpm build
- Deploy to any Node.js hosting provider:
- Vercel
- Railway
- Render
- Heroku
- DigitalOcean
- AWS Lambda
- Google Cloud Functions
Make sure these environment variables are configured in your deployment:
OPENROUTER_API_KEY
- Your AI API keyXMTP_WALLET_KEY
- XMTP wallet private keyXMTP_ENV
- dev or productionPORT
- Port for the agent server (optional)
pnpm test
- Start your agent:
pnpm dev
- Send XMTP messages to test your agent's responses
- Verify your custom filters and AI integration work as expected
- Agent: Main agent class for creating and configuring XMTP agents
- MessageListenerConfig: Configuration for message filtering and processing
- Reaction: Type for handling XMTP reactions
agent.listen()
: Start listening for XMTP messages with custom filtersfilter()
: Define which messages your agent should respond toprocessMessage()
: Handle incoming XMTP messagessendResponse()
: Send responses back to users
Hybrid supports all XMTP message types:
- Text Messages: Standard text content
- Reactions: π, β€οΈ, and custom reactions
- Replies: Threaded conversations
- Custom Content: Any XMTP-supported content type
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
ISC License - see LICENSE file for details
This project uses a monorepo structure with multiple packages and supporting directories:
hybrid/
βββ config/ # Shared configuration (biome, tsconfig)
βββ examples/
β βββ basic/ # Basic agent example implementation
βββ packages/
β βββ core/ # Main agent framework library (published as "hybrid")
β βββ cli/ # Command-line interface (bin: "hybrid")
β βββ create-hybrid/ # Project scaffolding tool (npm create hybrid)
β βββ ponder/ # Ponder plugin and event forwarder
β βββ types/ # Shared TypeScript types (@hybrd/types)
β βββ utils/ # Utilities (@hybrd/utils)
β βββ xmtp/ # XMTP client and resolvers (@hybrd/xmtp)
βββ scripts/ # Repo scripts (version bump, etc.)
βββ test/ # Test harness
- Documentation: Check the
/docs
directory - Issues: Create GitHub issues for bugs
- Discussions: Use GitHub discussions for questions
Built with β€οΈ using modern web3 technologies and natural language processing