roger33303 commited on
Commit
cad5295
·
verified ·
1 Parent(s): 9a46e61

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +109 -106
agents.py CHANGED
@@ -1,106 +1,109 @@
1
- from langgraph.graph import StateGraph, MessagesState, START, END
2
- from langmem.short_term import SummarizationNode
3
- from langchain_core.messages.utils import count_tokens_approximately
4
- from langgraph.prebuilt.chat_agent_executor import AgentState
5
- from langgraph.checkpoint.memory import InMemorySaver
6
- from typing import Any
7
- import os
8
- from langchain.chat_models import init_chat_model
9
- from langgraph.prebuilt import create_react_agent
10
- from langgraph_supervisor import create_supervisor
11
- import custom_tools as custom_tools
12
- from dotenv import load_dotenv
13
-
14
- load_dotenv()
15
-
16
- supervisor_prompt = os.getenv("SUPERVISOR_PROMPT")
17
-
18
- def build_graph():
19
- a_debug = False
20
- model = init_chat_model("llama3-70b-8192", model_provider="groq")
21
- summarization_node = SummarizationNode(token_counter=count_tokens_approximately,
22
- model=model,
23
- max_tokens=2048,
24
- max_summary_tokens=1024,
25
- output_messages_key="llm_input_messages",)
26
-
27
- class State(AgentState):
28
- context: dict[str, Any]
29
-
30
- checkpointer = InMemorySaver()
31
-
32
-
33
- agent0= create_react_agent(model=model,
34
- tools= [custom_tools.stock_data_tool],
35
- prompt=("Give the company name to the stock tool produce the stock fundamentals. Summarize all the information in one paragraph in 200 words."),
36
- name="Stock Analyst",
37
- pre_model_hook= summarization_node,
38
- state_schema=State,
39
- checkpointer=checkpointer,
40
- debug=a_debug)
41
-
42
- agent1= create_react_agent(model=model,
43
- tools= [custom_tools.web_search],
44
- 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.''',
45
- name="Web Surfer",
46
- pre_model_hook= summarization_node,
47
- state_schema=State,
48
- checkpointer=checkpointer,
49
- debug=a_debug)
50
-
51
- agent2= create_react_agent(model=model,
52
- tools= [custom_tools.reddit_search_tool],
53
- 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.''',
54
- name="Social Media Analyst",
55
- pre_model_hook= summarization_node,
56
- state_schema=State,
57
- checkpointer=checkpointer,
58
- debug=a_debug)
59
-
60
- agent3= create_react_agent(model=model,
61
- tools= [custom_tools.tech_news_tool],
62
- 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.''',
63
- name="Tech Journalist",
64
- pre_model_hook= summarization_node,
65
- state_schema=State,
66
- checkpointer=checkpointer,
67
- debug=a_debug)
68
-
69
- agent4= create_react_agent(model=model,
70
- tools= [custom_tools.politics_news_tool],
71
- 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.''',
72
- name="Political Journalist",
73
- pre_model_hook= summarization_node,
74
- state_schema=State,
75
- checkpointer=checkpointer,
76
- debug=a_debug)
77
-
78
- agent5= create_react_agent(model=model,
79
- tools= [custom_tools.business_news_tool],
80
- 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.''',
81
- name="Business Journalist",
82
- pre_model_hook= summarization_node,
83
- state_schema=State,
84
- checkpointer=checkpointer,
85
- debug=a_debug)
86
-
87
- agent6= create_react_agent(model=model,
88
- tools= [custom_tools.world_news_tool],
89
- 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.''',
90
- name="Geopolitical Journalist",
91
- pre_model_hook= summarization_node,
92
- state_schema=State,
93
- checkpointer=checkpointer,
94
- debug=a_debug)
95
-
96
-
97
- supervisor_prompt = '''
98
-
99
- '''
100
-
101
-
102
- graph = create_supervisor(agents=[agent0,agent1,agent2,agent3,agent4,agent5,agent6],
103
- model=model,
104
- prompt= supervisor_prompt)
105
- return graph.compile()
106
-
 
 
 
 
1
+ from patch_langmem import patch_langmem_for_python310
2
+ patch_langmem_for_python310()
3
+
4
+ from langgraph.graph import StateGraph, MessagesState, START, END
5
+ from langmem.short_term import SummarizationNode
6
+ from langchain_core.messages.utils import count_tokens_approximately
7
+ from langgraph.prebuilt.chat_agent_executor import AgentState
8
+ from langgraph.checkpoint.memory import InMemorySaver
9
+ from typing import Any
10
+ import os
11
+ from langchain.chat_models import init_chat_model
12
+ from langgraph.prebuilt import create_react_agent
13
+ from langgraph_supervisor import create_supervisor
14
+ import custom_tools as custom_tools
15
+ from dotenv import load_dotenv
16
+
17
+ load_dotenv()
18
+
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",
40
+ pre_model_hook= summarization_node,
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",
49
+ pre_model_hook= summarization_node,
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",
58
+ pre_model_hook= summarization_node,
59
+ state_schema=State,
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",
67
+ pre_model_hook= summarization_node,
68
+ state_schema=State,
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",
76
+ pre_model_hook= summarization_node,
77
+ state_schema=State,
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",
85
+ pre_model_hook= summarization_node,
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 = '''
101
+
102
+ '''
103
+
104
+
105
+ graph = create_supervisor(agents=[agent0,agent1,agent2,agent3,agent4,agent5,agent6],
106
+ model=model,
107
+ prompt= supervisor_prompt)
108
+ return graph.compile()
109
+