roger33303 commited on
Commit
52dc31e
·
verified ·
1 Parent(s): 323f6a9

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +20 -28
agents.py CHANGED
@@ -19,21 +19,19 @@ from dotenv import load_dotenv
19
  # supervisor_prompt = os.getenv("SUPERVISOR_PROMPT")
20
 
21
  def build_graph():
22
- a_debug = False
23
- model = init_chat_model("llama3-70b-8192", model_provider="groq")
24
- summarization_node = SummarizationNode(token_counter=count_tokens_approximately,
25
  model=model,
26
  max_tokens=2048,
27
  max_summary_tokens=1024,
28
  output_messages_key="llm_input_messages",)
29
 
30
- class State(AgentState):
31
- context: dict[str, Any]
32
-
33
- checkpointer = InMemorySaver()
34
-
35
-
36
- agent0= create_react_agent(model=model,
37
  tools= [custom_tools.stock_data_tool],
38
  prompt=("Give the company name to the stock tool produce the stock fundamentals. Summarize all the information in one paragraph in 200 words."),
39
  name="Stock Analyst",
@@ -41,8 +39,8 @@ def build_graph():
41
  state_schema=State,
42
  checkpointer=checkpointer,
43
  debug=a_debug)
44
-
45
- agent1= create_react_agent(model=model,
46
  tools= [custom_tools.web_search],
47
  prompt='''You are a geek that can find anything from the internet. Do the research and provide the summery in 250 words and in only one paragraph.''',
48
  name="Web Surfer",
@@ -50,8 +48,8 @@ def build_graph():
50
  state_schema=State,
51
  checkpointer=checkpointer,
52
  debug=a_debug)
53
-
54
- agent2= create_react_agent(model=model,
55
  tools= [custom_tools.reddit_search_tool],
56
  prompt='''You are a social media analyst. your job is to search social media and find out the sentiments of public on any topic. Do the research and provide the summery in 250 words and in only one paragraph.''',
57
  name="Social Media Analyst",
@@ -60,7 +58,7 @@ def build_graph():
60
  checkpointer=checkpointer,
61
  debug=a_debug)
62
 
63
- agent3= create_react_agent(model=model,
64
  tools= [custom_tools.tech_news_tool],
65
  prompt='''You are a Technology news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
66
  name="Tech Journalist",
@@ -69,7 +67,7 @@ def build_graph():
69
  checkpointer=checkpointer,
70
  debug=a_debug)
71
 
72
- agent4= create_react_agent(model=model,
73
  tools= [custom_tools.politics_news_tool],
74
  prompt='''You are a Politics news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
75
  name="Political Journalist",
@@ -78,7 +76,7 @@ def build_graph():
78
  checkpointer=checkpointer,
79
  debug=a_debug)
80
 
81
- agent5= create_react_agent(model=model,
82
  tools= [custom_tools.business_news_tool],
83
  prompt='''You are a Business news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
84
  name="Business Journalist",
@@ -86,17 +84,15 @@ def build_graph():
86
  state_schema=State,
87
  checkpointer=checkpointer,
88
  debug=a_debug)
89
-
90
- agent6= create_react_agent(model=model,
91
  tools= [custom_tools.world_news_tool],
92
  prompt='''You are a Geopolitical news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
93
  name="Geopolitical Journalist",
94
  pre_model_hook= summarization_node,
95
  state_schema=State,
96
  checkpointer=checkpointer,
97
- debug=a_debug)
98
-
99
-
100
  supervisor_prompt = '''You are a stock market research supervisor based in the United Kingdom. You lead a team of expert agents, each specializing in a specific domain. Your job is to orchestrate these agents to compile a comprehensive report based on the user's stock-related question.
101
  IMPORTANT: You DO NOT analyze anything yourself — your role is to build a strategy, decide when and whom to call, and summarize their findings.
102
  ---
@@ -155,13 +151,9 @@ Optimize calls:
155
  Your output should contain intermediate decisions, the agent/tool called, the query issued, and the response. After all tools are used, generate the final report.
156
 
157
  '''
158
-
159
-
160
-
161
-
162
 
163
- graph = create_supervisor(agents=[agent0,agent1,agent2,agent3,agent4,agent5,agent6],
164
  model=model,
165
  prompt= supervisor_prompt)
166
- return graph.compile()
167
 
 
19
  # supervisor_prompt = os.getenv("SUPERVISOR_PROMPT")
20
 
21
  def build_graph():
22
+ a_debug = False
23
+ model = init_chat_model("llama3-70b-8192", model_provider="groq")
24
+ summarization_node = SummarizationNode(token_counter=count_tokens_approximately,
25
  model=model,
26
  max_tokens=2048,
27
  max_summary_tokens=1024,
28
  output_messages_key="llm_input_messages",)
29
 
30
+ class State(AgentState):
31
+ context: dict[str, Any]
32
+ checkpointer = InMemorySaver()
33
+
34
+ agent0= create_react_agent(model=model,
 
 
35
  tools= [custom_tools.stock_data_tool],
36
  prompt=("Give the company name to the stock tool produce the stock fundamentals. Summarize all the information in one paragraph in 200 words."),
37
  name="Stock Analyst",
 
39
  state_schema=State,
40
  checkpointer=checkpointer,
41
  debug=a_debug)
42
+
43
+ agent1= create_react_agent(model=model,
44
  tools= [custom_tools.web_search],
45
  prompt='''You are a geek that can find anything from the internet. Do the research and provide the summery in 250 words and in only one paragraph.''',
46
  name="Web Surfer",
 
48
  state_schema=State,
49
  checkpointer=checkpointer,
50
  debug=a_debug)
51
+
52
+ agent2= create_react_agent(model=model,
53
  tools= [custom_tools.reddit_search_tool],
54
  prompt='''You are a social media analyst. your job is to search social media and find out the sentiments of public on any topic. Do the research and provide the summery in 250 words and in only one paragraph.''',
55
  name="Social Media Analyst",
 
58
  checkpointer=checkpointer,
59
  debug=a_debug)
60
 
61
+ agent3= create_react_agent(model=model,
62
  tools= [custom_tools.tech_news_tool],
63
  prompt='''You are a Technology news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
64
  name="Tech Journalist",
 
67
  checkpointer=checkpointer,
68
  debug=a_debug)
69
 
70
+ agent4= create_react_agent(model=model,
71
  tools= [custom_tools.politics_news_tool],
72
  prompt='''You are a Politics news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
73
  name="Political Journalist",
 
76
  checkpointer=checkpointer,
77
  debug=a_debug)
78
 
79
+ agent5= create_react_agent(model=model,
80
  tools= [custom_tools.business_news_tool],
81
  prompt='''You are a Business news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
82
  name="Business Journalist",
 
84
  state_schema=State,
85
  checkpointer=checkpointer,
86
  debug=a_debug)
87
+
88
+ agent6= create_react_agent(model=model,
89
  tools= [custom_tools.world_news_tool],
90
  prompt='''You are a Geopolitical news analyst. You find the latest news related to a topic and summerize it to findout the overall picture. Do the research and provide the summery in 250 words and in only one paragraph.''',
91
  name="Geopolitical Journalist",
92
  pre_model_hook= summarization_node,
93
  state_schema=State,
94
  checkpointer=checkpointer,
95
+ debug=a_debug)
 
 
96
  supervisor_prompt = '''You are a stock market research supervisor based in the United Kingdom. You lead a team of expert agents, each specializing in a specific domain. Your job is to orchestrate these agents to compile a comprehensive report based on the user's stock-related question.
97
  IMPORTANT: You DO NOT analyze anything yourself — your role is to build a strategy, decide when and whom to call, and summarize their findings.
98
  ---
 
151
  Your output should contain intermediate decisions, the agent/tool called, the query issued, and the response. After all tools are used, generate the final report.
152
 
153
  '''
 
 
 
 
154
 
155
+ graph = create_supervisor(agents=[agent0,agent1,agent2,agent3,agent4,agent5,agent6],
156
  model=model,
157
  prompt= supervisor_prompt)
158
+ return graph.compile()
159