Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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.
|
| 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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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"]:
|