Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

1.2 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

export type AgentsMdRecord = { text: string };

export const EMPTY_AGENTS_MD: AgentsMdRecord = { text: "" };

let agentsMdEdits = 0;

/** Bumped when Settings saves memory, so a cached read from before the save is not sent. */
export function forgetAgentsMd(): void {
  agentsMdEdits += 1;
}

export function agentsMdEditCount(): number {
  return agentsMdEdits;
}

/** System prompt for one request. AGENTS.md first, so project instructions and the typed system prompt
 *  have the last word; with no AGENTS.md this is byte-identical to the prompt before AGENTS.md support. */
export function composeChatInstructions(parts: {
  agentsMd?: AgentsMdRecord;
  projectInstructions: string;
  systemPrompt: string;
}): string {
  const agentsMd = parts.agentsMd?.text.trim() ?? "";
  return [
    agentsMd ? `<agents_md>\n${agentsMd}\n</agents_md>` : "",
    parts.projectInstructions
      ? `<project_instructions>\n${parts.projectInstructions}\n</project_instructions>`
      : "",
    parts.systemPrompt.trim(),
  ]
    .filter(Boolean)
    .join("\n\n");
}