System Architecture
The elizaOS runtime follows a modular, plugin-based architecture that orchestrates all agent functionality. For lifecycle details, see Runtime and Lifecycle. For extension architecture, see Plugin Architecture.Core Components
The runtime orchestrates these essential components:- AgentRuntime: Central orchestrator managing agent lifecycle
- Plugin System: Extends functionality through modular components
- Memory System: Hierarchical storage for conversations and knowledge
- State Management: Aggregates context from multiple sources
- Service Layer: Background processes and integrations
AgentRuntime Class
TheAgentRuntime
class is the central engine that manages agent lifecycle, processes messages, and coordinates all system components.
Core Interface
Key Responsibilities
1. Action Processing
The runtime orchestrates action selection and execution:2. State Composition
Builds comprehensive context by aggregating data from providers:3. Plugin Management
Registers and initializes plugin components:Runtime Lifecycle
Initialization Sequence
- Runtime Creation: Instantiate with character and configuration
- Character Loading: Load agent personality and settings
- Plugin Loading: Register plugins in dependency order
- Service Startup: Initialize background services
- Ready State: Agent ready to process messages
Plugin Loading Order
Configuration
Runtime Configuration
The runtime accepts configuration through multiple sources:Environment Variables
Core runtime environment variables:NODE_ENV
- Runtime environment (development/production)LOG_LEVEL
- Logging verbosityDATABASE_URL
- Database connection stringAPI_PORT
- Server port for API endpointsAGENT_ID
- Unique agent identifier
Settings Management
Access configuration through the runtime:Database Abstraction
The runtime implementsIDatabaseAdapter
for data persistence:
Memory Operations
Message Processing Pipeline
The runtime processes messages through a defined pipeline:Processing Steps
- Message Receipt: Receive and validate incoming message
- Memory Storage: Persist message to database
- State Composition: Build context from providers
- Action Selection: Choose appropriate actions
- Action Execution: Run selected action handlers
- Evaluation: Post-process results
- Response Generation: Create and send response
Error Handling
The runtime implements comprehensive error handling:Performance Considerations
State Caching
The runtime caches composed state for performance:Service Pooling
Services are singleton instances shared across the runtime:Best Practices
Runtime Initialization
- Initialize plugins in dependency order
- Start services after all plugins are loaded
- Verify character configuration before starting
- Set up error handlers before processing
Resource Management
- Clean up services on shutdown
- Clear state cache periodically
- Monitor memory usage
- Implement connection pooling
Error Recovery
- Implement retry logic for transient failures
- Log errors with context
- Gracefully degrade functionality
- Maintain audit trail
Integration Points
The runtime provides multiple integration points:- Plugins: Extend functionality through the plugin system
- Events: React to runtime events
- Services: Add background processes
- Models: Integrate AI providers
- Database: Custom database adapters
- API: HTTP endpoints through routes