Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/chat/__tests__/buildAgentSystemPrompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { buildAgentSystemPrompt } from "@/lib/chat/buildAgentSystemPrompt";
describe("buildAgentSystemPrompt", () => {
it("emits only customInstructions when no cwd is provided", () => {
const prompt = buildAgentSystemPrompt({ customInstructions: "hello" });
expect(prompt).toBe("hello");
expect(prompt).toContain("hello");
expect(prompt).not.toMatch(/Working directory/);
});

Expand All @@ -26,7 +26,9 @@ describe("buildAgentSystemPrompt", () => {
expect(customIdx).toBeGreaterThan(envIdx);
});

it("returns empty string when all options are empty", () => {
expect(buildAgentSystemPrompt({})).toBe("");
it("always includes the data-grounding no-fabrication rule, even with empty options", () => {
const prompt = buildAgentSystemPrompt({});
expect(prompt).toMatch(/never fabricate/i);
expect(prompt).toMatch(/sample|estimate|industry average/i);
});
});
12 changes: 11 additions & 1 deletion lib/chat/buildAgentSystemPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const ENVIRONMENT_SECTION = `# Environment
Working directory: . (workspace root)
Use workspace-relative paths for all file operations.`;

const DATA_GROUNDING_SECTION = `# Data grounding — never fabricate

State only figures, statistics, or facts you retrieved from a **successful tool
call in this run**. If a data call fails, returns empty, or the source isn't
connected, say so plainly (e.g. "no YouTube data connected for this artist") and
omit the metric — send a shorter, honest report or stop. **Never** estimate, use
"industry averages", or fill gaps with sample/placeholder/illustrative numbers. A
short accurate report always beats a padded one built on invented data.`;

export type BuildAgentSystemPromptOptions = {
/**
* Sandbox working directory. Triggers inclusion of the Environment
Expand Down Expand Up @@ -39,7 +48,8 @@ export type BuildAgentSystemPromptOptions = {
* generated branches).
*/
export function buildAgentSystemPrompt(options: BuildAgentSystemPromptOptions): string {
const parts: string[] = [];
// Always first: the no-fabrication rule applies to every agent run.
const parts: string[] = [DATA_GROUNDING_SECTION];

if (options.cwd) {
parts.push(ENVIRONMENT_SECTION);
Expand Down
Loading