-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagents.py
More file actions
81 lines (59 loc) · 1.73 KB
/
Copy pathagents.py
File metadata and controls
81 lines (59 loc) · 1.73 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
76
77
78
79
80
81
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from tools import web_search, scrape_url
import os
from dotenv import load_dotenv
load_dotenv()
#model setup
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
#first_agent
def build_search_agent():
return create_agent(
model = llm,
tools = [web_search]
)
#second_agent
def build_reader_agent():
return create_agent(
model = llm,
tools = [scrape_url]
)
#writer_chain
write_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 (minimu 3 well-explained points)
- Conclusion
- Source (list all URLs found in the research)
Be detailed, factual and professional.
""")
]
)
writer_chain = write_prompt | llm | StrOutputParser()
#crtic_chain
critic_prompt = 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_prompt | llm | StrOutputParser()