feat: support user system prompt (#147)

* feat: add support for userSystemPrompt

* feat: udpate chat-cli to support user system prompt
This commit is contained in:
Nikhil
2026-01-02 09:07:13 -08:00
committed by GitHub
parent 47b9c1894d
commit ee5de61967
6 changed files with 28 additions and 9 deletions

View File

@@ -169,4 +169,9 @@ export function getSystemPrompt(): string {
return systemPrompt
}
export function buildSystemPrompt(userSystemPrompt?: string): string {
if (!userSystemPrompt) return systemPrompt
return `${systemPrompt}\n\n---\n\n## User Preferences:\n\n${userSystemPrompt}`
}
export { systemPrompt }

View File

@@ -24,7 +24,7 @@ import { Sentry } from '../../common/sentry/instrument.js'
import type { BrowserContext } from '../../http/types.js'
import { AgentExecutionError } from '../errors.js'
import { KlavisClient } from '../klavis/index.js'
import { getSystemPrompt } from './GeminiAgent.prompt.js'
import { buildSystemPrompt } from './GeminiAgent.prompt.js'
import {
AIProvider,
VercelAIContentGenerator,
@@ -198,7 +198,9 @@ export class GeminiAgent {
).contentGenerator = contentGenerator
const client = geminiConfig.getGeminiClient()
client.getChat().setSystemInstruction(getSystemPrompt())
client
.getChat()
.setSystemInstruction(buildSystemPrompt(resolvedConfig.userSystemPrompt))
await client.setTools()
// Disable chat recording to prevent disk writes

View File

@@ -17,6 +17,7 @@ export const AgentConfigSchema = VercelAIConfigSchema.extend({
browserosId: z.string().optional(),
enabledMcpServers: z.array(z.string()).optional(),
customMcpServers: z.array(CustomMcpServerSchema).optional(),
userSystemPrompt: z.string().optional(),
})
export type AgentConfig = z.infer<typeof AgentConfigSchema>

View File

@@ -112,6 +112,7 @@ export function createChatRoutes(deps: ChatRouteDeps) {
browserosId,
enabledMcpServers: request.browserContext?.enabledMcpServers,
customMcpServers: request.browserContext?.customMcpServers,
userSystemPrompt: request.userSystemPrompt,
})
const sseStream = {

View File

@@ -43,6 +43,7 @@ export const ChatRequestSchema = VercelAIConfigSchema.extend({
message: z.string().min(1, 'Message cannot be empty'),
contextWindowSize: z.number().optional(),
browserContext: BrowserContextSchema.optional(),
userSystemPrompt: z.string().optional(),
})
export type ChatRequest = z.infer<typeof ChatRequestSchema>

View File

@@ -7,9 +7,10 @@
* bun --env-file=.env.dev tests/agent-cli.ts --provider=openai --model=gpt-4o "your message here"
*
* Options:
* --provider AI provider (default: google)
* --model Model name (default: gemini-2.5-flash)
* --provider AI provider (default: browseros)
* --model Model name (default: default)
* --port Server port (default: $BROWSEROS_SERVER_PORT or 9100)
* --system-prompt Custom system prompt to append
* --show-full-output Show full tool output (default: truncated to 50 chars)
*/
@@ -19,6 +20,7 @@ interface ChatRequest {
provider: string
model: string
apiKey?: string
userSystemPrompt?: string
}
function parseArgs(): {
@@ -26,13 +28,15 @@ function parseArgs(): {
provider: string
model: string
port: string
userSystemPrompt?: string
showFullOutput: boolean
} {
const args = process.argv.slice(2)
let provider = 'google'
let model = 'gemini-2.5-flash'
let provider = 'browseros'
let model = 'default'
let port = process.env.BROWSEROS_SERVER_PORT || '9100'
let showFullOutput = false
let userSystemPrompt: string | undefined
let message = ''
for (const arg of args) {
@@ -42,6 +46,8 @@ function parseArgs(): {
model = arg.split('=')[1]
} else if (arg.startsWith('--port=')) {
port = arg.split('=')[1]
} else if (arg.startsWith('--system-prompt=')) {
userSystemPrompt = arg.split('=').slice(1).join('=')
} else if (arg === '--show-full-output') {
showFullOutput = true
} else if (!arg.startsWith('--')) {
@@ -50,22 +56,23 @@ function parseArgs(): {
}
if (!message) {
console.error('Usage: bun tests/test-agent-cli.ts [options] "your message"')
console.error('Usage: bun scripts/dev/chat-cli.ts [options] "your message"')
console.error('Options:')
console.error(
' --provider=<provider> AI provider (anthropic, openai, google, etc.)',
)
console.error(' --model=<model> Model name')
console.error(
' --port=<port> Server port (default: $AGENT_PORT or 9200)',
' --port=<port> Server port (default: $BROWSEROS_SERVER_PORT or 9100)',
)
console.error(' --system-prompt=<prompt> Custom system prompt to append')
console.error(
' --show-full-output Show full tool output (default: truncated)',
)
process.exit(1)
}
return { message, provider, model, port, showFullOutput }
return { message, provider, model, port, userSystemPrompt, showFullOutput }
}
function truncateOutput(obj: unknown, maxLen = 50): unknown {
@@ -90,6 +97,7 @@ async function chat(config: {
provider: string
model: string
port: string
userSystemPrompt?: string
showFullOutput: boolean
}) {
const conversationId = crypto.randomUUID()
@@ -99,6 +107,7 @@ async function chat(config: {
message: config.message,
provider: config.provider,
model: config.model,
userSystemPrompt: config.userSystemPrompt,
}
console.log('\n--- Request ---')