Skip to main content

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:
  1. Episode Advancement - Increments conversation turns and updates temporal state
  2. TTL Processing - Expires components based on time-to-live settings
  3. ODI Coordination - Triggers depth shifting when message history changes
  4. 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:
  1. Sort components by creation_index (ascending)
  2. Calculate age for each component
  3. Expire components where age >= ttl
  4. Process rehydration for components with cadence
  5. Remove expired components without cadence
TTL processing happens before render lifecycle transitions. This ensures expired components don’t move to new stages.

Cadence and Rehydration

How Cadence Works

Components with both TTL and cadence expire and reappear on a schedule:

Rehydration Mechanics

When a component rehydrates:
  1. New component created with same content
  2. Same coordinates as original placement
  3. Fresh TTL countdown starts
  4. 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

During render(), the scheduler:
  1. Checks each component’s render lifecycle
  2. If TTL expired and more stages exist:
    • Remove component from current position
    • Advance to next stage
    • Insert at new position with new TTL
  3. 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:
Manual render calls should be rare. Let the agent system handle episode advancement automatically during normal operation.

Integration with Context Operations

Automatic Scheduling

Context operations automatically interact with the scheduler:

Component Creation Tracking

Every component tracks its creation episode:
This enables accurate age calculation during TTL processing.

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

Don’t manually increment current_episode. Use agent.call() or scheduler.render() to advance episodes properly.
Always use ContextExplorer to validate TTL component behavior before production use.
Processing order matters:
  1. Episode advances
  2. TTL expirations processed
  3. Render lifecycle transitions
  4. ODI depth shifting
Components expire before moving to new stages.
  • 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