diff --git a/api/routers/chat.py b/api/routers/chat.py index f4523be..8abe669 100644 --- a/api/routers/chat.py +++ b/api/routers/chat.py @@ -190,8 +190,10 @@ async def get_session(session_id: str): raise HTTPException(status_code=404, detail="Session not found") # Get session state from LangGraph to retrieve messages - thread_state = await chat_graph.aget_state( - config=RunnableConfig(configurable={"thread_id": full_session_id}) + # Use sync get_state() in a thread since SqliteSaver doesn't support async + thread_state = await asyncio.to_thread( + chat_graph.get_state, + config=RunnableConfig(configurable={"thread_id": full_session_id}), ) # Extract messages from state @@ -348,8 +350,10 @@ async def execute_chat(request: ExecuteChatRequest): ) # Get current state - current_state = await chat_graph.aget_state( - config=RunnableConfig(configurable={"thread_id": full_session_id}) + # Use sync get_state() in a thread since SqliteSaver doesn't support async + current_state = await asyncio.to_thread( + chat_graph.get_state, + config=RunnableConfig(configurable={"thread_id": full_session_id}), ) # Prepare state for execution diff --git a/api/routers/source_chat.py b/api/routers/source_chat.py index 779657b..9b7fa20 100644 --- a/api/routers/source_chat.py +++ b/api/routers/source_chat.py @@ -231,8 +231,10 @@ async def get_source_chat_session( ) # Get session state from LangGraph to retrieve messages - thread_state = await source_chat_graph.aget_state( - config=RunnableConfig(configurable={"thread_id": full_session_id}) + # Use sync get_state() in a thread since SqliteSaver doesn't support async + thread_state = await asyncio.to_thread( + source_chat_graph.get_state, + config=RunnableConfig(configurable={"thread_id": full_session_id}), ) # Extract messages from state @@ -416,8 +418,10 @@ async def stream_source_chat_response( """Stream the source chat response as Server-Sent Events.""" try: # Get current state - current_state = await source_chat_graph.aget_state( - config=RunnableConfig(configurable={"thread_id": session_id}) + # Use sync get_state() in a thread since SqliteSaver doesn't support async + current_state = await asyncio.to_thread( + source_chat_graph.get_state, + config=RunnableConfig(configurable={"thread_id": session_id}), ) # Prepare state for execution