Message Scheduler
The MessageScheduler is Egregore’s core rendering and episode management system. It coordinates context updates, processes component lifecycles, and manages the temporal flow of conversation turns.Core Responsibilities
The MessageScheduler handles four critical operations:- Episode Advancement - Increments conversation turns and updates temporal state
- TTL Processing - Expires components based on time-to-live settings
- ODI Coordination - Triggers depth shifting when message history changes
- Render Lifecycle - Manages dynamic component positioning through stages
Think of MessageScheduler as the “game loop” for your agent’s context - it advances time, processes expirations, and keeps the context tree synchronized.
Episode Management
What is an Episode?
An episode represents a single turn in the conversation. Each time the agent processes input or generates output, the episode number increments.Episode Advancement Flow
When a new message is processed:Episode advancement happens automatically during agent calls. You rarely need to manually trigger it.
TTL Processing
Expiration Algorithm
The MessageScheduler calculates component age and expires components based on TTL:Example: TTL Lifecycle
TTL Processing Order
Components are processed in creation order to ensure predictable behavior:- Sort components by
creation_index(ascending) - Calculate age for each component
- Expire components where
age >= ttl - Process rehydration for components with cadence
- Remove expired components without cadence
Cadence and Rehydration
How Cadence Works
Components with both TTL and cadence expire and reappear on a schedule:Rehydration Mechanics
When a component rehydrates:- New component created with same content
- Same coordinates as original placement
- Fresh TTL countdown starts
- Original component permanently removed
Rehydration is not component resurrection - it’s creating a new component with the same properties at the same location.
Render Lifecycle Management
Stage Transitions
The MessageScheduler processes render lifecycle stage transitions during each episode:Transition Processing
Duringrender(), the scheduler:
- Checks each component’s render lifecycle
- If TTL expired and more stages exist:
- Remove component from current position
- Advance to next stage
- Insert at new position with new TTL
- If TTL expired and no more stages:
- Remove component permanently
Render lifecycle transitions happen after TTL processing but before ODI shifting.
ODI Coordination
When ODI Triggers
The MessageScheduler triggers ODI (Overlap Demotion Invariant) when message history changes:ODI Processing Flow
Learn More
Deep dive into ODI mechanics and spatial conflict resolution
MessageScheduler API
Manual Episode Advancement
Most of the time, episode advancement is automatic. But for testing or advanced use cases:Render Modes
The scheduler supports different render modes:Integration with Context Operations
Automatic Scheduling
Context operations automatically interact with the scheduler:Component Creation Tracking
Every component tracks its creation episode:Debugging with ContextExplorer
Simulating Episode Advancement
Use ContextExplorer to test TTL behavior:Learn More
Complete guide to debugging with ContextExplorer
Monitoring TTL Lifecycle
Best Practices
Let the scheduler handle episodes
Let the scheduler handle episodes
Don’t manually increment
current_episode. Use agent.call() or scheduler.render() to advance episodes properly.Test TTL behavior with ContextExplorer
Test TTL behavior with ContextExplorer
Always use ContextExplorer to validate TTL component behavior before production use.
Understand render order
Understand render order
Processing order matters:
- Episode advances
- TTL expirations processed
- Render lifecycle transitions
- ODI depth shifting
Use appropriate TTL values
Use appropriate TTL values
- Short TTL (1-3): Temporary alerts, immediate reminders
- Medium TTL (5-10): Task tracking, session-level context
- Long TTL (20+): Periodic check-ins, recurring reminders
- No TTL: Permanent metadata, user preferences
Common Patterns
Session-Based Components
Periodic Reminders
Progressive Degradation
What’s Next?
Context History
Learn about snapshots and historical context access
TTL Lifecycle
Deep dive into TTL processing internals
ODI System
Understand depth shifting mechanics
Render Lifecycle
Advanced component positioning patterns

