Skip to main content

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

Use pact_insert() to add components at specific coordinates:
Insert behavior:
  • Creates component at exact coordinates
  • Shifts existing components if needed
  • Respects Core Offset Layout Rule

Updating Components

Use pact_update() with different modes:
Replace overwrites at exact coordinates. Append finds the next available offset automatically.

Deleting Components

Use pact_delete() to remove components:
Deleting the core (offset 0) may cause the entire container to be removed if it becomes empty.

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.
Use cases:
  • 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.
Use cases:
  • 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.
Use cases:
  • 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.
Use cases:
  • Periodic check-ins
  • Recurring reminders
  • Scheduled context injection

TTL Lifecycle Management

How TTL Works

TTL (Time-To-Live) is managed by the MessageScheduler:
  1. Episode advancement - Each turn increments current_episode
  2. Age calculation - age = current_episode - component.created_at_episode
  3. Expiration check - If age >= ttl, component expires
  4. 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

  • 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
Don’t manually track position changes - ODI handles depth shifting automatically:
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