Skip to main content

PACT Architecture

PACT (Positioned Adaptive Context Tree) is the foundational architecture that powers Egregore’s context management system. Think of it as a DOM for AI context - allowing you to precisely position, manipulate, and automatically adapt memory components as conversations evolve.

The Problem PACT Solves

Traditional chat-based AI systems treat context as a flat append-only log:
This creates several problems:
  • No addressability: Can’t reference or modify specific parts of context
  • Inefficient: LLM re-processes entire history every turn
  • No structure: Flat lists don’t represent hierarchical relationships
  • Limited control: Can’t expire, move, or manage individual pieces
PACT solves this with a tree structure and coordinate system.

The Three Pillars

1. Positioned

Every component has precise coordinates in 3D space:
Coordinates enable infinite addressability - you can reference any component precisely, just like DOM elements with IDs or CSS selectors.

2. Adaptive

Components automatically adjust positions as conversation grows through ODI (Overlap Demotion Invariant):

3. Context Tree

Hierarchical organization mirrors DOM structure:

PACT Coordinate System

Understanding Coordinates

PACT uses tuple coordinates with three dimensions:

Depth: Conversation Timeline

  • -1: System level (static, never moves)
  • 0: Current active message
  • 1, 2, 3…: Historical messages (pushed back by ODI)

Position: Attachment Points

  • 0: Message core content (user/assistant text)
  • 1+: Components attached to the message
  • 1-: Alternative component attachment (negative positions)

Offset: Fine-Grained Placement

Relative positioning within a container:
  • 0: Core/canvas position (always exists)
  • 1, 2, 3…: Positive offsets
  • -1, -2, -3…: Negative offsets

ODI: Overlap Demotion Invariant

The Magic of Automatic Adaptation ODI is the system that automatically shifts components as conversations grow, maintaining their relative positions.

How ODI Works

When a new message is added:
  1. Current message (0,0,0) becomes historical (1,0,0)
  2. All permanent/sticky components increment depth by 1
  3. New message takes position (0,0,0)

ODI Rules

ODI triggers when message count changes between turns:
  • Length increase → increment depths
  • Length decrease → decrement depths
  • Length same → no ODI processing
  • Permanent components (ttl=None)
  • Sticky components (ttl=1, cadence=1)
  • Components at depths ≥ 0
Excluded from ODI:
  • System depth (-1) - always static
  • Temporary/cyclic components (they expire instead)
No! ODI only changes depth, never position or offset. This preserves relative positioning within messages.

ODI Example: Multi-Turn Conversation

PACT Selectors

CSS-like syntax for querying context components:

Learn More

Complete PACT selector syntax reference

Message vs Component Positioning

Message Structure (dN,0)

Message core content - permanent by default:
Characteristics:
  • No TTL by default (permanent)
  • Automatically managed by MessageScheduler
  • Participate in ODI depth shifting

Component Structure (dN,1+)

Components attached to messages - MAY have TTL:
Characteristics:
  • Most are permanent (participate in ODI)
  • Can have TTL for automatic expiration
  • Can use render lifecycle for dynamic positioning

Core Offset Layout Rule

Offset 0 is special - the core/canvas position that always exists:
Deleting core (offset 0) may trigger container reorganization. If it empties the container, the entire container may cease to exist.

PACT v0.1 Canonical Compliance

All Context components inherit from PACTNode with canonical fields:

Automatic Serialization

Best Practices

Use Descriptive Keys

Leverage Tags

3-Coordinate Selectors

Trust ODI

Common Patterns

Adding Persistent Metadata

System-Level Instructions

Temporary Reminders

What’s Next?

Context Management

Learn about context operations and component lifecycles

Message Scheduler

Understand episode management and ODI processing

PACT Selectors

Master selector syntax for querying components

Architecture Deep Dive

Full PACT specification and internals