Skip to main content
The Session Compaction system and Workspace management provide a durable operating surface for agents. This system ensures long-running sessions remain performant by condensing historical event logs into structured summaries and persistent workspace documents, while maintaining security through proactive prompt injection scanning.

Workspace Durable Operating Surface

The Workspace is a managed filesystem-like structure used to store persistent state across sessions. It primarily consists of Markdown files that serve as the “long-term memory” for an agent’s operational context.

Key Workspace Documents

Security and Risk Scanning

The workspace includes a WorkspaceRiskScan mechanism that evaluates content for potential threats crates/palyra-daemon/src/domain/workspace.rs#208-211. Sources: crates/palyra-daemon/src/domain/workspace.rs#1-242

Session Compaction Lifecycle

Session Compaction (also known as the “continuity planner”) is triggered when a session’s token count exceeds specific thresholds. It transforms a verbose event Tape into a concise OrchestratorCompactionArtifactRecord crates/palyra-daemon/src/application/session_compaction.rs#21-27.

Compaction Strategy: session_window_v1

The system employs a windowing strategy to maintain immediate context while summarizing the past:
  1. Retention: Keeps the most recent 6 text events exactly as they occurred crates/palyra-daemon/src/application/session_compaction.rs#33-33.
  2. Condensation: Summarizes older events into a structured JSON summary crates/palyra-daemon/src/application/session_compaction.rs#120-124.
  3. Candidate Generation: Identifies “candidates” for workspace updates—facts or status changes that should be moved from the ephemeral session to durable files crates/palyra-daemon/src/application/session_compaction.rs#159-169.

Implementation Data Flow

The following diagram maps the compaction process from the high-level logic to the specific code entities involved. Title: Session Compaction Data Flow Sources: crates/palyra-daemon/src/application/session_compaction.rs#1-195, crates/palyra-daemon/src/application/provider_input.rs#14-17

Managed Block Updates

When the compaction system identifies a fact that belongs in the workspace, it uses apply_workspace_managed_block to perform a surgical update crates/palyra-daemon/src/domain/workspace.rs#43-47.
EntityRole
WorkspaceManagedEntryA single unit of information (e.g., a fact or task) with a unique ID crates/palyra-daemon/src/domain/workspace.rs#36-40.
WorkspaceManagedBlockUpdateA request to update a specific block with a list of entries crates/palyra-daemon/src/domain/workspace.rs#43-47.
WorkspaceManagedBlockOutcomeThe result of an update, including a diff of lines added/removed crates/palyra-daemon/src/domain/workspace.rs#60-66.
Sources: crates/palyra-daemon/src/domain/workspace.rs#35-66

Context References and Recall

The Workspace and Session history are exposed to the model through the ContextReference system, which allows users or agents to explicitly “tag” resources using the @ symbol crates/palyra-common/src/context_references.rs#69-72.

Resolution Process

  1. Parsing: parse_context_references identifies @file, @folder, @url, and @memory tags in the input text crates/palyra-common/src/context_references.rs#5-12.
  2. Previewing: preview_context_references calculates token estimates and fetches content previews crates/palyra-daemon/src/application/context_references.rs#72-77.
  3. Injection: render_context_reference_prompt formats the resolved content into a <context_references> XML-style block for the LLM crates/palyra-daemon/src/application/context_references.rs#131-134.
Title: Context Reference Resolution Map Sources: crates/palyra-common/src/context_references.rs#1-113, crates/palyra-daemon/src/application/context_references.rs#1-176

Checkpoint and Restore

Checkpoints allow a session to be “frozen” and later restored or branched. A checkpoint captures the state of the workspace and the condensed session summary at a specific point in time. Sources: crates/palyra-daemon/src/application/session_compaction.rs#142-146, crates/palyra-daemon/src/application/session_compaction.rs#184-189