History Byclaw¶
简介¶
by-framework-history-byclaw 库提供了基于 Byclaw 的会话历史存储实现。
安装¶
核心组件¶
ByclawHistoryStore¶
from by_framework_history_byclaw import ByclawHistoryStore
store = ByclawHistoryStore(
redis_client=redis,
namespace="history:byclaw",
)
使用示例¶
from by_framework_history_byclaw import ByclawHistoryStore
# 初始化
store = ByclawHistoryStore(redis_client=redis)
# 保存消息
await store.save_message(
session_id="sess_123",
message_id="msg_456",
role="user",
content="Hello!",
)
# 获取历史
messages = await store.get_history(
session_id="sess_123",
limit=50,
)
# 清空历史
await store.clear_history(session_id="sess_123")
配置选项¶
| 参数 | 类型 | 描述 | 默认值 |
|---|---|---|---|
redis_client |
Redis |
Redis 客户端 | 必填 |
namespace |
str |
Key 命名空间 | "history:byclaw" |
max_messages |
int |
最大消息数 | 1000 |
ttl |
int |
过期时间(秒) | 86400 * 30 |