refactor(prompt): split stable prefix from volatile tail
This commit is contained in:
1 parent
227fd7faf2
commit
2cdf26f9fa
13 files changed
+242
-54
No files matched your search
@@ -7,7 +7,7 @@ Do not print or echo AGENT_COMPANY_API_KEY into comments, summaries, or external
|
|||||||
Every API call MUST include these headers:
|
Every API call MUST include these headers:
|
||||||
Authorization: Bearer $AGENT_COMPANY_API_KEY
|
Authorization: Bearer $AGENT_COMPANY_API_KEY
|
||||||
Content-Type: application/json; charset=utf-8
|
Content-Type: application/json; charset=utf-8
|
||||||
X-Agent-Company-Run-Id: {{runId}}
|
X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID
|
||||||
|
|
||||||
Prefer Node.js fetch() over curl so non-ASCII bodies (Chinese, Japanese, etc.) are transmitted
|
Prefer Node.js fetch() over curl so non-ASCII bodies (Chinese, Japanese, etc.) are transmitted
|
||||||
correctly across all platforms. When curl is the only option, write the JSON body to a temp
|
correctly across all platforms. When curl is the only option, write the JSON body to a temp
|
||||||
@@ -18,7 +18,7 @@ Example using fetch (Node.js) — PREFERRED:
|
|||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bearer ${process.env.AGENT_COMPANY_API_KEY}`,
|
"Authorization": `Bearer ${process.env.AGENT_COMPANY_API_KEY}`,
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"X-Agent-Company-Run-Id": "{{runId}}"
|
"X-Agent-Company-Run-Id": process.env.AGENT_COMPANY_RUN_ID
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -29,7 +29,7 @@ Example POST using fetch (Node.js) — PREFERRED for non-ASCII content:
|
|||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bearer ${process.env.AGENT_COMPANY_API_KEY}`,
|
"Authorization": `Bearer ${process.env.AGENT_COMPANY_API_KEY}`,
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"X-Agent-Company-Run-Id": "{{runId}}"
|
"X-Agent-Company-Run-Id": process.env.AGENT_COMPANY_RUN_ID
|
||||||
},
|
},
|
||||||
body: JSON.stringify({title:"Task title",description:"Details",assigneeAgentId:"agent-id",priority:"medium",status:"todo"})
|
body: JSON.stringify({title:"Task title",description:"Details",assigneeAgentId:"agent-id",priority:"medium",status:"todo"})
|
||||||
});
|
});
|
||||||
@@ -38,14 +38,14 @@ Example GET using curl:
|
|||||||
curl -s -X GET "$AGENT_COMPANY_API_URL/api/agents/me" \
|
curl -s -X GET "$AGENT_COMPANY_API_URL/api/agents/me" \
|
||||||
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
||||||
-H "Content-Type: application/json; charset=utf-8" \
|
-H "Content-Type: application/json; charset=utf-8" \
|
||||||
-H "X-Agent-Company-Run-Id: {{runId}}"
|
-H "X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID"
|
||||||
|
|
||||||
Example POST using curl (write body to temp file to avoid encoding issues):
|
Example POST using curl (write body to temp file to avoid encoding issues):
|
||||||
echo '{"title":"Task title","description":"Details","priority":"medium","status":"todo"}' > /tmp/body.json
|
echo '{"title":"Task title","description":"Details","priority":"medium","status":"todo"}' > /tmp/body.json
|
||||||
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/issues" \
|
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/issues" \
|
||||||
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
||||||
-H "Content-Type: application/json; charset=utf-8" \
|
-H "Content-Type: application/json; charset=utf-8" \
|
||||||
-H "X-Agent-Company-Run-Id: {{runId}}" \
|
-H "X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID" \
|
||||||
-d @/tmp/body.json
|
-d @/tmp/body.json
|
||||||
|
|
||||||
IMPORTANT: Always check the HTTP response status. 200/201 = success, 4xx = client error (read the error message), 5xx = server error (retry once then report).
|
IMPORTANT: Always check the HTTP response status. 200/201 = success, 4xx = client error (read the error message), 5xx = server error (retry once then report).
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Example — send urgent message to a peer:
|
|||||||
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/messages" \
|
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/messages" \
|
||||||
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Agent-Company-Run-Id: {{runId}}" \
|
-H "X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID" \
|
||||||
-d '{"toAgentId":"PEER_ID","channel":"direct","subject":"Need API spec for integration","body":"I am working on task X and need the API contract from your team. Can you share or create a document?","priority":"urgent"}'
|
-d '{"toAgentId":"PEER_ID","channel":"direct","subject":"Need API spec for integration","body":"I am working on task X and need the API contract from your team. Can you share or create a document?","priority":"urgent"}'
|
||||||
|
|
||||||
### List Your Messages
|
### List Your Messages
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ Example: Create a task assigned to a report:
|
|||||||
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/issues" \
|
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/issues" \
|
||||||
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Agent-Company-Run-Id: {{runId}}" \
|
-H "X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID" \
|
||||||
-d '{"title":"Implement user auth","description":"Build JWT-based auth with refresh tokens. Acceptance: login, logout, token refresh all work.","assigneeAgentId":"REPORT_ID","projectId":"PROJ_ID","goalId":"GOAL_ID","requiresFilesystem":true,"priority":"high","status":"todo"}'
|
-d '{"title":"Implement user auth","description":"Build JWT-based auth with refresh tokens. Acceptance: login, logout, token refresh all work.","assigneeAgentId":"REPORT_ID","projectId":"PROJ_ID","goalId":"GOAL_ID","requiresFilesystem":true,"priority":"high","status":"todo"}'
|
||||||
|
|
||||||
### Update a Task
|
### Update a Task
|
||||||
@@ -48,13 +48,13 @@ Example — approve reviewed work:
|
|||||||
curl -s -X PATCH "$AGENT_COMPANY_API_URL/api/issues/ISSUE_ID" \
|
curl -s -X PATCH "$AGENT_COMPANY_API_URL/api/issues/ISSUE_ID" \
|
||||||
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Agent-Company-Run-Id: {{runId}}" \
|
-H "X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID" \
|
||||||
-d '{"status":"done","comment":"Reviewed and approved. Implementation meets acceptance criteria."}'
|
-d '{"status":"done","comment":"Reviewed and approved. Implementation meets acceptance criteria."}'
|
||||||
Example — request changes:
|
Example — request changes:
|
||||||
curl -s -X PATCH "$AGENT_COMPANY_API_URL/api/issues/ISSUE_ID" \
|
curl -s -X PATCH "$AGENT_COMPANY_API_URL/api/issues/ISSUE_ID" \
|
||||||
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Agent-Company-Run-Id: {{runId}}" \
|
-H "X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID" \
|
||||||
-d '{"status":"in_progress","comment":"Needs changes: 1) Add error handling for edge case X. 2) Unit test coverage is below threshold."}'
|
-d '{"status":"in_progress","comment":"Needs changes: 1) Add error handling for edge case X. 2) Unit test coverage is below threshold."}'
|
||||||
|
|
||||||
### Checkout a Task (claim it before working)
|
### Checkout a Task (claim it before working)
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ function render(template: string, ctx: PromptContext): string {
|
|||||||
.replace(/\{\{apiUrl\}\}/g, ctx.apiUrl)
|
.replace(/\{\{apiUrl\}\}/g, ctx.apiUrl)
|
||||||
.replace(/\{\{companyId\}\}/g, ctx.agent.companyId)
|
.replace(/\{\{companyId\}\}/g, ctx.agent.companyId)
|
||||||
.replace(/\{\{agentId\}\}/g, ctx.agent.id)
|
.replace(/\{\{agentId\}\}/g, ctx.agent.id)
|
||||||
.replace(/\{\{runId\}\}/g, ctx.runId)
|
|
||||||
.replace(/\{\{connectorIds\}\}/g, connectorIds)
|
.replace(/\{\{connectorIds\}\}/g, connectorIds)
|
||||||
.replace(/\{\{approvalTypes\}\}/g, approvalTypeEnum.options.join("|"))
|
.replace(/\{\{approvalTypes\}\}/g, approvalTypeEnum.options.join("|"))
|
||||||
.replace(/\{\{approvalTypeList\}\}/g, renderApprovalTypeList())
|
.replace(/\{\{approvalTypeList\}\}/g, renderApprovalTypeList())
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Before doing anything else, assess the state of the company:
|
|||||||
If there are NO active goals, this is your top priority — create strategic goals:
|
If there are NO active goals, this is your top priority — create strategic goals:
|
||||||
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/goals" \
|
curl -s -X POST "$AGENT_COMPANY_API_URL/api/companies/{{companyId}}/goals" \
|
||||||
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" -H "Content-Type: application/json" \
|
-H "Authorization: Bearer $AGENT_COMPANY_API_KEY" -H "Content-Type: application/json" \
|
||||||
-H "X-Agent-Company-Run-Id: {{runId}}" \
|
-H "X-Agent-Company-Run-Id: $AGENT_COMPANY_RUN_ID" \
|
||||||
-d '{"title":"Goal title","description":"Measurable success criteria","ownerAgentId":"{{agentId}}","status":"active"}'
|
-d '{"title":"Goal title","description":"Measurable success criteria","ownerAgentId":"{{agentId}}","status":"active"}'
|
||||||
Then decompose each goal into projects, and each project into tasks assigned to department leads.
|
Then decompose each goal into projects, and each project into tasks assigned to department leads.
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import type { AgentRecord, ApprovalRecord, DocumentRecord, ExecutionMode, GoalRecord, KnowledgeEntryRecord, MeetingRecord, ProjectRecord, SprintRecord, TaskRecord } from "@shared/types";
|
import type { AgentRecord, ApprovalRecord, DocumentRecord, ExecutionMode, GoalRecord, KnowledgeEntryRecord, MeetingRecord, ProjectRecord, SprintRecord, TaskRecord } from "@shared/types";
|
||||||
import type { AppLocale } from "@shared/locale";
|
import type { AppLocale } from "@shared/locale";
|
||||||
import type { ProjectedSkill } from "../skill-types";
|
import type { ProjectedSkill } from "../skill-types";
|
||||||
import { buildSystemPrompt } from "./system-prompt";
|
import { buildSystemPrompt, buildVolatilePromptTail } from "./system-prompt";
|
||||||
import { renderWakeReason } from "./wake-reasons";
|
import { renderWakeReason } from "./wake-reasons";
|
||||||
import { getSystemMessages } from "./messages";
|
import { getSystemMessages } from "./messages";
|
||||||
|
|
||||||
export { buildSystemPrompt } from "./system-prompt";
|
export { buildStableSystemPrompt, buildSystemPrompt, buildVolatilePromptTail } from "./system-prompt";
|
||||||
|
|
||||||
export interface PromptContext {
|
export interface PromptContext {
|
||||||
agent: AgentRecord;
|
agent: AgentRecord;
|
||||||
@@ -99,5 +99,10 @@ export function buildTaskPrompt(ctx: PromptContext): string {
|
|||||||
parts.push(m.immediateTaskSection(ctx.task.title, ctx.task.description, ctx.task.priority));
|
parts.push(m.immediateTaskSection(ctx.task.title, ctx.task.description, ctx.task.priority));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const volatileContextTail = buildVolatilePromptTail(ctx);
|
||||||
|
if (volatileContextTail) {
|
||||||
|
parts.push(`\n${volatileContextTail}`);
|
||||||
|
}
|
||||||
|
|
||||||
return parts.join("");
|
return parts.join("");
|
||||||
}
|
}
|
||||||
@@ -38,13 +38,19 @@ const MODE_TEMPLATES: Record<CeoMode, string> = {
|
|||||||
function render(template: string, ctx: PromptContext): string {
|
function render(template: string, ctx: PromptContext): string {
|
||||||
return template
|
return template
|
||||||
.replace(/\{\{companyId\}\}/g, ctx.agent.companyId)
|
.replace(/\{\{companyId\}\}/g, ctx.agent.companyId)
|
||||||
.replace(/\{\{agentId\}\}/g, ctx.agent.id)
|
.replace(/\{\{agentId\}\}/g, ctx.agent.id);
|
||||||
.replace(/\{\{runId\}\}/g, ctx.runId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildCEOInstructions(ctx: PromptContext): string[] {
|
export function buildStableCEOInstructions(): string[] {
|
||||||
|
// Stable CEO directives come from identity, leadership style, culture, and
|
||||||
|
// decision authority sections. Mode SOPs live in the volatile tail.
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildCEOModeInstructions(ctx: PromptContext): string[] {
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
const mode = resolveMode(ctx);
|
const mode = resolveMode(ctx);
|
||||||
|
|
||||||
parts.push(render(MODE_TEMPLATES[mode], ctx));
|
parts.push(render(MODE_TEMPLATES[mode], ctx));
|
||||||
|
|
||||||
if (mode === "team_building") {
|
if (mode === "team_building") {
|
||||||
@@ -52,6 +58,16 @@ export function buildCEOInstructions(ctx: PromptContext): string[] {
|
|||||||
if (connectorSection) parts.push(connectorSection);
|
if (connectorSection) parts.push(connectorSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
parts.push(render(proactiveFooterEn, ctx));
|
if (mode === "operating") {
|
||||||
|
parts.push(render(proactiveFooterEn, ctx));
|
||||||
|
}
|
||||||
|
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function buildCEOInstructions(ctx: PromptContext): string[] {
|
||||||
|
return [
|
||||||
|
...buildCEOModeInstructions(ctx),
|
||||||
|
...buildStableCEOInstructions(),
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { PromptContext } from "./index";
|
import type { PromptContext } from "./index";
|
||||||
import { buildCEOInstructions } from "./operating-instructions-ceo";
|
import { buildStableCEOInstructions } from "./operating-instructions-ceo";
|
||||||
import { getOperatingMessages } from "./messages";
|
import { getOperatingMessages } from "./messages";
|
||||||
|
|
||||||
import engineeringEn from "./department-guidelines/engineering.en.md?raw";
|
import engineeringEn from "./department-guidelines/engineering.en.md?raw";
|
||||||
@@ -25,7 +25,7 @@ export function buildOperatingInstructions(ctx: PromptContext, isCEO: boolean, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCEO) {
|
if (isCEO) {
|
||||||
parts.push(...buildCEOInstructions(ctx));
|
parts.push(...buildStableCEOInstructions());
|
||||||
} else if (isManager) {
|
} else if (isManager) {
|
||||||
parts.push(...m.managerInstructions(ctx.agent.companyId));
|
parts.push(...m.managerInstructions(ctx.agent.companyId));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
buildDecisionAuthoritySection,
|
buildDecisionAuthoritySection,
|
||||||
buildDepartmentSection,
|
buildDepartmentSection,
|
||||||
} from "./operating-instructions";
|
} from "./operating-instructions";
|
||||||
|
import { buildCEOModeInstructions } from "./operating-instructions-ceo";
|
||||||
import type { PromptContext } from "./index";
|
import type { PromptContext } from "./index";
|
||||||
import type { ProjectedSkill } from "../skill-types";
|
import type { ProjectedSkill } from "../skill-types";
|
||||||
import { roleMatchesLeadershipKeywords } from "../agent-role-helpers";
|
import { roleMatchesLeadershipKeywords } from "../agent-role-helpers";
|
||||||
@@ -64,7 +65,7 @@ function escapeSkillXml(value: string): string {
|
|||||||
.replaceAll("'", "'");
|
.replaceAll("'", "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildSystemPrompt(ctx: PromptContext): string {
|
export function buildStableSystemPrompt(ctx: PromptContext): string {
|
||||||
const m = getSystemMessages();
|
const m = getSystemMessages();
|
||||||
const sections: string[] = [];
|
const sections: string[] = [];
|
||||||
|
|
||||||
@@ -132,16 +133,6 @@ export function buildSystemPrompt(ctx: PromptContext): string {
|
|||||||
}))
|
}))
|
||||||
.join("\n");
|
.join("\n");
|
||||||
sections.push(m.directReportsSection(lines));
|
sections.push(m.directReportsSection(lines));
|
||||||
|
|
||||||
const workloadLines = ctx.directReports.map((report) => {
|
|
||||||
const reportTasks = ctx.allTasks.filter((t) => t.assigneeAgentId === report.id);
|
|
||||||
const inProgress = reportTasks.filter((t) => t.status === "in_progress").length;
|
|
||||||
const inReview = reportTasks.filter((t) => t.status === "in_review").length;
|
|
||||||
const blocked = reportTasks.filter((t) => t.status === "blocked").length;
|
|
||||||
const todo = reportTasks.filter((t) => t.status === "todo").length;
|
|
||||||
return m.teamWorkloadLine(report.name, report.role, inProgress, inReview, blocked, todo);
|
|
||||||
}).join("\n");
|
|
||||||
sections.push(m.teamWorkloadSection(workloadLines));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.agent.department) {
|
if (ctx.agent.department) {
|
||||||
@@ -192,6 +183,44 @@ export function buildSystemPrompt(ctx: PromptContext): string {
|
|||||||
sections.push(m.projectsSection(lines));
|
sections.push(m.projectsSection(lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const audience = isCEO ? "executive" : isManager ? "manager" : "individual_contributor";
|
||||||
|
sections.push(buildSOPSection(audience));
|
||||||
|
sections.push(buildAPISection(ctx, audience));
|
||||||
|
|
||||||
|
sections.push(buildDepartmentSection(ctx));
|
||||||
|
sections.push(buildOperatingInstructions(ctx, isCEO, isManager));
|
||||||
|
sections.push(buildDecisionAuthoritySection(ctx, isCEO, isManager));
|
||||||
|
|
||||||
|
sections.push(m.structuredOutputSection);
|
||||||
|
|
||||||
|
return sections.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildSystemPrompt(ctx: PromptContext): string {
|
||||||
|
return buildStableSystemPrompt(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildVolatilePromptTail(ctx: PromptContext): string {
|
||||||
|
const m = getSystemMessages();
|
||||||
|
const sections: string[] = [];
|
||||||
|
const isCEO = ctx.chainOfCommand.length === 0;
|
||||||
|
|
||||||
|
if (isCEO) {
|
||||||
|
sections.push(...buildCEOModeInstructions(ctx));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.directReports.length > 0) {
|
||||||
|
const workloadLines = ctx.directReports.map((report) => {
|
||||||
|
const reportTasks = ctx.allTasks.filter((t) => t.assigneeAgentId === report.id);
|
||||||
|
const inProgress = reportTasks.filter((t) => t.status === "in_progress").length;
|
||||||
|
const inReview = reportTasks.filter((t) => t.status === "in_review").length;
|
||||||
|
const blocked = reportTasks.filter((t) => t.status === "blocked").length;
|
||||||
|
const todo = reportTasks.filter((t) => t.status === "todo").length;
|
||||||
|
return m.teamWorkloadLine(report.name, report.role, inProgress, inReview, blocked, todo);
|
||||||
|
}).join("\n");
|
||||||
|
sections.push(m.teamWorkloadSection(workloadLines));
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx.sessionHandoff) sections.push(m.sessionHandoffSection(ctx.sessionHandoff));
|
if (ctx.sessionHandoff) sections.push(m.sessionHandoffSection(ctx.sessionHandoff));
|
||||||
|
|
||||||
if (ctx.task) {
|
if (ctx.task) {
|
||||||
@@ -218,10 +247,6 @@ export function buildSystemPrompt(ctx: PromptContext): string {
|
|||||||
const approvalsSection = buildPendingApprovalsSection(ctx.pendingApprovals);
|
const approvalsSection = buildPendingApprovalsSection(ctx.pendingApprovals);
|
||||||
if (approvalsSection) sections.push(approvalsSection);
|
if (approvalsSection) sections.push(approvalsSection);
|
||||||
|
|
||||||
const audience = isCEO ? "executive" : isManager ? "manager" : "individual_contributor";
|
|
||||||
sections.push(buildSOPSection(audience));
|
|
||||||
sections.push(buildAPISection(ctx, audience));
|
|
||||||
|
|
||||||
if (ctx.recentComments.length > 0) {
|
if (ctx.recentComments.length > 0) {
|
||||||
const lines = ctx.recentComments.slice(0, 10)
|
const lines = ctx.recentComments.slice(0, 10)
|
||||||
.map((c) => m.recentCommentLine(c.taskTitle, c.authorName, c.body))
|
.map((c) => m.recentCommentLine(c.taskTitle, c.authorName, c.body))
|
||||||
@@ -229,10 +254,6 @@ export function buildSystemPrompt(ctx: PromptContext): string {
|
|||||||
sections.push(m.recentCommentsSection(lines));
|
sections.push(m.recentCommentsSection(lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
sections.push(buildDepartmentSection(ctx));
|
|
||||||
sections.push(buildOperatingInstructions(ctx, isCEO, isManager));
|
|
||||||
sections.push(buildDecisionAuthoritySection(ctx, isCEO, isManager));
|
|
||||||
|
|
||||||
const meetingsSection = buildMeetingsSection({
|
const meetingsSection = buildMeetingsSection({
|
||||||
upcomingMeetings: ctx.upcomingMeetings ?? [],
|
upcomingMeetings: ctx.upcomingMeetings ?? [],
|
||||||
allAgents: ctx.allAgents,
|
allAgents: ctx.allAgents,
|
||||||
@@ -261,7 +282,6 @@ export function buildSystemPrompt(ctx: PromptContext): string {
|
|||||||
});
|
});
|
||||||
if (docsSection) sections.push(docsSection);
|
if (docsSection) sections.push(docsSection);
|
||||||
|
|
||||||
sections.push(m.structuredOutputSection);
|
|
||||||
sections.push(m.importantRulesSection(ctx.agent.companyId, ctx.agent.id, ctx.runId));
|
sections.push(m.importantRulesSection(ctx.agent.companyId, ctx.agent.id, ctx.runId));
|
||||||
|
|
||||||
const localeName = ctx.locale === "zh" ? "Chinese" : null;
|
const localeName = ctx.locale === "zh" ? "Chinese" : null;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { buildSystemPrompt } from "../../../src/main/prompt-builder/index";
|
import { buildSystemPrompt, buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
||||||
import type { ApprovalRecord } from "../../../src/shared/types";
|
import type { ApprovalRecord } from "../../../src/shared/types";
|
||||||
import { installSharedSetup } from "./shared-setup";
|
import { installSharedSetup } from "./shared-setup";
|
||||||
|
|
||||||
@@ -22,14 +22,21 @@ describe("Step 2: CEO phased prompts", () => {
|
|||||||
pendingApprovals: [],
|
pendingApprovals: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const stablePrompt = buildSystemPrompt(ctx);
|
||||||
|
const prompt = buildTaskPrompt(ctx);
|
||||||
|
|
||||||
|
expect(stablePrompt).not.toContain("Team Building Phase");
|
||||||
|
expect(stablePrompt).not.toContain("Awaiting Hire Approvals");
|
||||||
|
expect(stablePrompt).not.toContain("Awaiting Org Strategy Approval");
|
||||||
expect(prompt).toContain("Team Building Phase");
|
expect(prompt).toContain("Team Building Phase");
|
||||||
expect(prompt).toContain("file 3–5 `hire_agent` tool calls");
|
expect(prompt).toContain("file 3–5 `hire_agent` tool calls");
|
||||||
expect(prompt).toContain("Do this first — file the hires");
|
expect(prompt).toContain("Do this first — file the hires");
|
||||||
expect(prompt).not.toContain("file_approval.strategy.before_hires");
|
expect(prompt).not.toContain("file_approval.strategy.before_hires");
|
||||||
expect(prompt).not.toContain("file_approval.strategy.already_filed");
|
expect(prompt).not.toContain("file_approval.strategy.already_filed");
|
||||||
expect(prompt).not.toContain("Awaiting Org Strategy Approval");
|
expect(prompt).not.toContain("Awaiting Org Strategy Approval");
|
||||||
|
expect(prompt).not.toContain("Standup & Situational Assessment");
|
||||||
expect(prompt).not.toContain("Goal Decomposition");
|
expect(prompt).not.toContain("Goal Decomposition");
|
||||||
|
expect(prompt).not.toContain("Proactive Behaviors");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Phase 0.5: shows awaiting hire approvals when pending_approval hires exist but no org approval", () => {
|
it("Phase 0.5: shows awaiting hire approvals when pending_approval hires exist but no org approval", () => {
|
||||||
@@ -45,12 +52,19 @@ describe("Step 2: CEO phased prompts", () => {
|
|||||||
pendingApprovals: [],
|
pendingApprovals: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const stablePrompt = buildSystemPrompt(ctx);
|
||||||
|
const prompt = buildTaskPrompt(ctx);
|
||||||
|
|
||||||
|
expect(stablePrompt).not.toContain("Team Building Phase");
|
||||||
|
expect(stablePrompt).not.toContain("Awaiting Hire Approvals");
|
||||||
|
expect(stablePrompt).not.toContain("Awaiting Org Strategy Approval");
|
||||||
expect(prompt).toContain("Awaiting Hire Approvals");
|
expect(prompt).toContain("Awaiting Hire Approvals");
|
||||||
expect(prompt).toContain("call `file_approval` once");
|
expect(prompt).toContain("call `file_approval` once");
|
||||||
expect(prompt).toContain("file_approval.strategy.before_hires");
|
expect(prompt).toContain("file_approval.strategy.before_hires");
|
||||||
expect(prompt).not.toContain("Team Building Phase");
|
expect(prompt).not.toContain("Team Building Phase");
|
||||||
|
expect(prompt).not.toContain("Standup & Situational Assessment");
|
||||||
expect(prompt).not.toContain("Goal Decomposition");
|
expect(prompt).not.toContain("Goal Decomposition");
|
||||||
|
expect(prompt).not.toContain("Proactive Behaviors");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Phase 1: shows awaiting org approval when pending approve_ceo_strategy exists", () => {
|
it("Phase 1: shows awaiting org approval when pending approve_ceo_strategy exists", () => {
|
||||||
@@ -77,10 +91,17 @@ describe("Step 2: CEO phased prompts", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const stablePrompt = buildSystemPrompt(ctx);
|
||||||
|
const prompt = buildTaskPrompt(ctx);
|
||||||
|
|
||||||
|
expect(stablePrompt).not.toContain("Team Building Phase");
|
||||||
|
expect(stablePrompt).not.toContain("Awaiting Hire Approvals");
|
||||||
|
expect(stablePrompt).not.toContain("Awaiting Org Strategy Approval");
|
||||||
expect(prompt).toContain("Awaiting Org Strategy Approval");
|
expect(prompt).toContain("Awaiting Org Strategy Approval");
|
||||||
expect(prompt).not.toContain("Team Building Phase");
|
expect(prompt).not.toContain("Team Building Phase");
|
||||||
|
expect(prompt).not.toContain("Standup & Situational Assessment");
|
||||||
expect(prompt).not.toContain("Goal Decomposition");
|
expect(prompt).not.toContain("Goal Decomposition");
|
||||||
|
expect(prompt).not.toContain("Proactive Behaviors");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Phase 2: shows normal executive instructions when active reports and no pending org approval", () => {
|
it("Phase 2: shows normal executive instructions when active reports and no pending org approval", () => {
|
||||||
@@ -95,11 +116,12 @@ describe("Step 2: CEO phased prompts", () => {
|
|||||||
pendingApprovals: [],
|
pendingApprovals: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const prompt = buildTaskPrompt(ctx);
|
||||||
expect(prompt).toContain("Executive / CEO");
|
expect(prompt).toContain("Executive / CEO");
|
||||||
expect(prompt).toContain("Goal Decomposition");
|
expect(prompt).toContain("Goal Decomposition");
|
||||||
expect(prompt).toContain("Delegation");
|
expect(prompt).toContain("Delegation");
|
||||||
expect(prompt).toContain("Unblock & Coordinate");
|
expect(prompt).toContain("Unblock & Coordinate");
|
||||||
|
expect(prompt).toContain("Proactive Behaviors");
|
||||||
expect(prompt).not.toContain("Team Building Phase");
|
expect(prompt).not.toContain("Team Building Phase");
|
||||||
expect(prompt).not.toContain("Awaiting Org Approval");
|
expect(prompt).not.toContain("Awaiting Org Approval");
|
||||||
});
|
});
|
||||||
@@ -130,7 +152,7 @@ describe("Step 2: CEO phased prompts", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const prompt = buildTaskPrompt(ctx);
|
||||||
expect(prompt).toContain("Pending Approvals");
|
expect(prompt).toContain("Pending Approvals");
|
||||||
expect(prompt).toContain("Need Twitter API keys");
|
expect(prompt).toContain("Need Twitter API keys");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { buildSystemPrompt, buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
import { buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
||||||
import type { ApprovalRecord } from "../../../src/shared/types";
|
import type { ApprovalRecord } from "../../../src/shared/types";
|
||||||
import { installSharedSetup } from "./shared-setup";
|
import { installSharedSetup } from "./shared-setup";
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
|
|||||||
chainOfCommand: [],
|
chainOfCommand: [],
|
||||||
pendingApprovals: [],
|
pendingApprovals: [],
|
||||||
});
|
});
|
||||||
const phase0Prompt = buildSystemPrompt(phase0Ctx);
|
const phase0Prompt = buildTaskPrompt(phase0Ctx);
|
||||||
expect(phase0Prompt).toContain("Team Building Phase");
|
expect(phase0Prompt).toContain("Team Building Phase");
|
||||||
|
|
||||||
// 2. CEO submits hire requests
|
// 2. CEO submits hire requests
|
||||||
@@ -60,7 +60,7 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
|
|||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
} as ApprovalRecord],
|
} as ApprovalRecord],
|
||||||
});
|
});
|
||||||
const phase1Prompt = buildSystemPrompt(phase1Ctx);
|
const phase1Prompt = buildTaskPrompt(phase1Ctx);
|
||||||
expect(phase1Prompt).toContain("Awaiting Org Strategy Approval");
|
expect(phase1Prompt).toContain("Awaiting Org Strategy Approval");
|
||||||
|
|
||||||
// 4. Board approves hires
|
// 4. Board approves hires
|
||||||
@@ -100,7 +100,7 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
|
|||||||
chainOfCommand: [],
|
chainOfCommand: [],
|
||||||
pendingApprovals: [], // all approved now
|
pendingApprovals: [], // all approved now
|
||||||
});
|
});
|
||||||
const phase2Prompt = buildSystemPrompt(phase2Ctx);
|
const phase2Prompt = buildTaskPrompt(phase2Ctx);
|
||||||
expect(phase2Prompt).toContain("Executive / CEO");
|
expect(phase2Prompt).toContain("Executive / CEO");
|
||||||
expect(phase2Prompt).toContain("Goal Decomposition");
|
expect(phase2Prompt).toContain("Goal Decomposition");
|
||||||
expect(phase2Prompt).toContain("Delegation");
|
expect(phase2Prompt).toContain("Delegation");
|
||||||
@@ -226,7 +226,7 @@ describe("Review Fix: CEO phase ordering edge case", () => {
|
|||||||
pendingApprovals: [], // org strategy already resolved
|
pendingApprovals: [], // org strategy already resolved
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const prompt = buildTaskPrompt(ctx);
|
||||||
// Should NOT get Phase 0 (team building) — hires are already submitted
|
// Should NOT get Phase 0 (team building) — hires are already submitted
|
||||||
expect(prompt).not.toContain("Team Building Phase");
|
expect(prompt).not.toContain("Team Building Phase");
|
||||||
// Should get the awaiting hire approvals phase
|
// Should get the awaiting hire approvals phase
|
||||||
@@ -245,7 +245,7 @@ describe("Review Fix: CEO phase ordering edge case", () => {
|
|||||||
pendingApprovals: [],
|
pendingApprovals: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const prompt = buildTaskPrompt(ctx);
|
||||||
expect(prompt).toContain("Executive / CEO");
|
expect(prompt).toContain("Executive / CEO");
|
||||||
expect(prompt).not.toContain("Awaiting Hire Approvals");
|
expect(prompt).not.toContain("Awaiting Hire Approvals");
|
||||||
expect(prompt).not.toContain("Team Building Phase");
|
expect(prompt).not.toContain("Team Building Phase");
|
||||||
@@ -277,7 +277,7 @@ describe("Review Fix: Org gate consistency (revision_requested)", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const prompt = buildTaskPrompt(ctx);
|
||||||
expect(prompt).toContain("Awaiting Org Strategy Approval");
|
expect(prompt).toContain("Awaiting Org Strategy Approval");
|
||||||
expect(prompt).toContain("revision_requested");
|
expect(prompt).toContain("revision_requested");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { buildSystemPrompt } from "../../../src/main/prompt-builder/index";
|
import { buildSystemPrompt, buildTaskPrompt } from "../../../src/main/prompt-builder/index";
|
||||||
import { installSharedSetup } from "./shared-setup";
|
import { installSharedSetup } from "./shared-setup";
|
||||||
|
|
||||||
const shared = installSharedSetup();
|
const shared = installSharedSetup();
|
||||||
@@ -19,7 +19,7 @@ describe("Step 1: CEO role detection", () => {
|
|||||||
chainOfCommand: [], // top-level
|
chainOfCommand: [], // top-level
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompt = buildSystemPrompt(ctx);
|
const prompt = buildTaskPrompt(ctx);
|
||||||
|
|
||||||
// CEO should NOT get IC instructions
|
// CEO should NOT get IC instructions
|
||||||
expect(prompt).not.toContain("Individual Contributor");
|
expect(prompt).not.toContain("Individual Contributor");
|
||||||
|
|||||||
@@ -71,6 +71,54 @@ function buildCtx(overrides: Partial<PromptContext> = {}): PromptContext {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildTask(overrides: Partial<NonNullable<PromptContext["task"]>> = {}): NonNullable<PromptContext["task"]> {
|
||||||
|
const now = new Date().toISOString();
|
||||||
|
return {
|
||||||
|
id: "task-1",
|
||||||
|
companyId: "company-1",
|
||||||
|
projectId: null,
|
||||||
|
goalId: null,
|
||||||
|
parentId: null,
|
||||||
|
title: "Ship volatile task",
|
||||||
|
description: "This task should live in the volatile prompt tail.",
|
||||||
|
assigneeAgentId: "agent-1",
|
||||||
|
workspaceId: null,
|
||||||
|
status: "in_progress",
|
||||||
|
priority: "high",
|
||||||
|
activeRunId: null,
|
||||||
|
costUsd: 0,
|
||||||
|
taskType: null,
|
||||||
|
requiresUserReview: false,
|
||||||
|
requiresFilesystem: false,
|
||||||
|
startedAt: null,
|
||||||
|
completedAt: null,
|
||||||
|
cancelledAt: null,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildApproval(overrides: Partial<PromptContext["pendingApprovals"][number]> = {}): PromptContext["pendingApprovals"][number] {
|
||||||
|
const now = new Date().toISOString();
|
||||||
|
return {
|
||||||
|
id: "approval-1",
|
||||||
|
companyId: "company-1",
|
||||||
|
relatedTaskId: null,
|
||||||
|
relatedAgentId: null,
|
||||||
|
requestedByAgentId: "agent-1",
|
||||||
|
type: "approve_ceo_strategy",
|
||||||
|
payloadSummary: "Review the volatile org gate.",
|
||||||
|
impactSummary: "Board decision required.",
|
||||||
|
payloadJson: null,
|
||||||
|
decisionNote: "",
|
||||||
|
state: "pending",
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
describe("buildSystemPrompt leadership classification", () => {
|
describe("buildSystemPrompt leadership classification", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
@@ -112,6 +160,84 @@ describe("buildSystemPrompt leadership classification", () => {
|
|||||||
expect(second).toBe(first);
|
expect(second).toBe(first);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps run, locale, and task context out of the stable system prompt", () => {
|
||||||
|
const ctx = buildCtx({
|
||||||
|
runId: "run-volatile",
|
||||||
|
locale: "zh",
|
||||||
|
task: buildTask(),
|
||||||
|
wakeReason: "assignment",
|
||||||
|
});
|
||||||
|
|
||||||
|
const stablePrompt = buildSystemPrompt(ctx);
|
||||||
|
const fullPrompt = buildTaskPrompt(ctx);
|
||||||
|
|
||||||
|
expect(stablePrompt).not.toContain("run-volatile");
|
||||||
|
expect(stablePrompt).not.toContain("Ship volatile task");
|
||||||
|
expect(stablePrompt).not.toContain("Respond to the user in Chinese.");
|
||||||
|
expect(stablePrompt).not.toContain("{{runId}}");
|
||||||
|
expect(stablePrompt).toContain("$AGENT_COMPANY_RUN_ID");
|
||||||
|
expect(fullPrompt).toContain("Current Run ID: run-volatile");
|
||||||
|
expect(fullPrompt).toContain("Ship volatile task");
|
||||||
|
expect(fullPrompt).toContain("Respond to the user in Chinese.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps the stable prefix identical across volatile run changes", () => {
|
||||||
|
const firstCtx = buildCtx({
|
||||||
|
runId: "run-a",
|
||||||
|
locale: "en",
|
||||||
|
task: buildTask({ id: "task-a", title: "First volatile task" }),
|
||||||
|
wakeReason: "timer",
|
||||||
|
});
|
||||||
|
const secondCtx = buildCtx({
|
||||||
|
runId: "run-b",
|
||||||
|
locale: "zh",
|
||||||
|
task: buildTask({ id: "task-b", title: "Second volatile task" }),
|
||||||
|
wakeReason: "assignment",
|
||||||
|
});
|
||||||
|
|
||||||
|
const firstStable = buildSystemPrompt(firstCtx);
|
||||||
|
const secondStable = buildSystemPrompt(secondCtx);
|
||||||
|
const secondFull = buildTaskPrompt(secondCtx);
|
||||||
|
|
||||||
|
expect(secondStable).toBe(firstStable);
|
||||||
|
expect(secondFull.slice(0, secondStable.length)).toBe(secondStable);
|
||||||
|
expect(secondFull.slice(secondStable.length)).toContain("Second volatile task");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps approval gates and workload counts out of the stable system prompt", () => {
|
||||||
|
const baseAgent = buildCtx().agent;
|
||||||
|
const report = {
|
||||||
|
...baseAgent,
|
||||||
|
id: "report-1",
|
||||||
|
name: "Engineer",
|
||||||
|
role: "Engineer",
|
||||||
|
title: "Staff Engineer",
|
||||||
|
reportsTo: baseAgent.id,
|
||||||
|
};
|
||||||
|
const stableBase = buildCtx({
|
||||||
|
chainOfCommand: [],
|
||||||
|
directReports: [report],
|
||||||
|
allAgents: [baseAgent, report],
|
||||||
|
allTasks: [buildTask({ id: "report-task", assigneeAgentId: report.id, status: "todo" })],
|
||||||
|
pendingApprovals: [],
|
||||||
|
});
|
||||||
|
const volatileChanged = buildCtx({
|
||||||
|
chainOfCommand: [],
|
||||||
|
directReports: [report],
|
||||||
|
allAgents: [baseAgent, report],
|
||||||
|
allTasks: [buildTask({ id: "report-task", assigneeAgentId: report.id, status: "blocked" })],
|
||||||
|
pendingApprovals: [buildApproval()],
|
||||||
|
});
|
||||||
|
|
||||||
|
const stablePrompt = buildSystemPrompt(stableBase);
|
||||||
|
const changedStablePrompt = buildSystemPrompt(volatileChanged);
|
||||||
|
const changedFullPrompt = buildTaskPrompt(volatileChanged);
|
||||||
|
|
||||||
|
expect(changedStablePrompt).toBe(stablePrompt);
|
||||||
|
expect(changedFullPrompt).toContain("Pending Approvals");
|
||||||
|
expect(changedFullPrompt).toContain("1 blocked");
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps volatile task context after the cacheable system prefix", () => {
|
it("keeps volatile task context after the cacheable system prefix", () => {
|
||||||
const ctx = buildCtx({ wakeReason: "timer" });
|
const ctx = buildCtx({ wakeReason: "timer" });
|
||||||
const systemPrompt = buildSystemPrompt(ctx);
|
const systemPrompt = buildSystemPrompt(ctx);
|
||||||
|
|||||||
Reference in new issue
Block a user