Update rag_langgraph.py
Browse files- rag_langgraph.py +11 -11
rag_langgraph.py
CHANGED
@@ -46,17 +46,17 @@ def today_tool(text: str) -> str:
|
|
46 |
def create_graph(topic):
|
47 |
tavily_tool = TavilySearchResults(max_results=10)
|
48 |
|
49 |
-
|
50 |
|
51 |
system_prompt = (
|
52 |
-
"You are a
|
53 |
-
" following
|
54 |
-
" respond with the
|
55 |
" task and respond with their results and status. When finished,"
|
56 |
" respond with FINISH."
|
57 |
)
|
58 |
|
59 |
-
options = ["FINISH"] +
|
60 |
|
61 |
function_def = {
|
62 |
"name": "route",
|
@@ -86,7 +86,7 @@ def create_graph(topic):
|
|
86 |
" Or should we FINISH? Select one of: {options}",
|
87 |
),
|
88 |
]
|
89 |
-
).partial(options=str(options), members=", ".join(
|
90 |
|
91 |
llm = ChatOpenAI(model=LLM)
|
92 |
|
@@ -96,10 +96,10 @@ def create_graph(topic):
|
|
96 |
| JsonOutputFunctionsParser()
|
97 |
)
|
98 |
|
99 |
-
researcher_agent = create_agent(llm, [tavily_tool], system_prompt=f"
|
100 |
researcher_node = functools.partial(agent_node, agent=researcher_agent, name="Researcher")
|
101 |
|
102 |
-
writer_agent = create_agent(llm, [today_tool], system_prompt=f"Write a 2000-word article on topic: {topic}
|
103 |
writer_node = functools.partial(agent_node, agent=writer_agent, name="Writer")
|
104 |
|
105 |
workflow = StateGraph(AgentState)
|
@@ -107,10 +107,10 @@ def create_graph(topic):
|
|
107 |
workflow.add_node("Writer", writer_node)
|
108 |
workflow.add_node("Manager", supervisor_chain)
|
109 |
|
110 |
-
for
|
111 |
-
workflow.add_edge(
|
112 |
|
113 |
-
conditional_map = {k: k for k in
|
114 |
conditional_map["FINISH"] = END
|
115 |
|
116 |
workflow.add_conditional_edges("Manager", lambda x: x["next"], conditional_map)
|
|
|
46 |
def create_graph(topic):
|
47 |
tavily_tool = TavilySearchResults(max_results=10)
|
48 |
|
49 |
+
agents = ["Researcher", "Writer"]
|
50 |
|
51 |
system_prompt = (
|
52 |
+
"You are a Manager tasked with managing a conversation between the"
|
53 |
+
" following agents: {agents}. Given the following user request,"
|
54 |
+
" respond with the agent to act next. Each agent will perform a"
|
55 |
" task and respond with their results and status. When finished,"
|
56 |
" respond with FINISH."
|
57 |
)
|
58 |
|
59 |
+
options = ["FINISH"] + agents
|
60 |
|
61 |
function_def = {
|
62 |
"name": "route",
|
|
|
86 |
" Or should we FINISH? Select one of: {options}",
|
87 |
),
|
88 |
]
|
89 |
+
).partial(options=str(options), members=", ".join(agents))
|
90 |
|
91 |
llm = ChatOpenAI(model=LLM)
|
92 |
|
|
|
96 |
| JsonOutputFunctionsParser()
|
97 |
)
|
98 |
|
99 |
+
researcher_agent = create_agent(llm, [tavily_tool], system_prompt=f"Research content on topic: {topic}. Prioritize research papers, if available.")
|
100 |
researcher_node = functools.partial(agent_node, agent=researcher_agent, name="Researcher")
|
101 |
|
102 |
+
writer_agent = create_agent(llm, [today_tool], system_prompt=f"Write a 2000-word article on topic: {topic}. At the beginning, add current date and author: Multi-AI-Agent System based on GPT-4o. At the end, add a reference section with research papers.")
|
103 |
writer_node = functools.partial(agent_node, agent=writer_agent, name="Writer")
|
104 |
|
105 |
workflow = StateGraph(AgentState)
|
|
|
107 |
workflow.add_node("Writer", writer_node)
|
108 |
workflow.add_node("Manager", supervisor_chain)
|
109 |
|
110 |
+
for agent in agents:
|
111 |
+
workflow.add_edge(agent, "Manager")
|
112 |
|
113 |
+
conditional_map = {k: k for k in agents}
|
114 |
conditional_map["FINISH"] = END
|
115 |
|
116 |
workflow.add_conditional_edges("Manager", lambda x: x["next"], conditional_map)
|