composing-context

Render retrieved content into synthetic user-message prefaces with provenance metadata.

97|5|Updated Apr 23, 2026
One-click install
npx skills add https://github.com/friday-platform/friday-studio --skill composing-context
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: composing-context
Source: https://github.com/friday-platform/friday-studio/tree/main/packages/system/skills/composing-context
Command: npx skills add https://github.com/friday-platform/friday-studio --skill composing-context

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill solves the critical issue of broken LLM caching and cross-tenant data leakage that occurs when turn-local retrieved content (such as session memory, artifacts, and temporal facts) is mixed directly into the system prompt. This practice invalidates cacheable prefixes on every turn, wastes token budget, and exposes private tenant data to shared cache scopes.

Core Features & Use Cases

  • Synthetic Preface Pattern: Keeps turn-local retrieved content out of the system prompt by wrapping it in a synthetic first user message, preserving cache efficiency and data isolation.
  • Safe Rendering Helper: Includes the composePreface utility that automatically escapes malicious closing envelope tags in retrieved content to prevent injection attacks that would break out of the retrieved content wrapper.
  • Production Use Cases: Used by Friday's chat supervisor and FSM type: llm actions to assemble per-turn LLM inputs, with built-in support for future on-demand mid-turn retrieval tools like web fetch and artifact parsing.

Quick Start

Import the composePreface helper from the @atlas/core/agent-context/compose-preface module, pass your list of preface entry records containing your retrieved content to it, and prepend the returned preface string as a synthetic user message to the start of your LLM prompt.

Frequently Asked Questions about composing-context

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does adding retrieved content to a system prompt break LLM caching?

Embedding turn-local retrieved content directly into a system prompt invalidates cacheable prefixes on every turn and wastes token budget. Moving this content into a synthetic user-message preface preserves LLM cache efficiency and isolates cross-tenant data.

How do I assemble per-turn LLM inputs without leaking cross-tenant data?

To assemble per-turn LLM inputs safely, wrap turn-local retrieved content in a synthetic first user message using a preface helper. This isolates cross-tenant data from shared cache scopes found in the system prompt.

What is the best way to prevent prompt injection in retrieved context?

The best way to prevent prompt injection in retrieved context is to use a safe rendering helper that automatically escapes malicious closing envelope tags. This prevents attacks from breaking out of the retrieved content wrapper during prompt assembly.

Can I use a synthetic preface for on-demand mid-turn retrieval in an agent runtime?

Yes, synthetic prefaces support on-demand mid-turn retrieval tools like web fetch and artifact parsing within an agent runtime. They safely render temporal facts and session memory into per-turn LLM inputs without breaking caching.

How does a synthetic user message preface format retrieved content?

A synthetic user message preface formats retrieved content by wrapping it as a first user message with correct provenance and freshness metadata. This approach keeps the system prompt stable while safely injecting turn-local artifacts.

When should I not use system prompts for session memory in LLM actions?

You should not use system prompts for session memory in FSM type: llm actions when retrieved content changes per turn. Doing so breaks LLM caching and risks cross-tenant data leakage across shared cache scopes.