Console Chat HTTP Handlers
The Console Chat API provides the bridge between the React-based Web Console and the underlying Orchestration Engine. These handlers manage session lifecycles, message streaming, and state mutations like renaming or resetting.Key Handlers and Routes
console_chat_sessions_list_handler: Lists available sessions for the authenticated principal, supporting pagination viaafter_session_keycrates/palyra-daemon/src/transport/http/handlers/console/chat.rs#9-34.console_chat_session_resolve_handler: Resolves or creates a session based on a ULID or a human-readable session key crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#36-69.console_chat_message_stream_handler: The primary entry point for sending messages. It validates the session, processes attachments, and initiates aRunStreamcrates/palyra-daemon/src/transport/http/handlers/console/chat.rs#139-182.console_chat_session_reset_handler: Truncates the session history while preserving the session identity crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#107-137.
Data Flow: Message Submission
- Authorization:
authorize_console_sessionverifies the request crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#145. - Attachment Processing:
load_console_chat_message_attachmentshandles binary data crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#154-160. - Parameter Delta: Builds the
parameter_deltawhich includes explicit recall queries or context references crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#161-176. - Run Execution: Spawns a background task to manage the
RunStreamand returns an NDJSON stream to the client crates/palyra-daemon/src/transport/http/handlers/console/chat.rs#184-210.
Prompt Preparation Pipeline
Theprovider_input.rs module is responsible for transforming a user’s raw input into a structured prompt for the LLM. This process involves augmenting the input with historical context, RAG (Retrieval-Augmented Generation) results, and workspace documents.
Pipeline Stages
- Vision Processing:
build_provider_image_inputsextracts and validates image attachments based onMediaRuntimeConfiglimits crates/palyra-daemon/src/application/provider_input.rs#107-155. - Memory Augmentation:
build_memory_augmented_promptperforms a vector search against theJournalStoreto find relevant past interactions crates/palyra-daemon/src/application/provider_input.rs#158-200. - Context References: Resolves
[[tags]]or file paths into full text usingpreview_context_referencescrates/palyra-daemon/src/application/context_references.rs#72-129. - Session Compaction Injection: If a session has been compacted, the summary and key facts are injected as a system-level block via
render_compaction_prompt_blockcrates/palyra-daemon/src/application/provider_input.rs#14-17.
Context Reference Resolution
The system supports several types of inline references:- Files/Folders: Read from the authorized workspace roots crates/palyra-daemon/src/application/context_references.rs#188-193.
- Git: Resolves
difforstagedchanges crates/palyra-daemon/src/application/context_references.rs#194-199. - URLs: Fetches content using the internal
http_fetchtool crates/palyra-daemon/src/application/context_references.rs#200-203.
Pipeline Diagram
Title: Prompt Preparation Pipeline (Natural Language to Code Entity) Sources: crates/palyra-daemon/src/application/provider_input.rs#1-200, crates/palyra-daemon/src/application/context_references.rs#72-176Session Compaction
Session Compaction is the process of condensing a long chat transcript into a concise summary and a set of “Durable Facts.” This prevents context window overflow and persists important information into the Workspace.The Compaction Plan
ASessionCompactionPlan is generated by an LLM to determine:
- Summary: A high-level narrative of the session crates/palyra-daemon/src/application/session_compaction.rs#82.
- Candidates: Proposed changes to workspace documents (e.g., updating
MEMORY.md) crates/palyra-daemon/src/application/session_compaction.rs#159-169. - Checkpoint: A snapshot of the workspace state at the time of compaction crates/palyra-daemon/src/application/session_compaction.rs#184-189.
Strategy: session_window_v1
The system uses a window-based strategy crates/palyra-daemon/src/application/session_compaction.rs#31:
- Keep Recent: The most recent 6 text events are always preserved crates/palyra-daemon/src/application/session_compaction.rs#33.
- Confidence Threshold: Automated writes to the workspace require a confidence score > 0.82 crates/palyra-daemon/src/application/session_compaction.rs#38.
Compaction Execution Flow
Title: Session Compaction and Workspace Persistence Sources: crates/palyra-daemon/src/application/session_compaction.rs#31-189, crates/palyra-daemon/src/application/mod.rs#1-14Workspace and Durable Operating Surface
The Workspace represents the persistent filesystem-like view of an agent’s knowledge. It is composed of “Managed Blocks” within Markdown documents.Document Types
The system recognizes several core document kinds crates/palyra-daemon/src/domain/workspace.rs#98-106:README.md: High-level agent purpose and instructions.MEMORY.md: Long-term facts and user preferences.HEARTBEAT.md: Periodic status updates and active goals.
Managed Blocks
Documents use HTML comments to define regions that Palyra can safely edit:<!-- PALYRA:BEGIN ID -->: Start of a managed block crates/palyra-daemon/src/domain/workspace.rs#30.<!-- PALYRA:ITEM ID -->: Individual entry within a block crates/palyra-daemon/src/domain/workspace.rs#33.<!-- PALYRA:END ID -->: End of a managed block crates/palyra-daemon/src/domain/workspace.rs#32.
Risk and Safety
The workspace implementation includes guardrails to prevent prompt injection and accidental leakage:- High Risk Patterns: Patterns like “ignore previous instructions” trigger
WorkspaceRiskState::Quarantinedcrates/palyra-daemon/src/domain/workspace.rs#10-19. - Sensitive Segments: Paths containing
.ssh,.aws, orsecretsare blocked crates/palyra-daemon/src/domain/workspace.rs#8-9.
Workspace Structure Table
| Kind | Class | Prompt Binding | Purpose |
|---|---|---|---|
Readme | Curated | SystemCandidate | Core identity and instructions |
Memory | Curated | SystemCandidate | Durable facts from compaction |
Heartbeat | System | Never | Internal state tracking |
Daily | User | ManualOnly | User-created logs |
Branching and Checkpoints
Palyra supports versioning the “Operating Surface” through Checkpoints and Session Branching.- Checkpoints: Created during compaction or manually, a
OrchestratorCheckpointRecordstores the hashes of all workspace documents at a specific point in time crates/palyra-daemon/src/application/session_compaction.rs#184-189. - Branching: When a session is reset or branched, the agent can start from a previous checkpoint, allowing for “what-if” scenarios or recovery from poor compaction outcomes.
- Deep Linking: The Web Console uses
usePhase4DeepLinksto navigate directly to specific runs, compactions, or checkpoints apps/web/src/chat/usePhase4DeepLinks.ts#3-23.