方法 | URI | 功能说明 |
---|---|---|
GET | /api/v0/checkpoint/direct/stats |
获取Checkpoint统计信息 |
GET | /api/v0/checkpoint/direct/stats?user_id={user_id} |
获取指定用户的Checkpoint统计信息 |
POST | /api/v0/checkpoint/direct/cleanup |
清理Checkpoint数据 |
React Agent Checkpoint管理API提供了对LangGraph Agent运行过程中产生的checkpoint数据进行管理和监控的功能。这些API通过直接操作Redis数据库,实现对checkpoint的统计查询和清理操作,不依赖Agent实例运行。
API名称 | 路由 | 方法 | 使用目的 |
---|---|---|---|
获取Checkpoint统计 | /api/v0/checkpoint/direct/stats |
GET | 查看系统中checkpoint的统计信息,包括用户数量、线程数量、checkpoint总数等 |
清理Checkpoint | /api/v0/checkpoint/direct/cleanup |
POST | 清理过期的checkpoint数据,支持全局、用户级、线程级的清理操作 |
API路由: GET /api/v0/checkpoint/direct/stats
使用目的: 获取系统或指定用户的checkpoint统计信息,用于监控数据量和存储状态。
user_id
: 指定用户ID,获取特定用户的统计信息# 获取系统全部统计信息
curl http://localhost:8084/api/v0/checkpoint/direct/stats
# 获取指定用户统计信息
curl "http://localhost:8084/api/v0/checkpoint/direct/stats?user_id=wang1"
系统全部统计信息:
{
"code": 200,
"success": true,
"message": "获取系统checkpoint统计成功",
"data": {
"operation_type": "system_stats",
"total_users": 2, // 系统总用户数
"total_threads": 4, // 系统总线程数
"total_checkpoints": 132, // 系统总checkpoint数
"users": [ // 用户详细信息列表
{
"user_id": "wang1", // 用户ID
"thread_count": 3, // 用户线程数
"total_checkpoints": 116, // 用户checkpoint总数
"threads": [ // 线程详细信息
{
"thread_id": "wang1:20250729235038043",
"checkpoint_count": 36 // 线程checkpoint数量
}
// ... 更多线程
]
}
// ... 更多用户
],
"timestamp": "2025-01-31T10:30:00" // 统计时间戳
}
}
指定用户统计信息:
{
"code": 200,
"success": true,
"message": "获取用户wang1统计成功",
"data": {
"operation_type": "user_stats",
"user_id": "wang1", // 目标用户ID
"thread_count": 3, // 用户线程数
"total_checkpoints": 116, // 用户checkpoint总数
"threads": [ // 按checkpoint数量降序排列
{
"thread_id": "wang1:20250801171843665",
"checkpoint_count": 64
},
{
"thread_id": "wang1:20250729235038043",
"checkpoint_count": 36
},
{
"thread_id": "wang1:20250731141657916",
"checkpoint_count": 16
}
],
"timestamp": "2025-01-31T10:30:00"
}
}
API路由: POST /api/v0/checkpoint/direct/cleanup
使用目的: 清理过期的checkpoint数据,释放Redis存储空间,每个线程保留最近N个checkpoint。
请求体参数(JSON格式):
参数名 | 类型 | 必需 | 默认值 | 说明 |
---|---|---|---|---|
keep_count |
int | 否 | 10 | 每个线程保留的checkpoint数量 |
user_id |
string | 否 | - | 指定要清理的用户ID |
thread_id |
string | 否 | - | 指定要清理的线程ID |
参数逻辑:
user_id
:清理指定用户的所有线程thread_id
:清理指定的线程user_id
和thread_id
同时存在:以thread_id
为准# 清理所有线程,每个保留10个checkpoint
curl -X POST http://localhost:8084/api/v0/checkpoint/direct/cleanup \
-H "Content-Type: application/json" \
-d '{"keep_count": 10}'
# 清理用户wang1的所有线程,每个保留5个checkpoint
curl -X POST http://localhost:8084/api/v0/checkpoint/direct/cleanup \
-H "Content-Type: application/json" \
-d '{"user_id": "wang1", "keep_count": 5}'
# 清理指定线程,保留8个checkpoint
curl -X POST http://localhost:8084/api/v0/checkpoint/direct/cleanup \
-H "Content-Type: application/json" \
-d '{"thread_id": "wang1:20250729235038043", "keep_count": 8}'
{
"code": 200,
"success": true,
"message": "Checkpoint清理完成",
"data": {
"operation_type": "cleanup_all", // 操作类型:cleanup_all|cleanup_user|cleanup_thread
"target": "all", // 操作目标:all|用户ID|线程ID
"keep_count": 10, // 保留数量
"total_processed": 15, // 处理的线程总数
"total_deleted": 45, // 删除的checkpoint总数
"details": { // 详细处理结果
"wang1:20250729235038043": {
"original_count": 36, // 原始checkpoint数量
"deleted_count": 26, // 删除的checkpoint数量
"remaining_count": 10, // 剩余checkpoint数量
"status": "success" // 处理状态
},
"wang1:20250731141657916": {
"original_count": 16,
"deleted_count": 6,
"remaining_count": 10,
"status": "success"
}
// ... 更多线程处理结果
},
"timestamp": "2025-01-31T10:30:00" // 操作时间戳
}
}
{
"code": 500,
"success": false,
"message": "请求处理失败",
"data": {
"response": "具体错误信息",
"error_type": "REDIS_CONNECTION_ERROR", // 错误类型
"timestamp": "2025-01-31T10:30:00"
}
}
错误类型 | 说明 |
---|---|
REDIS_CONNECTION_ERROR |
Redis连接失败 |
INVALID_THREAD_ID |
线程ID格式错误 |
USER_NOT_FOUND |
指定用户不存在 |
DELETE_FAILED |
删除checkpoint操作失败 |
# 定期检查系统checkpoint数据量
curl http://localhost:8084/api/v0/checkpoint/direct/stats
# 检查特定用户的数据量
curl "http://localhost:8084/api/v0/checkpoint/direct/stats?user_id=wang1"
# 系统维护:清理所有过期数据
curl -X POST http://localhost:8084/api/v0/checkpoint/direct/cleanup \
-H "Content-Type: application/json" \
-d '{"keep_count": 10}'
# 用户维护:清理特定用户数据
curl -X POST http://localhost:8084/api/v0/checkpoint/direct/cleanup \
-H "Content-Type: application/json" \
-d '{"user_id": "wang1", "keep_count": 5}'
# 检查问题线程的checkpoint数量
curl "http://localhost:8084/api/v0/checkpoint/direct/stats?user_id=problem_user"
# 清理问题线程的数据
curl -X POST http://localhost:8084/api/v0/checkpoint/direct/cleanup \
-H "Content-Type: application/json" \
-d '{"thread_id": "problem_user:20250729235038043", "keep_count": 3}'
该文档提供了React Agent Checkpoint API的完整使用指南,帮助用户有效管理和维护checkpoint数据。