fix: use sync get_state() for SqliteSaver compatibility (#519)
SqliteSaver does not support async methods like aget_state(). Use asyncio.to_thread() to run the sync get_state() call from async context, maintaining compatibility with the existing sync graph invocations. Closes #509
This commit is contained in:
parent
c4ed1b18ec
commit
98eb6ed202
1 changed files with 7 additions and 2 deletions
|
|
@ -1,11 +1,16 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from langchain_core.runnables import RunnableConfig
|
from langchain_core.runnables import RunnableConfig
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
async def get_session_message_count(graph, session_id: str) -> int:
|
async def get_session_message_count(graph, session_id: str) -> int:
|
||||||
"""Get message count from LangGraph state, returns 0 on error."""
|
"""Get message count from LangGraph state, returns 0 on error."""
|
||||||
try:
|
try:
|
||||||
thread_state = await graph.aget_state( # async version
|
# Use sync get_state() in a thread (SqliteSaver doesn't support async)
|
||||||
config=RunnableConfig(configurable={"thread_id": session_id})
|
thread_state = await asyncio.to_thread(
|
||||||
|
graph.get_state,
|
||||||
|
config=RunnableConfig(configurable={"thread_id": session_id}),
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
thread_state
|
thread_state
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue