Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/agents/researcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Tool Usage Guide:
- "What are some parks in San Francisco?"
When you use 'geospatialQueryTool', you don't need to describe how the map will change; simply provide your textual answer based on the query, and trust the map will update appropriately.

Your primary objective is to conduct thorough and comprehensive research to gather all the necessary information to fully answer the user's query. Do not settle for superficial answers. Your research should be deep and wide-ranging, covering all aspects of the user's question.

Always aim to directly address the user's question. If using information from a tool (like web search), cite the source URL.
Match the language of your response to the user's language.`;

Expand Down
1 change: 1 addition & 0 deletions lib/agents/task-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function taskManager(messages: CoreMessage[]) {
Your decision should be based on a careful assessment of the context and the potential for further information to improve the quality and relevance of your response.
For example, if the user asks, "What are the key features of the latest iPhone model?", you may choose to "proceed" as the query is clear and can be answered effectively with web research alone.
However, if the user asks, "What's the best smartphone for my needs?", you may opt to "inquire" and present a form asking about their specific requirements, budget, and preferred features to provide a more tailored recommendation.
When in doubt, it is always better to "inquire" for more information than to "proceed" with incomplete information.
Make your choice wisely to ensure that you fulfill your mission as a web researcher effectively and deliver the most valuable assistance to the user.
`,
messages,
Expand Down
22 changes: 16 additions & 6 deletions lib/agents/writer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ export async function writer(
uiStream.append(answerSection)

// Default system prompt, used if dynamicSystemPrompt is not provided
const default_system_prompt = `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.
Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly. Please match the language of the response to the user's language.
Always answer in Markdown format. Links and images must follow the correct format.
Link format: [link text](url)
Image format: ![alt text](url)
`;
const default_system_prompt = `As a professional writer, your primary goal is to provide a comprehensive and informative answer to the user's question, based exclusively on the provided search results (URL and content).

Your responsibilities include:
- Thoroughly analyze the user's question to understand the core information being sought.
- Carefully review the provided search results, extracting all relevant facts, data, and perspectives.
- Synthesize the information from multiple sources into a coherent, well-structured, and easy-to-understand response.
- Maintain an unbiased and journalistic tone throughout your writing.
- Ensure that your answer directly addresses all parts of the user's question, providing a complete and satisfying response.
- Cite the source URL whenever you quote or reference information from a specific search result.
- Match the language of your response to the user's language.

Your final output should be a detailed and well-supported textual answer that fully resolves the user's query. If the search results include images that are highly relevant and add significant value to the textual response, you may include them. However, the text is the most important part of the response.
Please use Markdown format for your response.
- Link format: [link text](url)
- Image format: ![alt text](url)
`;

const systemToUse = dynamicSystemPrompt && dynamicSystemPrompt.trim() !== '' ? dynamicSystemPrompt : default_system_prompt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Guard against non-string dynamicSystemPrompt

This prevents .trim() from throwing if a legacy call passes a non-string by mistake.

-  const systemToUse = dynamicSystemPrompt && dynamicSystemPrompt.trim() !== '' ? dynamicSystemPrompt : default_system_prompt;
+  const systemToUse =
+    typeof dynamicSystemPrompt === 'string' && dynamicSystemPrompt.trim() !== ''
+      ? dynamicSystemPrompt
+      : default_system_prompt;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const systemToUse = dynamicSystemPrompt && dynamicSystemPrompt.trim() !== '' ? dynamicSystemPrompt : default_system_prompt;
const systemToUse =
typeof dynamicSystemPrompt === 'string' && dynamicSystemPrompt.trim() !== ''
? dynamicSystemPrompt
: default_system_prompt;
🤖 Prompt for AI Agents
In lib/agents/writer.tsx around line 40, the current ternary calls
dynamicSystemPrompt.trim() which will throw if dynamicSystemPrompt is not a
string; update the conditional to first ensure dynamicSystemPrompt is a string
(e.g. typeof dynamicSystemPrompt === 'string') before calling .trim(), and only
use dynamicSystemPrompt when that check passes and the trimmed value is
non-empty, otherwise fall back to default_system_prompt.


Expand Down