Skip to content

Commit aaae8b9

Browse files
committed
feat: add custom system prompt functionality to agent system prompt
1 parent a17524a commit aaae8b9

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

agent/systemPrompt.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ export const DEFAULT_AGENT_SYSTEM_PROMPT = [
3535
"If the confirmed plan has multiple steps, you may execute the whole confirmed plan without asking again between those steps.",
3636
"If the plan changes, expands, or you want to do anything beyond the confirmed plan, ask for confirmation again.",
3737
"Do not reuse an old confirmation for a new mutation plan.",
38-
39-
4038
].join(" ");
4139

40+
export function appendCustomSystemPrompt(
41+
systemPrompt: string,
42+
customSystemPrompt?: string,
43+
) {
44+
const normalizedCustomSystemPrompt = customSystemPrompt?.trim();
45+
46+
if (!normalizedCustomSystemPrompt) {
47+
return systemPrompt;
48+
}
49+
50+
return `${systemPrompt}\n\n${normalizedCustomSystemPrompt}`;
51+
}
52+
4253
function formatResources(resources: AdminForthResource[]) {
4354
return resources
4455
.map((resource) => `- resourceId: ${resource.resourceId}\n label: ${resource.label}`)

index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from './apiBasedTools.js';
1717
import type { ApiBasedTool } from './apiBasedTools.js';
1818
import {
19+
appendCustomSystemPrompt,
1920
buildAgentSystemPrompt,
2021
DEFAULT_AGENT_SYSTEM_PROMPT,
2122
} from "./agent/systemPrompt.js";
@@ -67,7 +68,7 @@ function assertRequiredApiTool(
6768
export default class AdminForthAgentPlugin extends AdminForthPlugin {
6869
options: PluginOptions;
6970
apiBasedTools: Record<string, ApiBasedTool> = {};
70-
agentSystemPromptPromise = Promise.resolve(DEFAULT_AGENT_SYSTEM_PROMPT);
71+
agentSystemPromptPromise: Promise<string>;
7172

7273
private async createNewTurn(sessionId: string, prompt: string, response?: string) {
7374
const turnId = randomUUID();
@@ -109,6 +110,9 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
109110
constructor(options: PluginOptions) {
110111
super(options, import.meta.url);
111112
this.options = options;
113+
this.agentSystemPromptPromise = Promise.resolve(
114+
appendCustomSystemPrompt(DEFAULT_AGENT_SYSTEM_PROMPT, this.options.systemPrompt),
115+
);
112116
this.shouldHaveSingleInstancePerWholeApp = () => false;
113117
}
114118

@@ -139,7 +143,8 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
139143
assertRequiredApiTool(this.apiBasedTools, toolName);
140144
}
141145
assertRequiredApiTool(this.apiBasedTools, "update_record");
142-
this.agentSystemPromptPromise = buildAgentSystemPrompt(adminforth);
146+
this.agentSystemPromptPromise = buildAgentSystemPrompt(adminforth)
147+
.then((systemPrompt) => appendCustomSystemPrompt(systemPrompt, this.options.systemPrompt));
143148
}
144149

145150
instanceUniqueRepresentation(pluginOptions: any) : string {

types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export interface PluginOptions extends PluginsCommonOptions {
3636
*/
3737
maxTokens?: number;
3838

39+
/**
40+
* Optional custom system prompt appended to the built-in agent system prompt.
41+
*/
42+
systemPrompt?: string;
43+
3944
/**
4045
* Response generation level.
4146
* Default is low

0 commit comments

Comments
 (0)