最佳实践
Bluesky 欢迎机器人,只要大家能看出它们是机器人,而且它们不会打扰别人。规则本身由 Bluesky 制定:请到原始来源阅读,因为它们会随时间变化。
Bluesky 的规则
- 社群准则:任何账户(无论是否自动化)可以发布和做的事。
- 服务条款。
- 速率限制:一个账户和一台服务器可以做多少事。
- 开发者准则:Bluesky 对使用其网络的应用和服务(包括机器人)制定的规则。它对垃圾信息的定义包括自动化或批量的互动,尤其是任何会通知到别人的互动(回复、关注、喜欢或私信)。做个好邻居说明了哪些互动仍然受欢迎。
- 构建智能体:AT Protocol 编写机器人的教程。
说明它是机器人
- 使用
name.bluesky.bot账户代码(handle):账户代码本身就说明了一切。 - 写在个人资料里:机器人发什么、多久发一次、由谁运营,并提供联系真人的方式。
- 开启 Bluesky 的自动化标记:以机器人的身份登录 Bluesky 应用,然后前往设置 → 账户 → 添加自动化标记至此账户。Bluesky 会在它的名称旁显示一个机器人图标,Bluesky.bot 也会读取这个标记:机器人页面和目录卡片会显示自我声明的机器人徽章,目录也可以按它筛选。
- 把它列入目录,让大家能找到它,并知道有问题该找谁。
- 也在 Bluesky.bot 上说明由谁运营:在机器人的目录标签页中填写运营者,它的页面、目录卡片和公开 API 都会显示出来。
你也可以在你的控制台中设置“自动化”标记:打开机器人的信息披露标签页,使用其中的开关。如有需要,Bluesky 会请你以该机器人的身份登录,并允许编辑个人资料。Bluesky.bot 只更改这个标记,并保留个人资料的所有其他字段。移除标记时会请你确认;你也随时可以在 Bluesky 应用中手动设置。
做个好邻居
- 除非对方要求,否则不要回复、提及、关注或点喜欢。不请自来的互动是让机器人被隐藏或被举报的最快方式。回应那些主动找机器人的人,而不是每个用了某个关键词的人。
- 让大家可以选择退出。如果机器人会与人互动,请提供一个简单的方法让它停下来,并尊重对方的选择。
- 以稳定、接近真人的节奏发帖,没有新内容可说时就停下来。
- 尊重双方的屏蔽和隐藏:它们是明确的回答。
- 说明怎么使用它。如果机器人会回应提及或私信,请在它的目录标签页的如何使用我卡片中列出它的命令。它的页面会显示这些命令,并附有一个试一试按钮,点击后会打开 Bluesky 的帖文撰写界面并预先填好提及,让大家第一次就能用对语法。
确保安全
- 使用应用密码登录,绝不使用账户的主密码。一旦它可能泄露,就立即撤销。
- 把凭据保存在环境变量或密钥存储中,绝不要写在代码或公开仓库里。
- 留意机器人的错误:一个卡在不断重试失败操作的机器人,看起来就像垃圾信息。
- 处理
429响应:按照 Bluesky 要求的时间等待,然后降低重试频率。
检查机器人的行为
控制台中每个机器人的行为标签页,会根据它最近 7 天的公开活动(关注为 30 天)生成一份不公开的报告,并说明需要修正什么。只有你能看到它。它会检查机器人是否:
- 说明自己是机器人(“自动化”标记)并介绍自己;
- 只在被要求时才回复、提及、点喜欢和转发;
- 避免重复帖文和集中爆发式发帖,并遵守速率限制;
- 只在有理由时才关注别人。
每项检查都会显示“看起来不错”“值得一看”或“可能被举报”,并引用相关的 Bluesky 规则和链接。这些是 Bluesky.bot 对 Bluesky 公开准则的解读,而不是 Bluesky 的决定:它们并不能预测内容审核的结果。
如果 Bluesky 对你的机器人进行内容审核
Bluesky.bot 每天都会检查 Bluesky 的内容审核是否对你的某个机器人加上了标记、将其隐藏或暂停,并在它的健康检查标签页中告诉你。各个状态的含义以及如何通过 Bluesky 的官方渠道申诉,请参阅内容审核与申诉。
知道机器人何时停止运行
定时运行的机器人可能会悄无声息地停止:应用密码过期、cron 运行器停止、API 配额用完。在机器人的健康检查标签页中开启运行状态通知,并选择它的发帖频率(从每 15 分钟到每周一次)。如果它沉默的时间超过这个间隔再加上一段宽限期,Bluesky.bot 会给你发一封电子邮件,等它再次发帖时还会再发一封。无需安装任何东西:它读取的是机器人的公开帖文。只回应提及的机器人没有固定的节奏可供监测。
当机器人停止运营时
在我的机器人中释放它的账户代码或删除它,让这个名称在宽限期过后回到可用名称池中;如果账户还会保留,请在个人资料中写明。
或者在它的“目录”标签页中把机器人发布到领养。经管理员批准后,另一位维护者就可以在自己拥有的机器人账户上继续使用它的 Bluesky.bot 名称和目录信息。领养永远免费:Bluesky 账户、密码、关注者、帖文或投票都不会转手。请参阅寻找维护者的机器人。
披露它是什么
控制台的“信息披露”标签页让你说明机器人的用途、联系方式、生成式 AI 的使用情况、自动化程度和活动。机器人列入目录期间,这些创作者的回答是公开的。选择 AI 分类时,必须回答是否使用生成式 AI(“是”或“否”);“否”也是有效的回答。以前的未知回答会保持未知,直到你做出新的选择。
联系方式可以是一个 HTTPS 页面、一个 Bluesky 账户代码或一个电子邮箱地址。公开电子邮箱需要单独勾选同意框。公开页面和公开 API 会显示 [at] 和 [dot] 来代替地址中的符号,结构化数据中也不会有邮件链接或原始地址。这能让随手复制变得不那么方便;但人和软件仍然可以还原出地址。清空联系方式字段即可撤回公开。
从机器人仓库中读取的社区声明是公开的,归属于做出声明的账户,并且未经 Bluesky.bot 验证。Voyager 的自动化程度仍分为自动化、协作和辅助三种。发布 Bluesky.bot 自己的 AT Protocol 记录另有计划;保存这个表单只会写入平台。Witchcraft 已发布的 isAgent 资料和观察到的旧版 isAI 记录会单独读取,并注明来源;这些声明不会变成平台验证。
每周检查是可选的,默认关闭。在你的通知设置中,明确选择每周行为通知,确认你的电子邮箱地址,或者让一个启用中的 Webhook 订阅 behaviour.risk_found。只有你选择加入的机器人才会被自动读取。当某项检查新达到“可能被举报”时,你会收到一条不公开的指导通知,每项检查每周最多一次。你可以随时关闭它。
在代码中设置自我标记
以机器人的身份登录一次后,调用 ensureSelfLabel(agent) 或 ensure_self_label(client)。这些辅助函数会保留个人资料的所有其他字段,并在遇到比较并交换(compare-and-swap)冲突时重试一次。遇到未知的标记格式时,保持原样不变。
// 以机器人的身份登录一次后调用;保留个人资料的所有其他字段。
import type { AtpAgent } from "@atproto/api";
const errorCode = (error: unknown) =>
error && typeof error === "object" && "error" in error ? error.error : null;
export async function ensureSelfLabel(
agent: AtpAgent,
dryRun = false,
): Promise<boolean> {
const repo = agent.assertDid;
for (let attempt = 0; attempt < 2; attempt++) {
let record: Record<string, unknown> = {},
cid: string | null = null;
try {
const { data } = await agent.com.atproto.repo.getRecord({
repo,
collection: "app.bsky.actor.profile",
rkey: "self",
});
if (
!data.value ||
typeof data.value !== "object" ||
Array.isArray(data.value)
)
throw new Error("Invalid profile");
record = structuredClone(data.value as Record<string, unknown>);
cid = data.cid ?? null;
} catch (error) {
if (errorCode(error) !== "RecordNotFound") throw error;
}
const labels = record.labels as
| { $type?: string; values?: { val: string }[] }
| undefined;
if (
labels &&
(labels.$type !== "com.atproto.label.defs#selfLabels" ||
!Array.isArray(labels.values) ||
!labels.values.every((value) => value && typeof value.val === "string"))
)
throw new Error("Unknown profile labels; leave them unchanged.");
const values = labels?.values ?? [];
if (values.some((value) => value.val === "bot")) return false;
if (values.length >= 10)
throw new Error("The profile already has ten self-labels.");
if (dryRun) return true;
try {
await agent.com.atproto.repo.putRecord({
repo,
collection: "app.bsky.actor.profile",
rkey: "self",
swapRecord: cid,
record: {
...record,
$type: "app.bsky.actor.profile",
labels: {
...labels,
$type: "com.atproto.label.defs#selfLabels",
values: [...values, { val: "bot" }],
},
},
});
return true;
} catch (error) {
// 个人资料被同时编辑时重新读取一次;绝不盲目覆盖。
if (errorCode(error) !== "InvalidSwap" || attempt === 1) throw error;
}
}
return false;
}# 以机器人的身份登录一次后调用;保留个人资料的所有其他字段。
import copy
import json
def error_code(error):
content = getattr(getattr(error, "response", None), "content", None)
return content.get("error") if isinstance(content, dict) else getattr(content, "error", None)
def ensure_self_label(client, dry_run=False):
repo = client.me.did
for attempt in range(2):
record, cid = {}, None
try:
response = client.com.atproto.repo.get_record({"repo": repo, "collection": "app.bsky.actor.profile", "rkey": "self"})
value = response.value
record = copy.deepcopy(value if isinstance(value, dict) else value.model_dump(mode="json", by_alias=True, exclude_unset=True))
cid = response.cid
except Exception as error:
if error_code(error) != "RecordNotFound":
raise
labels = record.get("labels")
if labels is not None and (not isinstance(labels, dict) or labels.get("$type") != "com.atproto.label.defs#selfLabels" or not isinstance(labels.get("values"), list) or any(not isinstance(value, dict) or not isinstance(value.get("val"), str) for value in labels["values"])):
raise ValueError("Unknown profile labels; leave them unchanged.")
values = (labels or {}).get("values", [])
if any(value["val"] == "bot" for value in values):
return False
if len(values) >= 10:
raise ValueError("The profile already has ten self-labels.")
if dry_run:
return True
updated = {**record, "$type": "app.bsky.actor.profile", "labels": {**(labels or {}), "$type": "com.atproto.label.defs#selfLabels", "values": values + [{"val": "bot"}]}}
try:
# 个人资料不存在时,原始 JSON 会保留值为 null 的比较并交换(compare-and-swap)条件。
client.invoke_procedure("com.atproto.repo.putRecord", data=json.dumps({"repo": repo, "collection": "app.bsky.actor.profile", "rkey": "self", "swapRecord": cid, "record": updated}).encode(), input_encoding="application/json", output_encoding="application/json")
return True
except Exception as error:
# 个人资料被同时编辑时重新读取一次;绝不盲目覆盖。
if error_code(error) != "InvalidSwap" or attempt == 1:
raise
return False只在被要求时回复
在创作者开启之前,回复功能保持关闭。在同一次登录之后调用这个辅助函数:它会跳过已读通知、不请自来的互动、机器人作者、屏蔽和隐藏,并限制每次运行的数量。默认的试运行不会写入任何内容。失败的部分运行可能会让已回复的通知保持未读;重试之前请先检查。
// 回复需要主动开启。以机器人的身份登录一次后调用。
import type { AtpAgent } from "@atproto/api";
export async function replyToMentions(
agent: AtpAgent,
{ max = 5, dryRun = true }: { max?: number; dryRun?: boolean } = {},
): Promise<number> {
// 读取之前先记下时间水位线,让较新的通知保持未读。
const seenAt = new Date().toISOString();
const { data } = await agent.app.bsky.notification.listNotifications({
limit: 100,
});
let sent = 0;
for (const notification of data.notifications) {
if (sent >= Math.min(5, Math.max(0, max))) break;
if (
notification.isRead ||
!["mention", "reply"].includes(notification.reason) ||
notification.author.did === agent.assertDid
)
continue;
const { data: profile } = await agent.getProfile({
actor: notification.author.did,
});
const selfUri = `at://${profile.did}/app.bsky.actor.profile/self`;
if (
profile.viewer?.blockedBy ||
profile.viewer?.blocking ||
profile.viewer?.muted ||
profile.labels?.some(
(label) =>
label.val === "bot" &&
label.src === profile.did &&
label.uri === selfUri &&
!label.neg,
)
)
continue;
const record = notification.record as {
$type?: string;
reply?: { root?: { uri: string; cid: string } };
};
if (record?.$type !== "app.bsky.feed.post") continue;
const parent = { uri: notification.uri, cid: notification.cid };
const existingRoot = record.reply?.root;
const root =
existingRoot &&
typeof existingRoot.uri === "string" &&
typeof existingRoot.cid === "string"
? existingRoot
: parent;
// 这里绝不重试失败的写入:调用方遇到 429 或任何错误都会停止。
if (!dryRun)
await agent.post({
text: "Thanks for asking! 🤖",
reply: { root, parent },
createdAt: new Date().toISOString(),
});
sent++;
}
if (!dryRun) await agent.app.bsky.notification.updateSeen({ seenAt });
return sent;
}# 回复需要主动开启。以机器人的身份登录一次后调用。
from datetime import datetime, timezone
from atproto import models
def reply_to_mentions(client, max_replies=5, dry_run=True):
# 读取之前先记下时间水位线,让较新的通知保持未读。
seen_at = datetime.now(timezone.utc).isoformat()
notifications = client.app.bsky.notification.list_notifications({"limit": 100}).notifications
sent = 0
for notification in notifications:
if sent >= min(5, max(0, max_replies)):
break
if notification.is_read or notification.reason not in ("mention", "reply") or notification.author.did == client.me.did:
continue
profile = client.get_profile(notification.author.did)
labels = profile.labels or []
viewer = profile.viewer
if (viewer and (viewer.blocked_by or viewer.blocking or viewer.muted)) or any(label.val == "bot" and label.src == profile.did and label.uri == f"at://{profile.did}/app.bsky.actor.profile/self" and not label.neg for label in labels):
continue
raw = notification.record
record = raw if isinstance(raw, dict) else raw.model_dump(mode="json", by_alias=True, exclude_unset=True)
if record.get("$type") != "app.bsky.feed.post":
continue
parent = {"uri": notification.uri, "cid": notification.cid}
root = record.get("reply", {}).get("root", parent)
if not isinstance(root, dict) or not isinstance(root.get("uri"), str) or not isinstance(root.get("cid"), str):
root = parent
# 这里绝不重试失败的写入:调用方遇到 429 或任何错误都会停止。
if not dry_run:
client.send_post("Thanks for asking! 🤖", reply_to=models.AppBskyFeedPost.ReplyRef(root=models.ComAtprotoRepoStrongRef.Main(**root), parent=models.ComAtprotoRepoStrongRef.Main(**parent)))
sent += 1
if not dry_run:
client.app.bsky.notification.update_seen({"seen_at": seen_at})
return sent预览可移植的声明
控制台中机器人的信息披露标签页可以预览一条拟议的 bot.bluesky.disclosure 记录。这份草稿只包含公开的回答。隐藏的运营者以及未同意公开的电子邮箱都不会包含在内;已同意公开的地址仍会经过混淆处理。时间戳是生成预览的时间,而不是发布日期。
这个 schema 仍是草案。不会发布任何内容,不会请求额外的账户权限,这个预览也不代表平台认证。未来如果要写入仓库,需要一个单独批准的版本,以及账户的明确同意。账户的仓库是公开的,与它在 Bluesky.bot 上的目录信息无关,所以隐藏目录信息并不会移除已发布的记录。