-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy path03-custom-prompt.ts
More file actions
43 lines (36 loc) · 1.3 KB
/
03-custom-prompt.ts
File metadata and controls
43 lines (36 loc) · 1.3 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
/**
* Custom System Prompt
*
* Shows how to replace or modify the default system prompt.
*/
import { createAgentSession, SessionManager } from "@oh-my-pi/pi-coding-agent";
// Option 1: Replace prompt entirely
const { session: session1 } = await createAgentSession({
systemPrompt: `You are a helpful assistant that speaks like a pirate.
Always end responses with "Arrr!"`,
sessionManager: SessionManager.inMemory(),
});
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");
// Option 2: Modify default prompt (receives default, returns modified)
const { session: session2 } = await createAgentSession({
systemPrompt: defaultPrompt => `${defaultPrompt}
## Additional Instructions
- Always be concise
- Use bullet points when listing things`,
sessionManager: SessionManager.inMemory(),
});
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();