Skip to content

An AI-powered search engine with a generative UI

feat(prompt): add conditional system prompts based on search mode

Yoshiki Miura6f6156bf7ea5
diff --git a/lib/agents/manual-researcher.ts b/lib/agents/manual-researcher.ts
index 6dc2b0df..e8cef2e9 100644
--- a/lib/agents/manual-researcher.ts
+++ b/lib/agents/manual-researcher.ts
@@ -1,42 +1,62 @@
import { CoreMessage, smoothStream, streamText } from 'ai'
import { getModel } from '../utils/registry'
-const MANUAL_SYSTEM_PROMPT = `
+const BASE_SYSTEM_PROMPT = `
Instructions:
-You are a helpful AI assistant analyzing search results to provide accurate information.
+You are a helpful AI assistant providing accurate information.
+1. Provide comprehensive and detailed responses to user questions
+2. Use markdown to structure your responses with appropriate headings
+3. Acknowledge when you are uncertain about specific details
+4. Focus on maintaining high accuracy in your responses
+`
+
+const SEARCH_ENABLED_PROMPT = `
+${BASE_SYSTEM_PROMPT}
+
+When analyzing search results:
1. Analyze the provided search results carefully to answer the user's question
2. Always cite sources using the [number](url) format, matching the order of search results
3. If multiple sources are relevant, include all of them using comma-separated citations
4. Only use information that has a URL available for citation
-5. Provide comprehensive and detailed responses based on the search results
-6. Use markdown to structure your responses with appropriate headings
-7. If the search results don't contain relevant information, acknowledge this and provide a general response
+5. If the search results don't contain relevant information, acknowledge this and provide a general response
Citation Format:
[number](url)
+`
+
+const SEARCH_DISABLED_PROMPT = `
+${BASE_SYSTEM_PROMPT}
-Remember: Focus on the search results provided to you and maintain high accuracy in your responses.
+Important:
+1. Provide responses based on your general knowledge
+2. Be clear about any limitations in your knowledge
+3. Suggest when searching for additional information might be beneficial
`
interface ManualResearcherConfig {
messages: CoreMessage[]
model: string
+ isSearchEnabled?: boolean
}
type ManualResearcherReturn = Parameters<typeof streamText>[0]
export function manualResearcher({
messages,
- model
+ model,
+ isSearchEnabled = true
}: ManualResearcherConfig): ManualResearcherReturn {
try {
const currentDate = new Date().toLocaleString()
+ const systemPrompt = isSearchEnabled
+ ? SEARCH_ENABLED_PROMPT
+ : SEARCH_DISABLED_PROMPT
return {
model: getModel(model),
- system: `${MANUAL_SYSTEM_PROMPT}\nCurrent date and time: ${currentDate}`,
+ system: `${systemPrompt}\nCurrent date and time: ${currentDate}`,
messages,
temperature: 0.6,
topP: 1,
diff --git a/lib/streaming/create-manual-tool-stream.ts b/lib/streaming/create-manual-tool-stream.ts
index 83569072..28a0cd3d 100644
--- a/lib/streaming/create-manual-tool-stream.ts
+++ b/lib/streaming/create-manual-tool-stream.ts
@@ -33,7 +33,8 @@ export function createManualToolStreamResponse(config: BaseStreamConfig) {
const researcherConfig = manualResearcher({
messages: [...truncatedMessages, ...toolCallMessages],
- model
+ model,
+ isSearchEnabled: searchMode
})
const result = streamText({