feat: recipe-based system prompt management (#1293)

This commit is contained in:
Devansh Jain
2026-03-09 17:20:11 -07:00
committed by GitHub
parent c55a1fbd22
commit f148beee5d
8 changed files with 470 additions and 295 deletions

View File

@@ -343,25 +343,21 @@ export async function updateAgentSystemPrompt(
systemPromptId: string,
): Promise<UpdateSystemPromptResult> {
try {
const { resolveSystemPrompt } = await import("./promptAssets");
const { detectMemoryPromptDrift, reconcileMemoryPrompt } = await import(
"./memoryPrompt"
const { isKnownPreset, resolveAndBuildSystemPrompt } = await import(
"./promptAssets"
);
const { settingsManager } = await import("../settings-manager");
const client = await getClient();
const currentAgent = await client.agents.retrieve(agentId);
const baseContent = await resolveSystemPrompt(systemPromptId);
const settingIndicatesMemfs = settingsManager.isMemfsEnabled(agentId);
const promptIndicatesMemfs = detectMemoryPromptDrift(
currentAgent.system || "",
"standard",
).some((drift) => drift.code === "memfs_language_with_standard_mode");
const memoryMode =
settingIndicatesMemfs || promptIndicatesMemfs ? "memfs" : "standard";
const systemPromptContent = reconcileMemoryPrompt(baseContent, memoryMode);
settingsManager.isReady && settingsManager.isMemfsEnabled(agentId)
? "memfs"
: "standard";
const systemPromptContent = await resolveAndBuildSystemPrompt(
systemPromptId,
memoryMode,
);
const updateResult = await updateAgentSystemPromptRaw(
agentId,
@@ -375,6 +371,15 @@ export async function updateAgentSystemPrompt(
};
}
// Persist preset for known presets; clear stale preset for subagent/unknown
if (settingsManager.isReady) {
if (isKnownPreset(systemPromptId)) {
settingsManager.setSystemPromptPreset(agentId, systemPromptId);
} else {
settingsManager.clearSystemPromptPreset(agentId);
}
}
// Re-fetch agent to get updated state
const agent = await client.agents.retrieve(agentId);
@@ -407,15 +412,26 @@ export async function updateAgentSystemPromptMemfs(
enableMemfs: boolean,
): Promise<SystemPromptUpdateResult> {
try {
const client = await getClient();
const agent = await client.agents.retrieve(agentId);
const { reconcileMemoryPrompt } = await import("./memoryPrompt");
const nextSystemPrompt = reconcileMemoryPrompt(
agent.system || "",
enableMemfs ? "memfs" : "standard",
const { settingsManager } = await import("../settings-manager");
const { isKnownPreset, buildSystemPrompt, swapMemoryAddon } = await import(
"./promptAssets"
);
const newMode = enableMemfs ? "memfs" : "standard";
const storedPreset = settingsManager.isReady
? settingsManager.getSystemPromptPreset(agentId)
: undefined;
let nextSystemPrompt: string;
if (storedPreset && isKnownPreset(storedPreset)) {
nextSystemPrompt = buildSystemPrompt(storedPreset, newMode);
} else {
const client = await getClient();
const agent = await client.agents.retrieve(agentId);
nextSystemPrompt = swapMemoryAddon(agent.system || "", newMode);
}
const client = await getClient();
await client.agents.update(agentId, {
system: nextSystemPrompt,
});