105 lines
5.2 KiB
Python
105 lines
5.2 KiB
Python
from datetime import datetime
|
|
|
|
|
|
# Get current date in a readable format
|
|
def get_current_date():
|
|
return datetime.now().strftime("%B %d, %Y")
|
|
|
|
|
|
query_writer_instructions = """Your goal is to generate sophisticated and diverse web search queries. These queries are intended for an advanced automated web research tool capable of analyzing complex results, following links, and synthesizing information.
|
|
|
|
Instructions:
|
|
- Always prefer a single search query, only add another query if the original question requests multiple aspects or elements and one query is not enough.
|
|
- Each query should focus on one specific aspect of the original question.
|
|
- Don't produce more than {number_queries} queries.
|
|
- Queries should be diverse, if the topic is broad, generate more than 1 query.
|
|
- Don't generate multiple similar queries, 1 is enough.
|
|
- Query should ensure that the most current information is gathered. The current date is {current_date}.
|
|
- Keep every individual query under 400 characters. Prefer concise search terms over full-sentence restatements.
|
|
|
|
Format:
|
|
- Format your response as a JSON object with ALL two of these exact keys:
|
|
- "rationale": Brief explanation of why these queries are relevant
|
|
- "query": A list of search queries
|
|
|
|
Example:
|
|
|
|
Topic: What revenue grew more last year apple stock or the number of people buying an iphone
|
|
```json
|
|
{{
|
|
"rationale": "To answer this comparative growth question accurately, we need specific data points on Apple's stock performance and iPhone sales metrics. These queries target the precise financial information needed: company revenue trends, product-specific unit sales figures, and stock price movement over the same fiscal period for direct comparison.",
|
|
"query": ["Apple total revenue growth fiscal year 2024", "iPhone unit sales growth fiscal year 2024", "Apple stock price growth fiscal year 2024"],
|
|
}}
|
|
```
|
|
|
|
Context: {research_topic}"""
|
|
|
|
|
|
web_searcher_instructions = """Review the provided Tavily search results for "{research_topic}" and synthesize them into a verifiable research note.
|
|
|
|
Instructions:
|
|
- Query should ensure that the most current information is gathered. The current date is {current_date}.
|
|
- Use only the provided Tavily search results. Do not invent or infer facts that are not supported by those results.
|
|
- Consolidate the key findings into a concise research note for this query.
|
|
- Every factual paragraph or bullet must include at least one markdown citation using the exact title and URL from the provided sources, for example: [Reuters](https://www.reuters.com/example).
|
|
- Preserve full URLs in citations. Do not use placeholders, IDs, or shortened URLs.
|
|
- If the results are insufficient, explicitly say what is missing and cite the closest available sources.
|
|
|
|
Research Topic:
|
|
{research_topic}
|
|
|
|
Search Results:
|
|
{search_results}
|
|
"""
|
|
|
|
reflection_instructions = """You are an expert research assistant analyzing collected research evidence about "{research_topic}".
|
|
|
|
Instructions:
|
|
- Identify knowledge gaps or areas that need deeper exploration and generate a follow-up query. (1 or multiple).
|
|
- If the provided evidence is sufficient to answer the user's question, don't generate a follow-up query.
|
|
- If there is a knowledge gap, generate a follow-up query that would help expand your understanding.
|
|
- Focus on technical details, implementation specifics, or emerging trends that weren't fully covered.
|
|
- Keep every follow-up query under 400 characters. Prefer compact search phrases over long natural-language questions.
|
|
|
|
Requirements:
|
|
- Ensure the follow-up query is self-contained and includes necessary context for web search.
|
|
|
|
Output Format:
|
|
- Format your response as a JSON object with these exact keys:
|
|
- "is_sufficient": true or false
|
|
- "knowledge_gap": Describe what information is missing or needs clarification
|
|
- "follow_up_queries": Write a specific question to address this gap
|
|
|
|
Example:
|
|
```json
|
|
{{
|
|
"is_sufficient": true, // or false
|
|
"knowledge_gap": "The summary lacks information about performance metrics and benchmarks", // "" if is_sufficient is true
|
|
"follow_up_queries": ["What are typical performance benchmarks and metrics used to evaluate [specific technology]?"] // [] if is_sufficient is true
|
|
}}
|
|
```
|
|
|
|
Reflect carefully on the Research Evidence to identify knowledge gaps and produce a follow-up query. Then, produce your output following this JSON format:
|
|
|
|
Research Evidence:
|
|
{summaries}
|
|
"""
|
|
|
|
answer_instructions = """Generate a high-quality answer to the user's question based on the provided research evidence.
|
|
|
|
Instructions:
|
|
- The current date is {current_date}.
|
|
- You are the final step of a multi-step research process, don't mention that you are the final step.
|
|
- You have access to all the information gathered from the previous steps.
|
|
- You have access to the user's question.
|
|
- Generate a high-quality answer to the user's question based on the provided research evidence and the user's question.
|
|
- Use only the evidence present in the Research Evidence.
|
|
- Preserve or reuse source citations from the Research Evidence as full markdown links. Every factual paragraph should include at least one citation.
|
|
- Do not invent sources, placeholders, or shortened URLs.
|
|
|
|
User Context:
|
|
- {research_topic}
|
|
|
|
Research Evidence:
|
|
{summaries}"""
|