.cursorrules

Copy and paste this into your Rules section, in Settings in Cursor

User Rules (Global):

You are a world-class expert in TypeScript, Node.js, Next.js App Router, React, Shadcn UI, Radix UI and Tailwind.

Key Principles

  • Write concise, technical TypeScript code with accurate examples.

  • Use functional and declarative programming patterns; avoid classes.

  • Prefer iteration and modularization over code duplication.

  • Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).

  • Structure files: exported component, subcomponents, helpers, static content, types.

Naming Conventions

  • Use lowercase with dashes for directories (e.g., components/auth-wizard).

  • Favor named exports for components.

TypeScript Usage

  • Use TypeScript for all code; prefer interfaces over types.

  • Avoid enums; use maps instead.

  • Use functional components with TypeScript interfaces.

Syntax and Formatting

  • Use the "function" keyword for pure functions.

  • Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.

  • Use declarative JSX.

UI and Styling

  • Use Shadcn UI, Radix, and Tailwind for components and styling.

  • Implement responsive design with Tailwind CSS; use a mobile-first approach.

Performance Optimization

  • Minimize 'use client', 'useEffect', and 'setState'; favor React Server Components (RSC).

  • Wrap client components in Suspense with fallback.

  • Use dynamic loading for non-critical components.

  • Optimize images: use WebP format, include size data, implement lazy loading.

Key Conventions

  • Use 'nuqs' for URL search parameter state management.

  • Optimize Web Vitals (LCP, CLS, FID).

  • Limit 'use client':

  • Favor server components and Next.js SSR.

  • Use only for Web API access in small components.

  • Avoid for data fetching or state management.

Follow Next.js docs for Data Fetching, Rendering, and Routing.

Project Specific Rules

Overview

The AgentRuntime class is the primary implementation of the IAgentRuntime interface, which manages the agent's core functions, including:

Component
Description
API Reference
Related Files

Services

Supports multiple communication platforms and specialized functionalities for seamless interaction.

State

Maintains context for coherent cross-platform interactions, updates dynamically. Also tracks goals, knowledge, and recent interactions

Plugins

Dynamic extensions of agent functionalities using custom actions, evaluators, providers, and adapters

Services

Connects with external services for IMAGE_DESCRIPTION, TRANSCRIPTION, TEXT_GENERATION, SPEECH_GENERATION, VIDEO, PDF, BROWSER, WEB_SEARCH, EMAIL_AUTOMATION, and more

Memory Systems

Creates, retrieves, and embeds memories and manages conversation history.

Database Adapters

Persistent storage and retrieval for memories and knowledge

Cache Management

Provides flexible storage and retrieval via various caching methods.

Advanced: IAgentRuntime Interface


Key Methods

  • initialize(): Sets up the agent's runtime environment, including services, plugins, and knowledge processing.

  • processActions(): Executes actions based on message content and state.

  • evaluate(): Assesses messages and state using registered evaluators.

  • composeState(): Constructs the agent's state object for response generation.

  • registerService(): Adds a service to the runtime.

  • getService(): Retrieves a registered service by type.

  • useModel(): Utilizes AI models with typesafe parameters and results.

  • ensureRoomExists() / ensureConnection(): Ensures the existence of communication channels and connections.

Service System

Services provide specialized functionality with standardized interfaces that can be accessed cross-platform:

// Speech Generation
const speechService = runtime.getService<ISpeechService>('speech_generation');
const audioStream = await speechService.process(text);

// PDF Processing
const pdfService = runtime.getService<IPdfService>('pdf');
const textContent = await pdfService.convertPdfToText(pdfBuffer);

// Discord Integration
const discordService = runtime.getService<IDiscordService>('discord');
await discordService.sendMessage(channelId, content);

State Management

The runtime maintains comprehensive state through the State interface:

interface State {
  // Core state data
  values: {
    [key: string]: any;
  };
  data: {
    [key: string]: any;
  };
  text: string;
}

// State composition example
async function manageState() {
  // Initial state composition with all regular providers
  const state = await runtime.composeState(message);

  // State with specific providers only
  const filteredState = await runtime.composeState(message, ['timeProvider', 'recentMessages']);

  // Include private or dynamic providers
  const enhancedState = await runtime.composeState(message, null, [
    'weatherProvider',
    'portfolioProvider',
  ]);
}

Plugin System

Plugins extend agent functionality through a modular interface. The runtime supports various types of plugins including services, adapters, actions, and more:

interface Plugin {
  name: string;
  description: string;
  init?: (config: Record<string, string>, runtime: IAgentRuntime) => Promise<void>;

  // Components
  services?: (typeof Service)[]; // Communication platforms and external integrations
  actions?: Action[]; // Custom behaviors
  providers?: Provider[]; // Data providers
  evaluators?: Evaluator[]; // Response assessment
  adapters?: Adapter[]; // Database/cache adapters
  routes?: Route[]; // API endpoints
  tests?: TestSuite[]; // Testing utilities
}

Plugins can be configured through characterfile settings:

{
  "name": "MyAgent",
  "plugins": ["@elizaos/plugin-solana", "@elizaos/plugin-twitter"],
  "settings": {
    "twitter": {
      "shouldRespondToMentions": true
    },
    "solana": {
      "enableAutoTrading": false
    }
  }
}

For detailed information about plugin development and usage, see the ElizaOS Registry.


Running Multiple Agents

To run multiple agents:

bun start --characters="characters/agent1.json,characters/agent2.json"

Or use environment variables:

REMOTE_CHARACTER_URLS=https://example.com/characters.json

Last updated