ameglei-external commited on
Commit
ddb304e
·
verified ·
1 Parent(s): 5b59c30

Use messsage state from langgraph

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -9,12 +9,11 @@ import pandas as pd
9
 
10
  from duckduckgo_search import DDGS
11
 
12
- from langgraph.graph import StateGraph, START
13
  from langgraph.graph.message import add_messages
14
  from langgraph.prebuilt import ToolNode, tools_condition
15
 
16
  from langchain_openai import ChatOpenAI
17
- # from langchain_community.tools import DuckDuckGoSearchRun
18
  from langchain_core.messages import SystemMessage, HumanMessage, AnyMessage
19
  from langchain_core.tools import tool
20
 
@@ -22,9 +21,13 @@ from langchain_core.tools import tool
22
  # --- Constants ---
23
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
24
 
25
- class State(TypedDict):
 
 
 
 
 
26
  question: str
27
- messages: Annotated[List[AnyMessage], add_messages]
28
 
29
 
30
  class BasicAgent:
@@ -85,10 +88,8 @@ class BasicAgent:
85
 
86
  def assistant(self, state: State):
87
  print("Assistant invoked. State:", state)
88
-
89
  response = self.model_with_tools.invoke(state["messages"])
90
  print("Assistant response:", response)
91
-
92
  return {
93
  "messages": [response]
94
  }
 
9
 
10
  from duckduckgo_search import DDGS
11
 
12
+ from langgraph.graph import MessagesState, StateGraph, START
13
  from langgraph.graph.message import add_messages
14
  from langgraph.prebuilt import ToolNode, tools_condition
15
 
16
  from langchain_openai import ChatOpenAI
 
17
  from langchain_core.messages import SystemMessage, HumanMessage, AnyMessage
18
  from langchain_core.tools import tool
19
 
 
21
  # --- Constants ---
22
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
23
 
24
+ # class State(TypedDict):
25
+ # question: str
26
+ # messages: Annotated[List[AnyMessage], add_messages]
27
+
28
+
29
+ class State(MessagesState):
30
  question: str
 
31
 
32
 
33
  class BasicAgent:
 
88
 
89
  def assistant(self, state: State):
90
  print("Assistant invoked. State:", state)
 
91
  response = self.model_with_tools.invoke(state["messages"])
92
  print("Assistant response:", response)
 
93
  return {
94
  "messages": [response]
95
  }