Conversations
Context
Manage system prompt injection, active page metadata, conversation turn compression, and sliding context windows.
Overview
Effective AI assistants require relevant context without exceeding token budgets or diluting model attention. Asiyst uses a multi-layered Context Stack that dynamically balances system instructions, user metadata, live DOM context, and retrieved knowledge.
The Context Stack
Every LLM inference turn receives a curated prompt consisting of:
- System Persona: The global personality, constraints, and instructions configured in your assistant settings.
- Current Page Context: The active URL path, page title, and query parameters where the visitor is located.
- User Profile & Traits: Identified user traits (
planTier,role,company).
- Knowledge Retrieval Chunks: The top 3–5 document excerpts retrieved for the specific user query.
- Conversation History: The recent dialogue turns between user and assistant.
Sliding Window & Turn Compression
To keep latency low and avoid token limits during long conversations:
- The last 6 message turns are preserved with full verbatim text.
- Older conversation turns (turns 7+) are automatically compressed into an executive summary by a lightweight background model.
- This ensures the assistant remembers agreements made 20 messages ago without wasting context window tokens.
Dynamic Page Context Injection
You can inject custom page-level variables into the assistant's active memory:
import { Asiyst } from "@asiyst/sdk";
// Inject active product context on an e-commerce page
Asiyst.setContext({
productId: "prod_88291",
productName: "Enterprise Cloud Server",
inventoryStatus: "In Stock",
currentPrice: "$499/mo",
});
Token Budget Allocation
| Layer | Max Tokens | Allocation Strategy |
|---|---|---|
| System Instructions | 800 | Fixed static budget |
| User & Page Context | 400 | Injected dynamically |
| Knowledge Passages | 2,500 | Dense RAG excerpts |
| Conversation Memory | 1,500 | Compressed sliding window |
| Max Response Output | 1,000 | Generated completion |