Warning
Please note that the project is currently in an experimental phase, and it is subject to significant changes as it progresses.
An intelligent Lil Nouns DAO agent on the Farcaster social network. The agent listens for direct messages, uses AI to understand user intent, and can fetch real-time information about Lil Nouns governance, proposals, auctions, and more.
- Automated Response System: Responds to direct messages on Farcaster
- AI-Powered Understanding: Uses Cloudflare AI to understand user queries and generate contextual responses
- Real-Time Data Access: Fetches live data about Lil Nouns proposals, auctions, and governance
- Context-Aware Responses: Uses RAG for enhanced context generation
- Scheduled Processing: Runs on configurable intervals to process unread conversations
-
Clone the repository:
git clone https://github.com/lilnouns/lilnouns-agent.git cd lilnouns-agent -
Install dependencies:
pnpm install
-
Set up environment variables: Create a
.dev.varsfile in the root directory with the required environment variables (see the Environment Variables section). -
Generate TypeScript types:
pnpm cf-typegen
The following environment variables are required for the agent to function correctly:
NODE_ENV: The environment (development,staging, orproduction)FARCASTER_AUTH_TOKEN: Authentication token for the Farcaster APILILNOUNS_SUBGRAPH_URL: The URL for the Lil Nouns GraphQL subgraphETHEREUM_RPC_URL: The URL for an Ethereum RPC endpointENABLE_FARCASTER_STREAM: Set to 'true' to enable or 'false' to disable the Farcaster WebSocket Durable Object (default: 'true')
The agent uses the following Cloudflare infrastructure:
- KV Namespace: Used for caching data (
AGENT_CACHE) - Durable Objects: Used for managing WebSocket connections to Farcaster stream (
FARCASTER_STREAM) - Cloudflare AI: Used for AI processing with the binding
AI
pnpm dev: Starts the development server with local testingpnpm start: Starts the development serverpnpm build: Builds the worker for productionpnpm deploy: Deploys the worker to Cloudflarepnpm test: Runs the test suitepnpm test:run: Runs tests once without watch modepnpm format: Formats the code using Biomepnpm lint: Lints the code using Biomepnpm check: Runs both formatting and linting checkspnpm cf-typegen: Generates TypeScript types for Cloudflare Workers
- Scheduled Execution: The agent runs on a schedule defined in
wrangler.toml(hourly by default) - WebSocket Connection: Maintains persistent connections to Farcaster via Durable Objects
- Fetch Unread Messages: It fetches unread mentions in Farcaster chats and direct messages
- Process Conversations: For each conversation, it processes the message thread and determines context
- AI-Powered Responses: It uses Cloudflare's AI to understand the user's message and generate appropriate responses
- Tool Integration: If the user's message requires real-time data, the AI can use functions defined in
src/lib/tools.tsto fetch information about proposals, auctions, token supply, etc. - Context Generation: Uses RAG to generate relevant context based on the user's query
- Send Response: The agent sends the generated response back to the Farcaster conversation
- Use TypeScript with strict type checking
- Follow the existing JSDoc comment patterns for all exported functions
- Use structured logging with appropriate log levels (debug, info, error)
- Organize imports consistently
- Use functional programming patterns with Remeda where appropriate
- Write unit tests for all new functions
- Use Vitest for testing with Cloudflare Workers testing utilities
- Test both success and error scenarios
- Add JSDoc comments to all exported functions
- Include parameter types and descriptions
- Document return types and any thrown errors
- Keep inline comments concise but informative
- Fork the repository
- Create a feature branch
- Make your changes following the development guidelines
- Add tests for new functionality
- Run
pnpm checkto ensure code quality - Submit a pull request
This project is licensed under the Apache License, Version 2.0. See LICENSE for details.