Livestreaming to ATProtocol 是一份指南,用于借助 Letta Code hooks 将智能体的运行情况实时发布到 ATProtocol 集合中,从而实现公开、可观察的 AI 系统。
用途
该技能适用于以下场景:
- 搭建透明的 AI 运行(“玻璃盒”)。
- 公开广播工具调用、响应与推理过程。
- 在 ATProtocol 上构建可观察的 AI 系统。
架构
发布流程由两个钩子组成:
- PostToolUse 钩子 → network.comind.activity(工具调用)
- Stop 钩子 → 轮询 Letta API → network.comind.response(消息)以及 network.comind.reasoning(思考过程)
设置步骤
- 创建 hooks 目录:
mkdir -p hooks
-
活动钩子(PostToolUse):创建 hooks/livestream.py,用于将工具调用发布到 ATProtocol。要点包括:只使用 description 字段,绝不使用原始命令(出于安全考虑);对密钥应用脱敏模式;跳过噪声命令(如状态检查等)。完整实现见 references/livestream.py。
-
响应钩子(Stop):创建 hooks/publish-response.py,轮询 Letta API 获取消息并发布。要点包括:向 Letta API 查询最近的 assistant_message 和 reasoning_message;跟踪已发布的 ID 以避免重复;发布前应用脱敏;assistant_message 使用 content 字段;reasoning_message 使用 reasoning 字段。完整实现见 references/publish-response.py。
-
配置钩子:创建 .letta/settings.json,内容如下:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash|Edit|Write|Task",
"hooks": [
{
"type": "command",
"command": "cd /path/to/project && uv run python hooks/livestream.py"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "cd /path/to/project && uv run python hooks/publish-response.py"
}
]
}
]
}
}
安全
脱敏模式:发布前始终对密钥进行脱敏,示例:
REDACT_PATTERNS = [
(r'[A-Za-z_]*API_KEY[=:]\s*\S+', '[REDACTED]'),
(r'[A-Za-z_]*PASSWORD[=:]\s*\S+', '[REDACTED]'),
(r'Bearer\s+\S+', 'Bearer [REDACTED]'),
(r'sk-[A-Za-z0-9]+', '[REDACTED]'),
(r'ghp_[A-Za-z0-9]+', '[REDACTED]'),
]
命令仅用描述:绝不发布原始命令内容,只使用 Bash 工具调用中的 description 字段。
集合
- network.comind.activity:工具调用,记录类型 {tool, summary, createdAt}。
- network.comind.response:助手消息,记录类型 {content, createdAt}。
- network.comind.reasoning:思考过程,记录类型 {content, createdAt}。
查询直播流
# Activity
curl "https://your-pds/xrpc/com.atproto.repo.listRecords?repo=YOUR_DID&collection=network.comind.activity"
# Responses
curl "https://your-pds/xrpc/com.atproto.repo.listRecords?repo=YOUR_DID&collection=network.comind.response"
# Reasoning
curl "https://your-pds/xrpc/com.atproto.repo.listRecords?repo=YOUR_DID&collection=network.comind.reasoning"
环境变量
运行时环境需要:
- LETTA_API_KEY - 用于轮询消息
- LETTA_AGENT_ID - 你的智能体 ID
.env 中需要:
- ATPROTO_PDS - 你的 PDS URL
- ATPROTO_DID - 你的 DID
- ATPROTO_HANDLE - 你的 handle
- ATPROTO_APP_PASSWORD - 用于发布的 App 密码
限制
资料未提供关于收费、价格、平台兼容范围、性能表现或效果验证的信息。