Codemaster67 commited on
Commit
0d9ff86
·
verified ·
1 Parent(s): 6f6ed4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -11,10 +11,10 @@ from langchain_mcp_adapters.client import MultiServerMCPClient
11
  from langchain_google_genai import ChatGoogleGenerativeAI
12
  from langchain.agents import create_agent
13
  from langchain_core.messages import HumanMessage
14
- from langgraph.store.memory import InMemoryStore
15
 
16
- my_store = InMemoryStore()
17
 
 
18
 
19
  # --- GLOBAL STATE ---
20
  MCP_URL = "https://Codemaster67-ResearchPaperMCP.hf.space/sse"
@@ -85,7 +85,7 @@ async def initialize_agent(api_key: str = Form(...), model_name: str = Form(...)
85
  llm,
86
  mcp_tools,
87
  system_prompt = system_prompt,
88
- store=my_store
89
  )
90
 
91
  return {"status": "Success", "message": f"Agent initialized with {model_name}"}
@@ -97,6 +97,7 @@ async def initialize_agent(api_key: str = Form(...), model_name: str = Form(...)
97
  @app.post("/chat")
98
  async def chat(
99
  message: str = Form(...),
 
100
  file: Optional[UploadFile] = File(None)
101
  ):
102
  global agent_executor
@@ -116,7 +117,10 @@ async def chat(
116
 
117
  try:
118
  inputs = {"messages": [HumanMessage(content=message_content)]}
119
- response = await agent_executor.ainvoke(inputs)
 
 
 
120
 
121
  # --- NEW: PRINT TOOL CALLS ---
122
  for msg in response["messages"]:
 
11
  from langchain_google_genai import ChatGoogleGenerativeAI
12
  from langchain.agents import create_agent
13
  from langchain_core.messages import HumanMessage
14
+ from langgraph.checkpoint.memory import MemorySaver
15
 
 
16
 
17
+ memory_saver = MemorySaver()
18
 
19
  # --- GLOBAL STATE ---
20
  MCP_URL = "https://Codemaster67-ResearchPaperMCP.hf.space/sse"
 
85
  llm,
86
  mcp_tools,
87
  system_prompt = system_prompt,
88
+ checkpointer=memory_saver
89
  )
90
 
91
  return {"status": "Success", "message": f"Agent initialized with {model_name}"}
 
97
  @app.post("/chat")
98
  async def chat(
99
  message: str = Form(...),
100
+ session_id: str = Form("default_thread"),
101
  file: Optional[UploadFile] = File(None)
102
  ):
103
  global agent_executor
 
117
 
118
  try:
119
  inputs = {"messages": [HumanMessage(content=message_content)]}
120
+
121
+ # --- NEW: PASS THREAD ID IN CONFIG ---
122
+ config = {"configurable": {"thread_id": session_id}}
123
+ response = await agent_executor.ainvoke(inputs, config=config)
124
 
125
  # --- NEW: PRINT TOOL CALLS ---
126
  for msg in response["messages"]: