Q1: keep other work's chat mentions out of task prompts
Every mention already wakes the agent through its own chat-wake task, so ordinary tasks no longer inject the org-wide mention inbox. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b07eedbaa7
commit
77505aab8d
3 files changed
+72
-37
No files matched your search
@@ -15,7 +15,6 @@ import {
|
|||||||
buildAgentInstructions,
|
buildAgentInstructions,
|
||||||
buildTaskPrompt,
|
buildTaskPrompt,
|
||||||
type ChatContextBlock,
|
type ChatContextBlock,
|
||||||
type InboxContextBlock,
|
|
||||||
type GoalRow,
|
type GoalRow,
|
||||||
type ProjectRow,
|
type ProjectRow,
|
||||||
type SkillRuntimeSnapshotRow,
|
type SkillRuntimeSnapshotRow,
|
||||||
@@ -142,7 +141,6 @@ export class TaskExecutionService {
|
|||||||
workspace: workspace ? { id: workspace.id, localPath: workspace.local_path, writeAccess: task.requires_filesystem === 1 } : null,
|
workspace: workspace ? { id: workspace.id, localPath: workspace.local_path, writeAccess: task.requires_filesystem === 1 } : null,
|
||||||
};
|
};
|
||||||
const chatContext = this.loadChatContext(orgId, isolation);
|
const chatContext = this.loadChatContext(orgId, isolation);
|
||||||
const inboxContext = chatContext ? null : this.loadInboxContext(orgId, agent.id);
|
|
||||||
// The CEO is the c_suite role — the same predicate the grant system
|
// The CEO is the c_suite role — the same predicate the grant system
|
||||||
// enforces — not "has no manager", which any board hire can match.
|
// enforces — not "has no manager", which any board hire can match.
|
||||||
const isCeo = agent.role_level === "c_suite";
|
const isCeo = agent.role_level === "c_suite";
|
||||||
@@ -179,7 +177,6 @@ export class TaskExecutionService {
|
|||||||
hasReports,
|
hasReports,
|
||||||
managerName: this.agentName(orgId, agent.manager_agent_id),
|
managerName: this.agentName(orgId, agent.manager_agent_id),
|
||||||
chatContext,
|
chatContext,
|
||||||
inboxContext,
|
|
||||||
priorCompletedRuns: this.completedRunCount(task.id, runId),
|
priorCompletedRuns: this.completedRunCount(task.id, runId),
|
||||||
}),
|
}),
|
||||||
toolContext,
|
toolContext,
|
||||||
@@ -555,26 +552,6 @@ export class TaskExecutionService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadInboxContext(orgId: string, agentId: string): InboxContextBlock | null {
|
|
||||||
const messages = this.db.prepare(`
|
|
||||||
select m.body_md,
|
|
||||||
coalesce(a.name, e.display_name, m.sender_type) as sender_name,
|
|
||||||
s.name as channel_name
|
|
||||||
from chat_mentions cm
|
|
||||||
join chat_messages m on m.id = cm.message_id
|
|
||||||
join chat_spaces s on s.id = m.space_id
|
|
||||||
left join agents a on a.id = m.sender_id and m.sender_type = 'agent'
|
|
||||||
left join employees e on e.id = m.sender_id and m.sender_type = 'employee'
|
|
||||||
where cm.target_type = 'agent' and cm.target_id = ? and m.org_id = ? and m.deleted_at is null
|
|
||||||
order by m.created_at desc
|
|
||||||
limit 10
|
|
||||||
`).all(agentId, orgId) as Array<{ body_md: string; sender_name: string; channel_name: string }>;
|
|
||||||
if (messages.length === 0) return null;
|
|
||||||
return {
|
|
||||||
transcript: messages.reverse().map((m) => `[${m.sender_name} in #${m.channel_name}]: ${m.body_md}`).join("\n"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private completedRunCount(taskId: string, excludingRunId: string): number {
|
private completedRunCount(taskId: string, excludingRunId: string): number {
|
||||||
const row = this.db.prepare("select count(*) as n from task_runs where task_id = ? and state = 'completed' and id <> ?")
|
const row = this.db.prepare("select count(*) as n from task_runs where task_id = ? and state = 'completed' and id <> ?")
|
||||||
.get(taskId, excludingRunId) as { n: number };
|
.get(taskId, excludingRunId) as { n: number };
|
||||||
|
|||||||
@@ -150,10 +150,6 @@ function roleVoice(input: AgentInstructionContext): string {
|
|||||||
return "You own your craft. Ask the question early instead of guessing, do the work properly, and when you are stuck for more than a few minutes say so in the thread instead of spinning in place.";
|
return "You own your craft. Ask the question early instead of guessing, do the work properly, and when you are stuck for more than a few minutes say so in the thread instead of spinning in place.";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InboxContextBlock {
|
|
||||||
transcript: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildTaskPrompt(input: {
|
export function buildTaskPrompt(input: {
|
||||||
task: TaskExecutionTaskRow;
|
task: TaskExecutionTaskRow;
|
||||||
agent: TaskExecutionAgentRow;
|
agent: TaskExecutionAgentRow;
|
||||||
@@ -167,7 +163,6 @@ export function buildTaskPrompt(input: {
|
|||||||
hasReports: boolean;
|
hasReports: boolean;
|
||||||
managerName: string | null;
|
managerName: string | null;
|
||||||
chatContext: ChatContextBlock | null;
|
chatContext: ChatContextBlock | null;
|
||||||
inboxContext: InboxContextBlock | null;
|
|
||||||
/** Completed runs this task already spent without reaching done. */
|
/** Completed runs this task already spent without reaching done. */
|
||||||
priorCompletedRuns: number;
|
priorCompletedRuns: number;
|
||||||
}): string {
|
}): string {
|
||||||
@@ -220,15 +215,6 @@ export function buildTaskPrompt(input: {
|
|||||||
);
|
);
|
||||||
return lines.join("\n");
|
return lines.join("\n");
|
||||||
}
|
}
|
||||||
if (input.inboxContext) {
|
|
||||||
lines.push(
|
|
||||||
"",
|
|
||||||
"Recent messages that mention you:",
|
|
||||||
input.inboxContext.transcript,
|
|
||||||
"",
|
|
||||||
"Respond to anyone above who needs your input before starting the task.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (input.task.requires_filesystem === 1 && input.workspace) {
|
if (input.task.requires_filesystem === 1 && input.workspace) {
|
||||||
lines.push(
|
lines.push(
|
||||||
"",
|
"",
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { randomUUID } from "node:crypto";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
import { DatabaseConnection } from "../../src/main/database/connection";
|
||||||
|
import { OnboardingService } from "../../src/main/services/onboarding-service";
|
||||||
|
import { ProviderService } from "../../src/main/services/provider-service";
|
||||||
|
import { providerAdapters } from "../../src/main/services/provider-adapters";
|
||||||
|
import { TaskExecutionService } from "../../src/main/services/task-execution-service";
|
||||||
|
import { claimNextQueuedRun } from "../../src/main/app/task-queue-worker";
|
||||||
|
import { canonicalMentionHandle } from "../../src/shared/mention-handles";
|
||||||
|
import type { AgentTurnResult, ProviderToolTurnInput, ToolCall } from "../../src/main/services/provider-tool-turn";
|
||||||
|
|
||||||
|
const testVault = {
|
||||||
|
encryptSecret: (secret: string) => Buffer.from(secret, "utf8"),
|
||||||
|
decryptSecret: (ciphertext: Buffer) => ciphertext.toString("utf8"),
|
||||||
|
};
|
||||||
|
|
||||||
|
const CHANNEL_NOTE = "unrelated: rotate the staging certificates tonight";
|
||||||
|
|
||||||
|
function call(name: string, args: Record<string, unknown>): ToolCall {
|
||||||
|
return { id: `call_${randomUUID()}`, name, arguments: args };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("task prompt scope", () => {
|
||||||
|
test("an ordinary task prompt carries no chat mentions from other work", async () => {
|
||||||
|
const handle = canonicalMentionHandle("Dana Lee");
|
||||||
|
const danaPrompts: string[] = [];
|
||||||
|
let ceo = 0;
|
||||||
|
const ceoScript = [
|
||||||
|
{ text: "Staffing.", toolCalls: [call("hire_agent", { name: "Dana Lee", role: "Engineer", department: "Engineering" })] },
|
||||||
|
{ text: "Delegating.", toolCalls: [
|
||||||
|
call("create_task", { title: "Build the booking API", description: "Ship the booking API.", assignee_agent_name: "Dana Lee" }),
|
||||||
|
call("send_message", { channel: "engineering", body: `@${handle} ${CHANNEL_NOTE}` }),
|
||||||
|
] },
|
||||||
|
{ text: "Done.", toolCalls: [] },
|
||||||
|
];
|
||||||
|
const turn = async (input: ProviderToolTurnInput): Promise<AgentTurnResult> => {
|
||||||
|
if ((input.instructions ?? "").includes("Dana Lee")) {
|
||||||
|
const first = input.messages.find((message) => message.role === "user");
|
||||||
|
if (first && first.role === "user") danaPrompts.push(first.text);
|
||||||
|
return { text: "done", toolCalls: [], rawResponseJson: "{}" };
|
||||||
|
}
|
||||||
|
const step = ceoScript[ceo] ?? { text: "done", toolCalls: [] };
|
||||||
|
ceo += 1;
|
||||||
|
return { text: step.text, toolCalls: step.toolCalls, rawResponseJson: "{}" };
|
||||||
|
};
|
||||||
|
const connection = new DatabaseConnection(join(tmpdir(), `ac-scope-${randomUUID()}.db`));
|
||||||
|
const providers = new ProviderService(connection.db, providerAdapters, testVault, undefined, turn);
|
||||||
|
const onboarding = new OnboardingService({ db: connection.db, saveProviderCredential: (input) => providers.saveCredential(input) });
|
||||||
|
const execution = new TaskExecutionService(connection.db, providers);
|
||||||
|
let orgId = "";
|
||||||
|
connection.transaction(() => {
|
||||||
|
orgId = onboarding.bootstrap({
|
||||||
|
companyName: "OrbitOps AI", companyDescription: "Ops.", employeeName: "Yang", workspacePath: "",
|
||||||
|
executionMode: "ai_ceo", autoApproveHires: true, reviewDeliverables: false,
|
||||||
|
goalTitle: "Stand up a service business.", goalDescription: "Win customers.",
|
||||||
|
providerKey: "openai", providerSecret: "sk-test-key", providerModel: "gpt-5.4",
|
||||||
|
}).orgId;
|
||||||
|
});
|
||||||
|
const kickoff = claimNextQueuedRun(connection);
|
||||||
|
await execution.executeRun(kickoff!.org_id, kickoff!.id);
|
||||||
|
|
||||||
|
const task = connection.db.prepare("select id from tasks where org_id = ? and title = 'Build the booking API'").get(orgId) as { id: string };
|
||||||
|
await execution.runTask({ orgId, taskId: task.id });
|
||||||
|
|
||||||
|
expect(danaPrompts).toHaveLength(1);
|
||||||
|
expect(danaPrompts[0]).toContain("Build the booking API");
|
||||||
|
expect(danaPrompts[0]).not.toContain(CHANNEL_NOTE);
|
||||||
|
connection.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user