Repository navigation
Expand file tree
/
Copy pathagents.py
More file actions
75 lines (56 loc) · 1.66 KB
/
Copy pathagents.py
File metadata and controls
75 lines (56 loc) · 1.66 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
75
import warnings
warnings.filterwarnings('ignore')
from dotenv import load_dotenv
load_dotenv()
from langchain.agents import create_agent
from langchain_groq import ChatGroq
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from tools import web_search, scrape_url
# model setup
llm = ChatGroq(model="openai/gpt-oss-120b", temperature=0)
# 1st agent
def build_search_agent():
return create_agent(
model = llm,
tools = [web_search]
)
# 2nd agent
def build_reader_agent():
return create_agent(
model=llm,
tools=[scrape_url]
)
# writer chain
writer_prompt = ChatPromptTemplate.from_messages([
("system", "You are an expert research writer. Write clear, structured and insightful reports."),
("human", """Write a detailed research report on the topic below.
Topic: {topic}
Research Gathered:
{research}
Structure the report as:
- Introduction
- Key Findings (minimum 3 well-explained points)
- Conclusion
- Sources (list all URLs found in the research)
Be detailed, factual and professional."""),
])
writer_chain = writer_prompt | llm | StrOutputParser()
# critic chain
critic_chain = ChatPromptTemplate.from_messages([
("system", "You are a sharp and constructive research critic. Be honest and specific."),
("human", """Review the research report below and evaluate it strictly.
Report:
{report}
Respond in this exact format:
Score: X/10
Strengths:
- ...
- ...
Areas to Improve:
- ...
- ...
One line verdict:
..."""),
])
critic_chain = critic_chain | llm | StrOutputParser()