forked from earendil-works/pi
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path03-custom-prompt.ts
More file actions
75 lines (65 loc) · 1.88 KB
/
Copy path03-custom-prompt.ts
File metadata and controls
75 lines (65 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Custom System Prompt
*
* Shows how to replace or modify the default system prompt.
*/
import {
createAgentSession,
DefaultResourceLoader,
getAgentDir,
SessionManager,
} from "@earendil-works/pi-coding-agent";
const cwd = process.cwd();
const agentDir = getAgentDir();
// Option 1: Replace prompt entirely
const loader1 = new DefaultResourceLoader({
cwd,
agentDir,
systemPromptOverride: () => `You are a helpful assistant that speaks like a pirate.
Always end responses with "Arrr!"`,
// Needed to avoid DefaultResourceLoader appending APPEND_SYSTEM.md from ~/.pi/agent or <cwd>/.pi.
appendSystemPromptOverride: () => [],
});
await loader1.reload();
const { session: session1 } = await createAgentSession({
resourceLoader: loader1,
sessionManager: SessionManager.inMemory(),
});
try {
session1.subscribe((event) => {
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
process.stdout.write(event.assistantMessageEvent.delta);
}
});
console.log("=== Replace prompt ===");
await session1.prompt("What is 2 + 2?");
console.log("\n");
} finally {
session1.dispose();
}
// Option 2: Append instructions to the default prompt
const loader2 = new DefaultResourceLoader({
cwd,
agentDir,
appendSystemPromptOverride: (base) => [
...base,
"## Additional Instructions\n- Always be concise\n- Use bullet points when listing things",
],
});
await loader2.reload();
const { session: session2 } = await createAgentSession({
resourceLoader: loader2,
sessionManager: SessionManager.inMemory(),
});
try {
session2.subscribe((event) => {
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
process.stdout.write(event.assistantMessageEvent.delta);
}
});
console.log("=== Modify prompt ===");
await session2.prompt("List 3 benefits of TypeScript.");
console.log();
} finally {
session2.dispose();
}