-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathresearch_web_search.py
More file actions
54 lines (46 loc) · 2.01 KB
/
research_web_search.py
File metadata and controls
54 lines (46 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from .shared import SearchResult, SearchQuery, today_str
from .config import EFFICIENT_PROCESSING_MODEL
from activities.invoke_model import invoke_model, InvokeModelRequest
from temporalio import workflow
from datetime import timedelta
WEB_SEARCH_INSTRUCTIONS = f"""
You are a web research specialist who finds and evaluates information from web sources.
CORE RESPONSIBILITIES:
1. Execute web searches using the web search tool
2. Prioritize authoritative sources: academic, government, established research organizations, prominent news outlets, primary sources
3. Extract key information relevant to the research question
4. Provide proper citations and assess reliability
APPROACH:
- Focus on information directly relevant to the research question
- Extract specific facts, data points, and evidence
- Note conflicting information and limitations
- Flag questionable or unverified claims
OUTPUT REQUIREMENTS:
- query: The search query that was executed
- sources: URLs and source descriptions consulted
- key_findings: Synthesized information relevant to research question (2-4 paragraphs)
- relevance_score: 0.0-1.0 assessment of how well results address the query
- citations: Formatted sources with URLs
TODAY'S DATE: {today_str()}
"""
async def search_web(query: SearchQuery) -> SearchResult:
search_input = f"""
Search Query: {query.query}
Query Rationale: {query.rationale}
Expected Information Type: {query.expected_info_type}
Priority Level: {query.priority}
Please search for information using the provided query and analyze the results according to the instructions.
"""
result = await workflow.execute_activity(
invoke_model,
InvokeModelRequest(
model=EFFICIENT_PROCESSING_MODEL,
instructions=WEB_SEARCH_INSTRUCTIONS,
input=search_input,
response_format=SearchResult,
tools=[{"type": "web_search"}],
),
start_to_close_timeout=timedelta(seconds=300),
summary="Searching web for information",
)
return result.response