Context Management
Context management in Egregore provides DOM-like manipulation of agent memory with powerful lifecycle controls. This page covers the fundamental operations for inserting, updating, deleting, and querying context components.Core Operations
Inserting Components
Usepact_insert() to add components at specific coordinates:
- Creates component at exact coordinates
- Shifts existing components if needed
- Respects Core Offset Layout Rule
Updating Components
Usepact_update() with different modes:
Replace overwrites at exact coordinates. Append finds the next available offset automatically.
Deleting Components
Usepact_delete() to remove components:
Querying Components
Multiple ways to access components:Component Lifecycle Types
Egregore provides four lifecycle types based on TTL and cadence parameters:1. Permanent (ttl=None)
Never expires - most common for message content and persistent metadata.
- User preferences that shouldn’t expire
- Important metadata that needs to persist
- Historical conversation context
2. Temporary (ttl=N, no cadence)
Expires after N turns, gone forever.
- Temporary reminders
- Short-term task tracking
- Contextual hints that expire
3. Sticky (ttl=1, cadence=1)
Expires and reappears each turn at the same relative coordinates. Follows parent through ODI.
- Current task/status indicators
- Persistent UI-like elements
- Context that needs to stay visible but refresh each turn
4. Cyclic (ttl=N, cadence=M)
Expires after N turns, reappears every M turns.
- Periodic check-ins
- Recurring reminders
- Scheduled context injection
TTL Lifecycle Management
How TTL Works
TTL (Time-To-Live) is managed by the MessageScheduler:- Episode advancement - Each turn increments
current_episode - Age calculation -
age = current_episode - component.created_at_episode - Expiration check - If
age >= ttl, component expires - Removal or rehydration - Component removed or rehydrated based on cadence
Cadence and Rehydration
When a component has both TTL and cadence:Rehydration creates a new component with the same content at the same coordinates. The original component is permanently removed.
Message Container Pattern
Egregore separates message content from context components:Message Structure
Accessing Messages vs Components
Render Lifecycle System
Advanced pattern for dynamic component positioning through stages.Basic Render Lifecycle
Cycling Lifecycles
Learn More
Complete render lifecycle documentation with advanced patterns
Context API Methods
Core Methods
Snapshot Management
Best Practices
Use appropriate lifecycle types
Use appropriate lifecycle types
- Permanent for most content (user info, preferences)
- Temporary for short-term reminders or hints
- Sticky for persistent status indicators
- Cyclic for periodic check-ins or scheduled tasks
Trust ODI for depth management
Trust ODI for depth management
Don’t manually track position changes - ODI handles depth shifting automatically:
Use MessageContainer pattern
Use MessageContainer pattern
Keep message content at position 0, components at position 1+:
Common Patterns
User Preferences Storage
Temporary Task Tracking
Persistent Status Indicator
Scheduled Reminders
Debugging Context
Use ContextExplorer for debugging:Learn More
Complete guide to debugging context with ContextExplorer
What’s Next?
Message Scheduler
Understand episode management and TTL processing
Context History
Learn about snapshots and historical access
Context API Reference
Complete API documentation for context operations
Render Lifecycle
Advanced component positioning patterns

