Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

fix(shared): preserve paragraph breaks in the Bot system prompt (#48)

Arpan Sarkarea0ed61a0ea7
diff --git a/shared/bot-prompt.test.ts b/shared/bot-prompt.test.ts
new file mode 100644
index 00000000..21208213
--- /dev/null
+++ b/shared/bot-prompt.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, test } from "bun:test";
+import { SYSTEM_PROMPT } from "./bot-prompt";
+
+describe("SYSTEM_PROMPT", () => {
+ test("keeps paragraph breaks as blank lines instead of collapsing them into spaces", () => {
+ expect(SYSTEM_PROMPT).toContain("\n\n");
+ expect(SYSTEM_PROMPT).not.toContain(" ");
+ });
+
+ test("keeps each paragraph as one unbroken line of prose", () => {
+ for (const paragraph of SYSTEM_PROMPT.split("\n\n")) {
+ expect(paragraph).not.toContain("\n");
+ expect(paragraph.length).toBeGreaterThan(0);
+ }
+ });
+
+ test("still contains the full instruction text, unchanged in wording", () => {
+ expect(SYSTEM_PROMPT).toContain(
+ "You are a Bot with your own computer, a real web browser the person can watch you use.",
+ );
+ expect(SYSTEM_PROMPT).toContain(
+ "Say what you found or did in plain language, briefly.",
+ );
+ });
+});
diff --git a/shared/bot-prompt.ts b/shared/bot-prompt.ts
index 8e924902..2b1ec529 100644
--- a/shared/bot-prompt.ts
+++ b/shared/bot-prompt.ts
@@ -10,7 +10,7 @@
* The prompt requires snapshot-first computer use. Element refs are opaque and valid only with the
* snapshotId that produced them, so the Bot must read refs from the page before acting.
*/
-export const SYSTEM_PROMPT = [
+const SYSTEM_PROMPT_LINES = [
"You are a Bot with your own computer, a real web browser the person can watch you use.",
"When you are asked to look at, open, visit, check or read a web page, call computer_navigate.",
"Never claim you cannot browse: opening a page is something you can actually do.",
@@ -53,4 +53,22 @@ export const SYSTEM_PROMPT = [
"something to retry: say plainly what was blocked and why, and stop. Do not try another route to",
"the same thing.",
"Say what you found or did in plain language, briefly.",
-].join(" ");
+];
+
+/**
+ * `SYSTEM_PROMPT_LINES` uses `""` as a paragraph break. Joining the whole array with `" "` would
+ * collapse those breaks into a double space instead of a real paragraph gap, turning the prompt into
+ * one run-on block. Join each paragraph's lines with a space, then join paragraphs with a blank line.
+ */
+export const SYSTEM_PROMPT = SYSTEM_PROMPT_LINES.reduce<string[]>(
+ (paragraphs, line) => {
+ if (line === "") {
+ paragraphs.push("");
+ return paragraphs;
+ }
+ const last = paragraphs.length - 1;
+ paragraphs[last] = paragraphs[last] ? `${paragraphs[last]} ${line}` : line;
+ return paragraphs;
+ },
+ [""],
+).join("\n\n");