Skip to content

Commit 4985ad1

Browse files
MaxLinCodeclaude
andcommitted
feat: include entityContext in interpretWriteTurn prompt payload
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8f151eb commit 4985ad1

2 files changed

Lines changed: 83 additions & 7 deletions

File tree

packages/integrations/src/index.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from "@atlas/core";
55
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
66

7+
import { interpretWriteTurnSystemPrompt } from "./prompts/interpret-write-turn";
78
import {
89
buildGoogleCalendarOAuthUrl,
910
createGoogleCalendarAdapter,
@@ -1153,4 +1154,67 @@ describe("integrations", () => {
11531154
"Telegram editMessageText failed with status 400: Bad Request: message can't be edited.",
11541155
);
11551156
});
1157+
1158+
it("includes entityContext in the write interpretation prompt payload and prompt instructions", async () => {
1159+
const parse = vi.fn(async () => ({
1160+
output_parsed: {
1161+
operationKind: "edit",
1162+
actionDomain: "task",
1163+
targetRef: {
1164+
entityId: "task-1",
1165+
description: null,
1166+
entityKind: null,
1167+
},
1168+
taskName: null,
1169+
fields: {
1170+
scheduleFields: null,
1171+
taskFields: null,
1172+
},
1173+
confidence: {},
1174+
unresolvedFields: [],
1175+
},
1176+
}));
1177+
1178+
await interpretWriteTurnWithResponses(
1179+
{
1180+
currentTurnText: "Move gym to 5",
1181+
turnType: "edit_request",
1182+
entityContext:
1183+
'Known entities:\n- "Gym" (task, scheduled) [id: task-1]',
1184+
},
1185+
{
1186+
responses: {
1187+
parse,
1188+
},
1189+
},
1190+
);
1191+
1192+
expect(parse).toHaveBeenCalledWith(
1193+
expect.objectContaining({
1194+
input: expect.arrayContaining([
1195+
expect.objectContaining({
1196+
role: "system",
1197+
content: expect.arrayContaining([
1198+
expect.objectContaining({
1199+
text: expect.stringContaining(
1200+
"Resolve entity references only against the provided entityContext.",
1201+
),
1202+
}),
1203+
]),
1204+
}),
1205+
expect.objectContaining({
1206+
role: "user",
1207+
content: expect.arrayContaining([
1208+
expect.objectContaining({
1209+
text: expect.stringContaining("Entity context:\nKnown entities:"),
1210+
}),
1211+
]),
1212+
}),
1213+
]),
1214+
}),
1215+
);
1216+
expect(interpretWriteTurnSystemPrompt).toContain(
1217+
"Never invent an entity ID",
1218+
);
1219+
});
11561220
});

packages/integrations/src/openai.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export async function interpretWriteTurnWithResponses(
330330
content: [
331331
{
332332
type: "input_text",
333-
text: JSON.stringify(buildWriteInterpretationPromptContext(context)),
333+
text: buildWriteInterpretationPromptContext(context),
334334
},
335335
],
336336
},
@@ -413,12 +413,24 @@ function buildSlotExtractorPromptContext(context: SlotExtractorInput) {
413413
function buildWriteInterpretationPromptContext(
414414
context: WriteInterpretationInput,
415415
) {
416-
return {
417-
currentTurnText: context.currentTurnText,
418-
turnType: context.turnType,
419-
priorPendingWriteOperation: context.priorPendingWriteOperation ?? null,
420-
conversationContext: context.conversationContext ?? null,
421-
};
416+
return [
417+
"Current turn text:",
418+
context.currentTurnText,
419+
"",
420+
"Turn type:",
421+
context.turnType,
422+
"",
423+
"Prior pending write operation:",
424+
context.priorPendingWriteOperation
425+
? JSON.stringify(context.priorPendingWriteOperation, null, 2)
426+
: "None",
427+
"",
428+
"Conversation context:",
429+
context.conversationContext ?? "None",
430+
"",
431+
"Entity context:",
432+
context.entityContext ?? "None",
433+
].join("\n");
422434
}
423435

424436
function buildTurnRoutingPromptContext(context: TurnRoutingInput) {

0 commit comments

Comments
 (0)