Skip to content
Merged
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
41 changes: 30 additions & 11 deletions lib/agents/researcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,42 @@ export async function researcher(

const currentDate = new Date().toLocaleString()
// Default system prompt, used if dynamicSystemPrompt is not provided
const default_system_prompt = `As a comprehensive AI assistant, you can search the web, retrieve information from URLs, and understand geospatial queries to assist the user and display information on a map.
Current date and time: ${currentDate}.
const default_system_prompt = `As a comprehensive AI assistant, you can search the web, retrieve information from URLs except from maps -here use the Geospatial tools provided, and understand geospatial queries to assist the user and display information on a map.
Current date and time: ${currentDate}. When tools are not needed, provide direct, helpful answers based on your knowledge.Match the language of your response to the user's language.
Always aim to directly address the user's question. If using information from a tool (like web search), cite the source URL.

There are also some proconfigured example queires.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typographical errors.

Line 36 contains two typos: "proconfigured" should be "preconfigured" and "queires" should be "queries".

Apply this diff:

-There are also some proconfigured example queires.
+There are also some preconfigured example queries.
📝 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
There are also some proconfigured example queires.
There are also some preconfigured example queries.
🤖 Prompt for AI Agents
In lib/agents/researcher.tsx around line 36, fix the typos in the sentence:
replace "proconfigured" with "preconfigured" and "queires" with "queries" so the
line reads with correct spelling.

When asked the following respond accordingly:
'What is a planet computer?' answer with the following: '"A planet computer is a proprietary environment aware system that interoperates Climate forecasting, mapping and scheduling using cutting edge multi-agents to streamline automation and exploration on a planet'
‘What is QCX-Terra’ Respond with ‘QCX-Terra is a model garden of pixel level precision geospatial foundational models for efficient land prediction from satellite images’

Comment on lines +37 to +40
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider restructuring hardcoded example queries.

The hardcoded question-answer pairs for "planet computer" and "QCX-Terra" would be clearer as a structured list or lookup table rather than inline prose instructions.

Example:

Predefined Examples:
- "What is a planet computer?"  "A planet computer is a proprietary environment aware system..."
- "What is QCX-Terra?"  "QCX-Terra is a model garden of pixel level precision..."
🤖 Prompt for AI Agents
In lib/agents/researcher.tsx around lines 37-40, the hardcoded example Q/A prose
should be refactored into a structured lookup: create a typed constant (e.g.,
PREDEFINED_EXAMPLES: Record<string,string> or an array of {question,answer})
containing the two pairs ("What is a planet computer?" -> "A planet computer is
a proprietary environment aware system..." and "What is QCX-Terra?" ->
"QCX-Terra is a model garden of pixel level precision..."), replace the inline
prose with code that reads from that lookup when composing responses, and export
or scope the constant appropriately so tests and other modules can reuse it;
maintain original exact answer strings and remove duplicated quotes or smart
quotes.


Tool Usage Guide:

- For general web searches for factual information: Use the 'search' tool.
- For retrieving content from specific URLs provided by the user: Use the 'retrieve' tool. (Do not use this for URLs found in search results).
- **For any questions involving locations, places, addresses, geographical features, finding businesses or points of interest, distances between locations, or directions: You MUST use the 'geospatialQueryTool'. This tool will process the query, and relevant information will often be displayed or updated on the user's map automatically.**

- For any questions involving locations, places, addresses, geographical features, finding businesses or points of interest, distances between locations, or directions: You MUST use the 'geospatialQueryTool'. This tool will process the query, and relevant information will often be displayed or updated on the user's map automatically.**
Examples of queries for 'geospatialQueryTool':
- "Where is the Louvre Museum?"
- "Show me cafes near the current map center."
- "How far is it from New York City to Los Angeles?"
- "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.
Location Discovery
"Find coffee shops within walking distance of the Empire State Building"
"Show me gas stations along the route from Boston to New York"
"What restaurants are near Times Square?"
Navigation & Travel
"Get driving directions from LAX to Hollywood with current traffic"
"How long would it take to walk from Central Park to Times Square?"
"Calculate travel time from my hotel (Four Seasons) to JFK Airport by taxi during rush hour"
Visualization & Maps
"Create a map image showing the route from Golden Gate Bridge to Fisherman's Wharf with markers at both locations"
"Show me a satellite view of Manhattan with key landmarks marked"
"Generate a map highlighting all Starbucks locations within a mile of downtown Seattle"
Analysis & Planning
"Show me areas reachable within 30 minutes of downtown Portland by car"
"Calculate a travel time matrix between these 3 hotel locations (Marriott, Sheraton and Hilton) and the convention center in Denver"
"Find the optimal route visiting these 3 tourist attractions (Golden Gate, Musical Stairs and Fisherman's Wharf) in San Francisco"

When tools are not needed, provide direct, helpful answers based on your knowledge.
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.`;
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.
`;

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

Expand Down
18 changes: 13 additions & 5 deletions lib/agents/task-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ export async function taskManager(messages: CoreMessage[]) {
try {
const result = await generateObject({
model: getModel() as LanguageModel,
system: `As a professional web researcher, your primary objective is to fully comprehend the user's query, conduct thorough web searches to gather the necessary information, and provide an appropriate response.
system: `As a planet computer, your primary objective is to fully comprehend the user's query, conduct thorough web searches and use Geospatial tools to gather preview the necessary information, and provide an appropriate response.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix grammatical error.

The phrase "gather preview the necessary information" is malformed. It should be "gather or preview" or "gather and preview".

Apply this diff:

-system: `As a planet computer, your primary objective is to fully comprehend the user's query, conduct thorough web searches and use Geospatial tools to gather preview the necessary information, and provide an appropriate response.
+system: `As a planet computer, your primary objective is to fully comprehend the user's query, conduct thorough web searches and use Geospatial tools to gather or preview the necessary information, and provide an appropriate response.
📝 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
system: `As a planet computer, your primary objective is to fully comprehend the user's query, conduct thorough web searches and use Geospatial tools to gather preview the necessary information, and provide an appropriate response.
system: `As a planet computer, your primary objective is to fully comprehend the user's query, conduct thorough web searches and use Geospatial tools to gather or preview the necessary information, and provide an appropriate response.
🤖 Prompt for AI Agents
In lib/agents/task-manager.tsx around line 10, the system prompt contains a
malformed phrase "gather preview the necessary information"; replace that
fragment with a correct conjunction such as "gather or preview the necessary
information" (or "gather and preview the necessary information") so the sentence
reads grammatically correct and preserves the intended meaning.

To achieve this, you must first analyze the user's input and determine the optimal course of action. You have two options at your disposal:
"commitment_to_accuracy": "All analyses, decisions, and communications must be grounded in the most accurate available data. Prioritize verifiable information and clearly distinguish between observed facts, derived inferences, and predictive models.",
"data_driven_operations": "Base all operational procedures, exploration strategies, and automated tasks on empirical evidence and validated data inputs. Assumptions made due to incomplete data must be explicitly stated.",
"transparency_in_uncertainty": "When faced with ambiguity, incomplete data, or conflicting information, explicitly state the level of uncertainty. Quantify confidence where possible and clearly articulate potential impacts of this uncertainty on conclusions or actions.",
"avoidance_of_speculation": "Generate responses and take actions based on known information. Do not invent, fabricate, or present unsubstantiated claims as facts. If information is unavailable, state so clearly.",
"continuous_verification": "Wherever feasible, cross-verify information from multiple sources or sensors. Implement checks to ensure data integrity throughout processing and decision-making cycles."
1. "proceed": If the provided information is sufficient to address the query effectively, choose this option to proceed with the research and formulate a response.
2. "inquire": If you believe that additional information from the user would enhance your ability to provide a comprehensive response, select this option. You may present a form to the user, offering default selections or free-form input fields, to gather the required details.
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.
2. "inquire": If you believe that additional information from the user would enhance your ability to provide a comprehensive response, select this option. You may present a form to the user, offering default selections or free-form input fields, to gather the required details.if its a location based query clarify the following detailsBe specific about locations (use full addresses or landmark names)
Specify your preferred travel method (driving, walking, cycling)
Include time constraints when relevant ("during rush hour", "at 3 PM")
Ask for specific output formats when needed ("as a map image", "in JSON format")
Your decision should be based on a careful assessment of the context, location and the potential for further information to improve the quality and relevance of your response. If the query involves a location make sure to look through all the Geospatial tools available.
For example, if the user asks, "What are the latest news about the floods in India?", 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 warmest temperature in my area?", you may opt to "inquire" and present a form asking about their specific requirements, location, and preferred mertrics like Farenheit or Celsius.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typographical errors.

Line 24 contains two typos: "mertrics" should be "metrics" and "Farenheit" should be "Fahrenheit".

Apply this diff:

-However, if the user asks, "What's the warmest temperature in my area?", you may opt to "inquire" and present a form asking about their specific requirements, location, and preferred mertrics like Farenheit or Celsius.
+However, if the user asks, "What's the warmest temperature in my area?", you may opt to "inquire" and present a form asking about their specific requirements, location, and preferred metrics like Fahrenheit or Celsius.
📝 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
However, if the user asks, "What's the warmest temperature in my area?", you may opt to "inquire" and present a form asking about their specific requirements, location, and preferred mertrics like Farenheit or Celsius.
However, if the user asks, "What's the warmest temperature in my area?", you may opt to "inquire" and present a form asking about their specific requirements, location, and preferred metrics like Fahrenheit or Celsius.
🤖 Prompt for AI Agents
In lib/agents/task-manager.tsx around line 24, there's a sentence with two
typos: replace "mertrics" with "metrics" and "Farenheit" with "Fahrenheit";
update the text accordingly so the sentence reads "...preferred metrics like
Fahrenheit or Celsius."

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
108 changes: 88 additions & 20 deletions lib/agents/tools/geospatial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ async function getConnectedMcpClient(): Promise<McpClient | null> {
// Load config from file or fallback
let config;
try {
const mapboxMcpConfig = await import('QCX/mapbox_mcp_config.json');
config = { ...mapboxMcpConfig.default || mapboxMcpConfig, mapboxAccessToken };
console.log('[GeospatialTool] Config loaded successfully');
// Use static import for config
let mapboxMcpConfig;
try {
mapboxMcpConfig = require('../../../mapbox_mcp_config.json');
config = { ...mapboxMcpConfig, mapboxAccessToken };
console.log('[GeospatialTool] Config loaded successfully');
} catch (configError: any) {
throw configError;
}
Comment on lines +55 to +63
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 | 🟠 Major

Remove redundant nested try-catch block.

The inner try-catch (lines 57-63) immediately re-throws the caught error without any transformation or additional handling. This adds unnecessary nesting without providing value. The outer catch block (lines 64-68) already handles config loading failures with appropriate fallback logic.

Apply this diff to simplify the error handling:

-  // Load config from file or fallback
-  let config;
-  try {
-    // Use static import for config
-    let mapboxMcpConfig;
-    try {
-      mapboxMcpConfig = require('../../../mapbox_mcp_config.json');
-      config = { ...mapboxMcpConfig, mapboxAccessToken };
-      console.log('[GeospatialTool] Config loaded successfully');
-    } catch (configError: any) {
-      throw configError;
-    }
+  // Load config from file or fallback
+  let config;
+  try {
+    const mapboxMcpConfig = require('../../../mapbox_mcp_config.json');
+    config = { ...mapboxMcpConfig, mapboxAccessToken };
+    console.log('[GeospatialTool] Config loaded successfully');
   } catch (configError: any) {
     console.error('[GeospatialTool] Failed to load mapbox config:', configError.message);
     config = { mapboxAccessToken, version: '1.0.0', name: 'mapbox-mcp-server' };
📝 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
// Use static import for config
let mapboxMcpConfig;
try {
mapboxMcpConfig = require('../../../mapbox_mcp_config.json');
config = { ...mapboxMcpConfig, mapboxAccessToken };
console.log('[GeospatialTool] Config loaded successfully');
} catch (configError: any) {
throw configError;
}
// Load config from file or fallback
let config;
try {
const mapboxMcpConfig = require('../../../mapbox_mcp_config.json');
config = { ...mapboxMcpConfig, mapboxAccessToken };
console.log('[GeospatialTool] Config loaded successfully');
} catch (configError: any) {
console.error('[GeospatialTool] Failed to load mapbox config:', configError.message);
config = { mapboxAccessToken, version: '1.0.0', name: 'mapbox-mcp-server' };
}
🤖 Prompt for AI Agents
In lib/agents/tools/geospatial.tsx around lines 55 to 63, remove the redundant
inner try-catch that simply re-throws the caught error; instead perform the
require(...) and config assignment directly (letting the outer catch handle
failures). Ensure no behavior changes: keep the console.log on success and rely
on the existing outer catch block for fallback/error handling.

} catch (configError: any) {
console.error('[GeospatialTool] Failed to load mapbox config:', configError.message);
config = { mapboxAccessToken, version: '1.0.0', name: 'mapbox-mcp-server' };
Expand All @@ -63,7 +69,7 @@ async function getConnectedMcpClient(): Promise<McpClient | null> {

// Build Smithery URL
const smitheryUrlOptions = { config, apiKey, profileId };
const mcpServerBaseUrl = `https://server.smithery.ai/@ngoiyaeric/mapbox-mcp-server/mcp?api_key=${smitheryUrlOptions.apiKey}&profile=${smitheryUrlOptions.profileId}`;
const mcpServerBaseUrl = `https://server.smithery.ai/@Waldzell-Agentics/mcp-server/mcp?api_key=${smitheryUrlOptions.apiKey}&profile=${smitheryUrlOptions.profileId}`;
let serverUrlToUse;
try {
serverUrlToUse = createSmitheryUrl(mcpServerBaseUrl, smitheryUrlOptions);
Expand Down Expand Up @@ -142,13 +148,74 @@ async function closeClient(client: McpClient | null) {
* Main geospatial tool executor.
*/
export const geospatialTool = ({ uiStream }: { uiStream: ReturnType<typeof createStreamableUI> }) => ({
description: `Use this tool for location-based queries including:
- Finding specific places, addresses, or landmarks
- Getting coordinates for locations
- Distance calculations between places
- Direction queries
- Map-related requests
- Geographic information lookup`,
description: `Use this tool for location-based queries including:
There a plethora of tools inside this tool accessible on the mapbox mcp server where switch case into the tool of choice for that use case
If the Query is supposed to use multiple tools in a sequence you must access all the tools in the sequence and then provide a final answer based on the results of all the tools used.

Static image tool:

Generates static map images using the Mapbox static image API. Features include:

Custom map styles (streets, outdoors, satellite, etc.)
Adjustable image dimensions and zoom levels
Support for multiple markers with custom colors and labels
Overlay options including polylines and polygons
Auto-fitting to specified coordinates

Category search tool:

Performs a category search using the Mapbox Search Box category search API. Features include:
Search for points of interest by category (restaurants, hotels, gas stations, etc.)
Filtering by geographic proximity
Customizable result limits
Rich metadata for each result
Support for multiple languages

Reverse geocoding tool:

Performs reverse geocoding using the Mapbox geocoding V6 API. Features include:
Convert geographic coordinates to human-readable addresses
Customizable levels of detail (street, neighborhood, city, etc.)
Results filtering by type (address, poi, neighborhood, etc.)
Support for multiple languages
Rich location context information

Directions tool:

Fetches routing directions using the Mapbox Directions API. Features include:

Support for different routing profiles: driving (with live traffic or typical), walking, and cycling
Route from multiple waypoints (2-25 coordinate pairs)
Alternative routes option
Route annotations (distance, duration, speed, congestion)

Scheduling options:

Future departure time (depart_at) for driving and driving-traffic profiles
Desired arrival time (arrive_by) for driving profile only
Profile-specific optimizations:
Driving: vehicle dimension constraints (height, width, weight)
Exclusion options for routing:
Common exclusions: ferry routes, cash-only tolls
Driving-specific exclusions: tolls, motorways, unpaved roads, tunnels, country borders, state borders
Custom point exclusions (up to 50 geographic points to avoid)
GeoJSON geometry output format

Isochrone tool:

Computes areas that are reachable within a specified amount of times from a location using Mapbox Isochrone API. Features include:

Support for different travel profiles (driving, walking, cycling)
Customizable travel times or distances
Multiple contour generation (e.g., 15, 30, 45 minute ranges)
Optional departure or arrival time specification
Color customization for visualization

Search and geocode tool:
Uses the Mapbox Search Box Text Search API endpoint to power searching for and geocoding POIs, addresses, places, and any other types supported by that API. This tool consolidates the functionality that was previously provided by the ForwardGeocodeTool and PoiSearchTool (from earlier versions of this MCP server) into a single tool.`


,
Comment on lines +151 to +218
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider restructuring the tool description for clarity.

The description has expanded from a concise statement to 65+ lines of prose covering multiple distinct tools (static image, category search, reverse geocoding, directions, isochrone, search/geocode). While comprehensive, this format may:

  1. Consume significant tokens in LLM context windows
  2. Make it harder for the AI to quickly identify the appropriate tool for a given query
  3. Conflate multiple tool capabilities into one description

Consider using structured markdown (bullet points, clear sections) or a more concise summary with references to detailed documentation.

🤖 Prompt for AI Agents
In lib/agents/tools/geospatial.tsx around lines 151 to 218 the tool description
has grown into a 65+ line prose block that mixes many distinct sub-tools and
will bloat LLM context and reduce clarity; replace this long paragraph with a
concise, structured summary that lists each sub-tool as a one-line entry (name +
2–3 key capabilities) or a short bulleted list and add a single-line pointer/URL
to full docs for details, ensuring each sub-tool is clearly separable so the
agent can select the correct capability without scanning long prose.

parameters: geospatialQuerySchema,
execute: async (params: z.infer<typeof geospatialQuerySchema>) => {
const { queryType, includeMap = true } = params;
Expand Down Expand Up @@ -181,24 +248,25 @@ export const geospatialTool = ({ uiStream }: { uiStream: ReturnType<typeof creat
const { tools } = await mcpClient.listTools().catch(() => ({ tools: [] }));
const names = new Set(tools?.map((t: any) => t.name) || []);
const prefer = (...cands: string[]) => cands.find(n => names.has(n));

switch (queryType) {
case 'directions':
case 'distance': return prefer('calculate_distance', 'mapbox_matrix', 'mapbox_directions') || 'mapbox_matrix';
case 'search': return prefer('search_nearby_places', 'mapbox_geocoding') || 'mapbox_geocoding';
case 'map': return prefer('generate_map_link', 'mapbox_geocoding') || 'mapbox_geocoding';
case 'reverse':
case 'geocode': return prefer('geocode_location', 'mapbox_geocoding') || 'mapbox_geocoding';
case 'directions': return prefer('directions_tool')
case 'distance': return prefer('matrix_tool');
case 'search': return prefer( 'isochrone_tool','category_search_tool') || 'poi_search_tool';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Questionable tool selection for search queries.

The search case prefers isochrone_tool first, but isochrone tools compute reachable areas (travel-time polygons), not search results. This will route search queries to the wrong tool if isochrone_tool exists.

Apply this diff to prioritize appropriate tools:

-          case 'search': return prefer( 'isochrone_tool','category_search_tool') || 'poi_search_tool';
+          case 'search': return prefer('category_search_tool', 'poi_search_tool');

If isochrone functionality is needed, introduce a separate queryType (e.g., 'isochrone' or 'reachability') rather than conflating it with search.

📝 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
case 'search': return prefer( 'isochrone_tool','category_search_tool') || 'poi_search_tool';
case 'search': return prefer('category_search_tool', 'poi_search_tool');
🤖 Prompt for AI Agents
In lib/agents/tools/geospatial.tsx around line 255, the 'search' case currently
prefers 'isochrone_tool' which is incorrect because isochrone computes reachable
areas rather than search results; change the preference order to prefer
search-related tools first (e.g.,
prefer('category_search_tool','poi_search_tool') || 'poi_search_tool') so search
queries route to appropriate tools, and if isochrone functionality is needed add
a new queryType like 'isochrone' or 'reachability' and handle that separately
instead of including it in the 'search' branch.

case 'map': return prefer('static_map_image_tool')
case 'reverse': return prefer('reverse_geocode_tool');
case 'geocode': return prefer('forward_geocode_tool');
}
})();

// Build arguments
const toolArgs = (() => {
switch (queryType) {
case 'directions':
case 'directions': return { waypoints: [params.origin, params.destination], includeMapPreview: includeMap, profile: params.mode };
case 'distance': return { places: [params.origin, params.destination], includeMapPreview: includeMap, mode: params.mode || 'driving' };
case 'reverse': return { searchText: `${params.coordinates.latitude},${params.coordinates.longitude}`, includeMapPreview: includeMap, maxResults: params.maxResults || 5 };
case 'search': return { searchText: params.query, includeMapPreview: includeMap, maxResults: params.maxResults || 5, ...(params.coordinates && { proximity: `${params.coordinates.latitude},${params.coordinates.longitude}` }), ...(params.radius && { radius: params.radius }) };
case 'geocode':
case 'geocode':
case 'map': return { searchText: params.location, includeMapPreview: includeMap, maxResults: queryType === 'geocode' ? params.maxResults || 5 : undefined };
}
})();
Expand All @@ -212,7 +280,7 @@ export const geospatialTool = ({ uiStream }: { uiStream: ReturnType<typeof creat
while (retryCount < MAX_RETRIES) {
try {
toolCallResult = await Promise.race([
mcpClient.callTool({ name: toolName, arguments: toolArgs }),
mcpClient.callTool({ name: toolName ?? 'unknown_tool', arguments: toolArgs }),
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider failing fast if toolName is undefined.

The fallback toolName ?? 'unknown_tool' prevents a null reference but will likely result in a failed tool call. Consider validating toolName before the retry loop and throwing a descriptive error early.

Example:

if (!toolName) {
  throw new Error(`No appropriate tool found for queryType: ${queryType}`);
}
🤖 Prompt for AI Agents
In lib/agents/tools/geospatial.tsx around line 283, the code uses a fallback
'unknown_tool' when toolName is undefined which will likely cause a failing tool
call; instead validate toolName before entering the retry loop and throw a
descriptive error (e.g., throw new Error(`No appropriate tool found for
queryType: ${queryType}`)) so the function fails fast, and remove the fallback
usage at the mcpClient.callTool invocation.

new Promise((_, reject) => setTimeout(() => reject(new Error('Tool call timeout')), 30000)),
]);
break;
Expand Down
5 changes: 4 additions & 1 deletion lib/agents/writer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ 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.
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 and mapbox results together into a coherent answer. Do not repeat text. If there are any images or maps 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 and the mapbox tool.
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)

There are also some proconfigured example queires.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typos in the system prompt.

Line 28 contains two typos:

  • "proconfigured" should be "preconfigured"
  • "queires" should be "queries"

Apply this diff:

-    There are also some proconfigured example queires. 
+    There are also some preconfigured example queries.
📝 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
There are also some proconfigured example queires.
There are also some preconfigured example queries.
🤖 Prompt for AI Agents
In lib/agents/writer.tsx around line 28, fix typos in the system prompt: replace
"proconfigured" with "preconfigured" and "queires" with "queries" so the
sentence reads correctly (e.g., "There are also some preconfigured example
queries.").

When asked about 'What is a planet computer?' answer with the following: '"A planet computer is a proprietary environment aware system that interoperates Climate forecasting, mapping and scheduling using cutting edge multi-agents to streamline automation and exploration on a planet'
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix syntax error and improve hardcoded example.

Line 29 has multiple issues:

  1. Critical: Missing closing double quote at the end of the string, which will cause a syntax error
  2. The hardcoded answer has grammatical issues: "interoperates Climate forecasting" should be "integrates climate forecasting"
  3. Hardcoding specific examples in the system prompt is poor practice—consider moving to a separate configuration file or examples database

Apply this diff to fix the immediate syntax error and grammar:

-    When asked about 'What is a planet computer?' answer with the following: '"A planet computer is a proprietary environment aware system that interoperates Climate forecasting, mapping and scheduling using cutting edge multi-agents to streamline automation and exploration on a planet'
+    When asked about 'What is a planet computer?' answer with the following: "A planet computer is a proprietary environment-aware system that integrates climate forecasting, mapping and scheduling using cutting-edge multi-agents to streamline automation and exploration on a planet."

Recommended refactor: Consider extracting hardcoded examples into a separate configuration file or database to improve maintainability.

📝 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
When asked about 'What is a planet computer?' answer with the following: '"A planet computer is a proprietary environment aware system that interoperates Climate forecasting, mapping and scheduling using cutting edge multi-agents to streamline automation and exploration on a planet'
When asked about 'What is a planet computer?' answer with the following: "A planet computer is a proprietary environment-aware system that integrates climate forecasting, mapping and scheduling using cutting-edge multi-agents to streamline automation and exploration on a planet."
🤖 Prompt for AI Agents
In lib/agents/writer.tsx around line 29, the string for the example response is
missing a closing double-quote (causing a syntax error) and contains grammar
issues; fix by closing the string, replace "interoperates Climate forecasting"
with "integrates climate forecasting" and correct capitalization/punctuation as
needed, and as a follow-up move this hardcoded example into a separate config or
examples file (or load from an examples DB) rather than keeping it inline.

`;

const systemToUse = dynamicSystemPrompt && dynamicSystemPrompt.trim() !== '' ? dynamicSystemPrompt : default_system_prompt;
Expand Down
Loading