A workspace bot asked to "update the workspace record" wrote to its own memory there, called it the workspace's record, and then, when the user said nothing had changed, denied making any write at all: it checked nothing and confessed to work it had done. - Say in the prompt that the workspace's context is the user's, and that memory in a workspace is the bot's own notes, readable in its settings - Say the same in update_memory and update_instructions results, with where the user reads it and that the workspace's own fields didn't change - Have ActionCheckNote look at what actually happened before agreeing with a user that nothing was done, and never deny work that happened
88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
type WorkspacePrompt = {
|
|
name?: string | null;
|
|
description?: string | null;
|
|
system_prompt?: string | null;
|
|
};
|
|
|
|
type WorkspaceBotPrompt = {
|
|
system_prompt?: string | null;
|
|
memory?: string | null;
|
|
};
|
|
|
|
type Params = {
|
|
system_prompt?: string | null;
|
|
memory?: string | null;
|
|
/**
|
|
* What the bot remembers about the user it's working with.
|
|
*/
|
|
user_memory?: string | null;
|
|
/**
|
|
* The workspace the bot is working in, if any.
|
|
*/
|
|
workspace?: WorkspacePrompt | null;
|
|
/**
|
|
* The bot's own instructions and memory for that workspace.
|
|
*/
|
|
workspace_bot?: WorkspaceBotPrompt | null;
|
|
};
|
|
|
|
/**
|
|
* The full prompt a bot runs with (markdown): its own core instructions,
|
|
* then, in a workspace, the workspace's context and the bot's
|
|
* instructions there, then its core memory, its memory about the user and
|
|
* its memory in the workspace (said to be the bot's own notes, not the
|
|
* workspace's context). Empty parts are left out; the workspace heading
|
|
* always shows, so the bot knows where it is.
|
|
*/
|
|
export default function composeBotPrompt({
|
|
system_prompt,
|
|
memory,
|
|
user_memory,
|
|
workspace,
|
|
workspace_bot,
|
|
}: Params) {
|
|
const parts: string[] = [];
|
|
const name = workspace?.name?.trim() || "Untitled";
|
|
|
|
if (system_prompt?.trim()) {
|
|
parts.push(system_prompt.trim());
|
|
}
|
|
|
|
if (workspace) {
|
|
const context = [workspace.description?.trim(), workspace.system_prompt?.trim()].filter(
|
|
Boolean,
|
|
) as string[];
|
|
|
|
parts.push(
|
|
[
|
|
`# Workspace: ${name}`,
|
|
`You're working in the workspace "${name}". Follow its context and your instructions for it below, over your general habits where they differ.`,
|
|
context.length ? "The workspace's context, which the user sets:" : "",
|
|
...context,
|
|
]
|
|
.filter(Boolean)
|
|
.join("\n\n"),
|
|
);
|
|
|
|
if (workspace_bot?.system_prompt?.trim()) {
|
|
parts.push(`# Your instructions in ${name}\n\n${workspace_bot.system_prompt.trim()}`);
|
|
}
|
|
}
|
|
|
|
if (memory?.trim()) {
|
|
parts.push(`# Memory\n\n${memory.trim()}`);
|
|
}
|
|
|
|
if (user_memory?.trim()) {
|
|
parts.push(`# Memory about the user\n\n${user_memory.trim()}`);
|
|
}
|
|
|
|
if (workspace && workspace_bot?.memory?.trim()) {
|
|
parts.push(
|
|
`# Memory in ${name}\n\nYour own notes for this workspace: what you have learned here. They are not the workspace's description or context, which the user sets above; never call them the workspace's record. The user reads them in the workspace's settings, under this bot's row.\n\n${workspace_bot.memory.trim()}`,
|
|
);
|
|
}
|
|
|
|
return parts.join("\n\n");
|
|
}
|