composeState method in ElizaOS and how it interacts with different types of providers to build contextual state for agent decision-making.
Introduction
ThecomposeState method is a core function in ElizaOS that aggregates data from multiple providers to create a comprehensive state object. This state represents the agent’s understanding of the current context and is used for decision-making, action selection, and response generation.
What is State?
State in ElizaOS is a structured object containing:- values: Key-value pairs for direct access (used in templates)
- data: Structured data from providers
- text: Concatenated textual context from all providers
Quick Reference
Provider Summary Table
| Provider Name | Dynamic | Position | Default Included | Purpose |
|---|---|---|---|---|
| ACTIONS | No | -1 | Yes | Lists available actions |
| ACTION_STATE | No | 150 | Yes | Action execution state |
| ANXIETY | No | Default | Yes | Response style guidelines |
| ATTACHMENTS | Yes | Default | No | File/media attachments |
| CAPABILITIES | No | Default | Yes | Service capabilities |
| CHARACTER | No | Default | Yes | Agent personality |
| CHOICE | No | Default | Yes | Pending user choices |
| ENTITIES | Yes | Default | No | Conversation participants |
| EVALUATORS | No | Default | No (private) | Post-processing options |
| FACTS | Yes | Default | No | Stored knowledge |
| PROVIDERS | No | Default | Yes | Available providers list |
| RECENT_MESSAGES | No | 100 | Yes | Conversation history |
| RELATIONSHIPS | Yes | Default | No | Social connections |
| ROLES | No | Default | Yes | Server roles (groups only) |
| SETTINGS | No | Default | Yes | Configuration state |
| TIME | No | Default | Yes | Current UTC time |
| WORLD | Yes | Default | No | Server/world context |
Common Usage Patterns
Understanding composeState
Method Signature
Parameters
- message: The current message/memory object being processed
- includeList: Array of provider names to include (optional)
- onlyInclude: If true, ONLY include providers from includeList
- skipCache: If true, bypass cache and fetch fresh data
How It Works
- Provider Selection: Determines which providers to run based on filters
- Parallel Execution: Runs all selected providers concurrently
- Result Aggregation: Combines results from all providers
- Caching: Stores the composed state for reuse
Provider Types
ElizaOS includes various built-in providers, each serving a specific purpose:Core Providers
1. Character Provider
Provides character information, personality, and behavior guidelines.2. Recent Messages Provider
Provides conversation history and context.3. Actions Provider
Lists available actions the agent can take.Dynamic Providers
Dynamic providers are only executed when explicitly requested:- Facts Provider: Retrieves relevant facts from memory
- Relationships Provider: Gets relationship information
- Settings Provider: Fetches configuration settings
- Roles Provider: Server role hierarchy
Private Providers
Private providers are internal and not included in default state composition:- Evaluators Provider: Post-interaction processing options
Detailed Provider Reference
Built-in Providers
Actions Provider (ACTIONS)
- Purpose: Lists all available actions the agent can execute
- Position: -1 (runs early)
- Dynamic: No (included by default)
- Data Provided:
actionNames: Comma-separated list of action namesactionsWithDescriptions: Formatted action detailsactionExamples: Example usage for each actionactionsData: Raw action objects
Action State Provider (ACTION_STATE)
- Purpose: Shares execution state between chained actions
- Position: 150
- Dynamic: No (included by default)
- Data Provided:
actionResults: Previous action execution resultsactionPlan: Multi-step action execution planworkingMemory: Temporary data shared between actionsrecentActionMemories: Historical action executions
Anxiety Provider (ANXIETY)
- Purpose: Provides behavioral guidelines based on channel type
- Position: Default
- Dynamic: No (included by default)
- Behavior: Adjusts response style for DMs, groups, and voice channels
Attachments Provider (ATTACHMENTS)
- Purpose: Lists files and media in the conversation
- Position: Default
- Dynamic: Yes (must be explicitly included)
- Data Provided:
- File names, URLs, descriptions
- Text content from attachments
- Media metadata
Capabilities Provider (CAPABILITIES)
- Purpose: Lists agent’s available services and capabilities
- Position: Default
- Dynamic: No (included by default)
- Data Provided: Service descriptions and available functions
Character Provider (CHARACTER)
- Purpose: Core personality and behavior definition
- Position: Default
- Dynamic: No (included by default)
- Data Provided:
agentName: Character namebio: Character backgroundtopics: Current interestsadjective: Current mood/statedirections: Style guidelinesexamples: Example conversations/posts
Choice Provider (CHOICE)
- Purpose: Lists pending decisions awaiting user input
- Position: Default
- Dynamic: No (included by default)
- Use Case: Interactive workflows requiring user selection
Entities Provider (ENTITIES)
- Purpose: Information about conversation participants
- Position: Default
- Dynamic: Yes (must be explicitly included)
- Data Provided:
- User names and aliases
- Entity metadata
- Sender identification
Facts Provider (FACTS)
- Purpose: Retrieves relevant stored facts
- Position: Default
- Dynamic: Yes (must be explicitly included)
- Behavior: Uses embedding search to find contextually relevant facts
Providers Provider (PROVIDERS)
- Purpose: Meta-provider listing all available providers
- Position: Default
- Dynamic: No (included by default)
- Use Case: Dynamic provider discovery
Recent Messages Provider (RECENT_MESSAGES)
- Purpose: Conversation history and context
- Position: 100 (runs later to access other data)
- Dynamic: No (included by default)
- Data Provided:
- Recent dialogue messages
- Action execution history
- Formatted conversation context
Relationships Provider (RELATIONSHIPS)
- Purpose: Social graph and interaction history
- Position: Default
- Dynamic: Yes (must be explicitly included)
- Data Provided:
- Known entities and their relationships
- Interaction frequency
- Relationship metadata
Roles Provider (ROLES)
- Purpose: Server/group role hierarchy
- Position: Default
- Dynamic: No (included by default)
- Restrictions: Only available in group channels
Settings Provider (SETTINGS)
- Purpose: Configuration and onboarding state
- Position: Default
- Dynamic: No (included by default)
- Behavior: Different output for DMs (onboarding) vs groups
Time Provider (TIME)
- Purpose: Current time and timezone information
- Position: Default
- Dynamic: No (included by default)
- Data Provided: Formatted timestamps and timezone data
World Provider (WORLD)
- Purpose: Virtual world/server context
- Position: Default
- Dynamic: No (included by default)
- Data Provided: World metadata and configuration
Cache Management
How Caching Works
ThecomposeState method uses an in-memory cache (stateCache) to store composed states:
Getting Cached Data
Clearing Cache
Usage Scenarios
Scenario 1: Default State Composition
Most common usage - compose state with all non-private, non-dynamic providers:Scenario 2: Including Dynamic Providers
Include specific dynamic providers for additional context:Scenario 3: Selective Provider Inclusion
Only include specific providers for focused processing:Scenario 4: Force Fresh Data
Skip cache for real-time data requirements:Examples
Example 1: Action Processing with State
Example 2: Settings-Based Configuration
Example 3: Context-Aware Response Generation
Example 4: Custom Provider Integration
Example 5: Performance Monitoring
Advanced Examples
Multi-Step Action Coordination
Provider Dependency Management
Dynamic Provider Loading
State Transformation Pipeline
Troubleshooting
Common Issues and Solutions
1. Stale Cache Data
Problem: State contains outdated information2. Provider Timeout Issues
Problem: Slow providers blocking state composition3. Memory Leaks from Cache
Problem: Cache grows indefinitely4. Circular Provider Dependencies
Problem: Providers depending on each otherDebugging State Composition
Best Practices
1. Provider Selection
- Use default providers for general conversation
- Include dynamic providers only when needed
- Use
onlyIncludefor performance-critical paths
2. Cache Management
3. Error Handling
4. Memory Optimization
5. Custom Provider Guidelines
When creating custom providers:Summary
ThecomposeState method is central to ElizaOS’s context management system. It provides a flexible way to aggregate data from multiple sources, manage caching for performance, and create rich contextual state for agent decision-making. By understanding how to effectively use providers and manage state composition, you can build more intelligent and context-aware agents.
Key takeaways:
- Use default composition for most scenarios
- Include dynamic providers when specific data is needed
- Leverage caching for performance
- Clear cache when data freshness is critical
- Monitor provider performance in production
- Handle errors gracefully

