amatsarski commited on
Commit
fd0d494
·
verified ·
1 Parent(s): 71299d1

Create agents/nodes

Browse files
Files changed (1) hide show
  1. agents/nodes +51 -0
agents/nodes ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.agents import AgentExecutor, create_tool_calling_agent
2
+ from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
3
+
4
+ def news_node(state: GraphState, agent: AgentExecutor) -> GraphState:
5
+ ticker = state["ticker"]
6
+ q = f"Research recent news for {ticker}. Focus on price-moving catalysts."
7
+ res = agent.invoke({"input": q})
8
+ state["news_summary"] = res["output"]
9
+ state["completed"] = list(set(state["completed"] + ["news"]))
10
+ return state
11
+
12
+
13
+ def earnings_node(state: GraphState, agent: AgentExecutor) -> GraphState:
14
+ ticker = state["ticker"]
15
+ q = f"Analyze earnings for {ticker}. Summarize last and upcoming earnings. Use the tool."
16
+ res = agent.invoke({"input": q})
17
+ state["earnings_summary"] = res["output"]
18
+ state["completed"] = list(set(state["completed"] + ["earnings"]))
19
+ return state
20
+
21
+
22
+ def market_node(state: GraphState, agent: AgentExecutor) -> GraphState:
23
+ ticker = state["ticker"]
24
+ q = f"Provide a market snapshot for {ticker}. Use the tool."
25
+ res = agent.invoke({"input": q})
26
+ state["market_summary"] = res["output"]
27
+ state["completed"] = list(set(state["completed"] + ["market"]))
28
+ return state
29
+
30
+
31
+ def synth_node(state: GraphState, synthesizer_chain) -> GraphState:
32
+ out = synthesizer_chain.invoke(
33
+ {
34
+ "ticker": state["ticker"],
35
+ "news_summary": state.get("news_summary", ""),
36
+ "earnings_summary": state.get("earnings_summary", ""),
37
+ "market_summary": state.get("market_summary", ""),
38
+ }
39
+ )
40
+ state["final_recommendation"] = out.content if hasattr(out, "content") else str(out)
41
+ return state
42
+
43
+ def supervisor_node(state: GraphState) -> GraphState:
44
+ # Do any bookkeeping here if needed; otherwise just pass state through
45
+ return state
46
+
47
+ AGENTS = ["news", "earnings", "market"]
48
+
49
+ def supervisor_router(state: GraphState) -> str:
50
+ remaining = [a for a in AGENTS if a not in state.get("completed", [])]
51
+ return remaining[0] if remaining else "synth"