Important: This guide provides comprehensive documentation for the composeState method and Providers in v1.x, including comparisons with v0.
Table of Contents
State Management with composeState
ThecomposeState method is the central mechanism for building the context state that powers agent responses. In v1, it has been enhanced with powerful filtering capabilities.
Basic Usage
- Agent information (bio, lore, personality)
- Conversation history
- Room and participant details
- Available actions and evaluators
- Knowledge and RAG data
- Provider-generated context
State Filtering
The v1composeState method introduces filtering capabilities for performance optimization:
Filtering Examples
Available State Keys
Here are the primary state keys you can filter:Core Agent Information
agentId- Agent’s UUIDagentName- Agent’s display namebio- Agent biography (string or selected from array)lore- Random selection of lore bitsadjective- Random adjective from charactertopic/topics- Agent’s interests
Conversation Context
recentMessages- Formatted recent messagesrecentMessagesData- Raw message Memory objectsrecentPosts- Formatted posts in threadattachments- Formatted attachment information
Interaction History
recentMessageInteractions- Past interactions as messagesrecentPostInteractions- Past interactions as postsrecentInteractionsData- Raw interaction Memory[]
Character Examples
characterPostExamples- Example posts from charactercharacterMessageExamples- Example conversations
Directions & Style
messageDirections- Message style guidelinespostDirections- Post style guidelines
Room & Participants
roomId- Current room UUIDactors- Formatted actor informationactorsData- Raw Actor[] arraysenderName- Name of message sender
Goals & Actions
goals- Formatted goals stringgoalsData- Raw Goal[] arrayactionNames- Available action namesactions- Formatted action descriptionsactionExamples- Action usage examples
Evaluators
evaluators- Formatted evaluator informationevaluatorNames- List of evaluator namesevaluatorExamples- Evaluator examplesevaluatorsData- Raw Evaluator[] array
Knowledge
knowledge- Formatted knowledge textknowledgeData- Knowledge itemsragKnowledgeData- RAG knowledge items
Providers
providers- Additional context from providers
Performance Optimization
Use filtering to optimize performance by only computing needed state:Providers in v1
Providers supply dynamic contextual information to the agent, acting as the agent’s “senses” for perceiving external data.Provider Interface
Creating Providers
Simple Text Provider
Complex Data Provider
Conditional Provider
Provider Options
dynamic Property
Set to true for providers that return different data based on context:
position Property
Controls provider priority (higher = higher priority):
private Property
Hide from public provider lists:
Provider Best Practices
- Always Return ProviderResult
- Use Appropriate Return Fields
- Handle Errors Gracefully
- Optimize Performance
v0 vs v1 Comparison
composeState Changes
Method Signature
Key Differences:
- Filtering: v1 allows selective state composition
- Performance: Can request only needed state keys
- Caching: Explicit cache control with
skipCache - Update Pattern: Use same method for updates with specific keys
Migration Example:
Provider Changes
Interface Changes
Return Type Changes
Key Differences:
- Required Name: Every provider must have unique
name - Structured Returns: Must return
ProviderResultobject - Rich Metadata: Can specify behavior with options
- State Parameter: No longer optional in
getmethod - Better Organization: Clear separation of text, values, and data
Migration Checklist
- Add
nameproperty to all providers - Update return statements to use
ProviderResultformat - Remove optional
?from state parameter in get method - Consider adding
descriptionfor documentation - Use
dynamic: truefor context-dependent providers - Replace
updateRecentMessageStatewith filteredcomposeState - Optimize performance by filtering state keys
- Add error handling with graceful fallbacks
- Consider caching strategies for expensive operations

