This commit is contained in:
@@ -12,18 +12,21 @@ class ThreadHistoryService:
|
||||
def __init__(self, checkpointer):
|
||||
self.checkpointer = checkpointer
|
||||
|
||||
async def get_user_threads(self, user_id: str, limit: int = 50) -> List[Dict[str, Any]]:
|
||||
async def get_user_threads(self, user_id: str, limit: int = 4) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
获取指定用户的所有线程摘要信息
|
||||
|
||||
Args:
|
||||
user_id: 用户 ID
|
||||
limit: 返回数量限制
|
||||
limit: 返回数量限制(强制最多4条)
|
||||
|
||||
Returns:
|
||||
线程列表,每个包含 thread_id, last_updated, summary, message_count
|
||||
"""
|
||||
try:
|
||||
# 强制限制最多4条
|
||||
actual_limit = min(limit, 4)
|
||||
|
||||
# 查询 checkpoints 表获取用户的线程列表
|
||||
async with self.checkpointer.conn.cursor() as cur:
|
||||
# 在较新的 LangGraph 版本中,AsyncPostgresSaver 创建的 checkpoints 表
|
||||
@@ -40,7 +43,7 @@ class ThreadHistoryService:
|
||||
ORDER BY last_updated DESC
|
||||
LIMIT %s
|
||||
"""
|
||||
await cur.execute(query, (user_id, limit))
|
||||
await cur.execute(query, (user_id, actual_limit))
|
||||
rows = await cur.fetchall()
|
||||
|
||||
threads = []
|
||||
|
||||
Reference in New Issue
Block a user