Composing Context logo

Composing Context

Organization
friday-platform
composing-context

Internal pattern guide for composing turn-local retrieval-gated context into a synthetic user-message preface. Documents the `composePreface` helper in `@atlas/core/agent-context/compose-preface`. Loaded by infrastructure code that assembles per-turn LLM input — not user-invocable.

Overview

Publisherfriday-platform
Repositoryfriday-studio
Skill namecomposing-context
Stars
102
Forks
5
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by friday-platform on GitHub. Read the source before you install it.

Installation

Install the Composing Context AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/friday-platform/friday-studio/tree/main/packages/system/skills/composing-context
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/friday-platform/friday-studio.git /tmp/friday-studio
mkdir -p .claude/skills
cp -r /tmp/friday-studio/packages/system/skills/composing-context .claude/skills/composing-context
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Composing Context in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Composing Context on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Composing Context is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Composing turn-local context as a synthetic user-message preface

This skill documents the synthetic user-message preface pattern used by Friday's chat supervisor and FSM type: llm actions to surface turn-local retrieved content (artifacts, narrative memory, temporal facts, future on-demand retrieval) to the model.

Why a synthetic preface and not the system prompt

Per-turn data does not belong in the system prompt. Mixing turn-local bytes into the system prompt invalidates the cacheable prefix on every turn, defeats Anthropic's 4-breakpoint cache layout (blocks 1/2/3 + top-level), and pulls org-private bytes into a cache scope that may be shared across tenants.

The synthetic preface lives in the first user message of the conversation, wrapped in <retrieved_content> envelopes. The system prompt stays byte-stable across weeks (block 1), workspace life (block 2), and session (block 3); turn-local variation rides in the messages array where it doesn't poison the cacheable prefix.

The helper: composePreface

ts
import {
  composePreface,
  type PrefaceEntry,
} from "@atlas/core/agent-context/compose-preface";

const entries: PrefaceEntry[] = [
  {
    source: "user-authored",
    origin: "memory:workspace-stores",
    body: memoryBlocks.join("\n\n"),
    fetched_at: new Date().toISOString(),
  },
  {
    source: "user-authored",
    origin: "artifacts:session",
    body: artifactBlocks.join("\n\n"),
    fetched_at: new Date().toISOString(),
  },
];

const preface = composePreface(entries);
// "" when entries is empty — concatenate without conditional checks.

Field semantics:

FieldMaps toPurpose
sourceprovenance attrTrust tier or content key (user-authored, external, system-config, artifact:<id>, memory:<store>, web:<url>, …)
originorigin attrHost scope the bytes were fetched from (workspace:<wsId>/session:<sId>, memory:workspace-stores, …)
bodyenvelope bodyModel-facing text
fetched_atfetched_at attrISO timestamp; omit when freshness is not meaningful

The helper is positionally indifferent — the caller decides whether to prepend the result as a synthetic user message, append it, or place it elsewhere. The string is the deliverable; positioning is the caller's choice.

The body is defanged before rendering: any literal </retrieved_content> close tag inside the body is rewritten to <\/retrieved_content> so a hostile payload cannot escape the envelope and land in the instructions frame. This mirrors wrapRetrieved in @atlas/llm.

Three call patterns

1. Pre-load: chat supervisor builds Block 4 from current state

The chat supervisor pulls memory + artifacts + temporal facts at the start of each turn, composes the preface, and prepends it as a synthetic user message at message position 0. The preface is ephemeral — it is not persisted to ChatStorage, so it does not accumulate in the conversation across turns.

See packages/system/agents/workspace-chat/workspace-chat.agent.ts (block4Entries / block4Preface / messagesWithBlock4Preface).

2. FSM type: llm action: same shape, prepended to action prompt

The FSM action runtime mirrors the chat pattern: pull narrative memory (via composeMemoryBlocks) and session-bound artifacts (via composeArtifactEntries), compose with composePreface, and prepend to the action's contextPrompt. The structured-entry shape from composeArtifactEntries is designed to drop straight into composePreface without intermediate string mangling.

See packages/fsm-engine/fsm-engine.ts (the case "llm" action prompt assembly).

3. On-demand mid-turn retrieval (forward-looking)

A future tool (e.g. web_fetch, parse_artifact, mid-turn semantic search) can hand the freshly-retrieved entry list to composePreface and inject it inline using whatever shape the LLM provider supports for mid-stream context — the helper is positionally indifferent and shape-agnostic, so the new caller drops in without reshaping.

Rules for callers

  1. Build a list of PrefaceEntry records, not pre-rendered XML strings. The helper owns the rendering. Callers that already have pre-rendered envelopes (e.g. composeArtifactBlocks's legacy return shape) wrap them in a single PrefaceEntry rather than reformatting each one — see Block 4 in the chat supervisor for the canonical example.

  2. Set source to a trust tier or content key, not a generic label. The model's <retrieved_content_hygiene> rule keys off provenance to decide trust (user-authored / system-config are trusted; external is not). Use the conventions in @atlas/llm/retrieved-content.ts:ProvenanceSource when the source is a trust tier.

  3. Set origin to a parseable host:scope identifier. The model does not parse origin literally, but operators inspecting captured transcripts do. Conventions: workspace:<wsId>/session:<sId>, memory:<store>, web:<url>, fsm:<jobId>:input.

  4. Always set fetched_at when the body's freshness matters. Omit only for static content (e.g. system-config). Use the same timestamp for all entries assembled in one turn so operators can correlate them.

  5. Do not nest <retrieved_content> envelopes deliberately, except in the legacy chat-Block-4 wrap-of-wrapped pattern that exists for per-section grouping. The defang protects against accidental nesting; deliberate nesting creates confusing transcripts.

  6. Never persist the preface as part of a stored UI message. It is an ephemeral runtime artifact rebuilt from current state each turn. Persisting it accumulates stale snapshots in the conversation and defeats the point of having retrieval-gated content.

Frequently asked questions

What does the Composing Context AI skill do?

Internal pattern guide for composing turn-local retrieval-gated context into a synthetic user-message preface. Documents the `composePreface` helper in `@atlas/core/agent-context/compose-preface`. Loaded by infrastructure code that assembles per-turn LLM input — not user-invocable.

Why use Composing Context on TypingMind?

Because you install it once and use it with any model. Composing Context is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Composing Context in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/friday-platform/friday-studio/tree/main/packages/system/skills/composing-context. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Composing Context?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Composing Context?

As many as you like. As long as a model supports skills, you can use Composing Context with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Composing Context AI skill free?

It is published on GitHub by friday-platform. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇