-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.py
More file actions
75 lines (52 loc) · 2 KB
/
Copy pathpipeline.py
File metadata and controls
75 lines (52 loc) · 2 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from agents import build_reader_agent , build_search_agent , writer_chain , critic_chain
def run_research_pipeline(topic : str) -> dict:
state = {}
#search agent working
print("\n"+" ="*50)
print("step 1 - search agent is working ...")
print("="*50)
search_agent = build_search_agent()
search_result = search_agent.invoke({
"messages" : [("user", f"Find recent, reliable and detailed information about: {topic}")]
})
state["search_results"] = search_result['messages'][-1].content
print("\n search result ",state['search_results'])
#step 2 - reader agent
print("\n"+" ="*50)
print("step 2 - Reader agent is scraping top resources ...")
print("="*50)
reader_agent = build_reader_agent()
reader_result = reader_agent.invoke({
"messages": [("user",
f"Based on the following search results about '{topic}', "
f"pick the most relevant URL and scrape it for deeper content.\n\n"
f"Search Results:\n{state['search_results'][:800]}"
)]
})
state['scraped_content'] = reader_result['messages'][-1].content
print("\nscraped content: \n", state['scraped_content'])
#step 3 - writer chain
print("\n"+" ="*50)
print("step 3 - Writer is drafting the report ...")
print("="*50)
research_combined = (
f"SEARCH RESULTS : \n {state['search_results']} \n\n"
f"DETAILED SCRAPED CONTENT : \n {state['scraped_content']}"
)
state["report"] = writer_chain.invoke({
"topic" : topic,
"research" : research_combined
})
print("\n Final Report\n",state['report'])
#critic report
print("\n"+" ="*50)
print("step 4 - critic is reviewing the report ")
print("="*50)
state["feedback"] = critic_chain.invoke({
"report":state['report']
})
print("\n critic report \n", state['feedback'])
return state
if __name__ == "__main__":
topic = input("\n Enter a research topic : ")
run_research_pipeline(topic)