Logo Composing Context

Composing Context

Tổ chức
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.

Add to TypingMind

Tổng quan

Nhà phát hànhfriday-platform
Kho mãfriday-studio
Tên kỹ năngcomposing-context
Sao
102
Bản fork
5
Tệp đi kèm
Chỉ có hướng dẫn
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được friday-platform công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Composing Context trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/friday-platform/friday-studio/tree/main/packages/system/skills/composing-context
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

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
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Composing Context trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Composing Context ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Composing Context với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

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.

Câu hỏi thường gặp

Kỹ năng AI Composing Context làm được gì?

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.

Vì sao nên dùng Composing Context trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Composing Context là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Composing Context trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/friday-platform/friday-studio/tree/main/packages/system/skills/composing-context. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Composing Context?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Composing Context với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Composing Context với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Composing Context có miễn phí không?

Kỹ năng này được friday-platform phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇