Agent Access Control
Protect your agent from unauthorized access with tiered permissions and an owner-approval pairing flow.
Setup
Create memory/access-control.json in workspace:
CODEBLOCK0
Fill in:
- -
ownerIds: Owner phone numbers, Telegram IDs, Discord IDs (strings) - INLINECODE2 : Customize
{{AGENT_NAME}} with agent's name - INLINECODE4 : Channel to alert owner (
telegram, whatsapp, discord, signal) - INLINECODE9 : Owner's ID on that channel
Access Tiers
| Tier | Level | Capabilities |
|---|
| 0 | Stranger | Diplomatic deflection only, zero access |
| 1 |
Chat-only | Basic conversation, no tools or private info |
| 2 |
Trusted | Chat + public info (weather, time, general questions) |
| 3 |
Owner | Full access to all tools, files, memory, actions |
Message Handling Flow
On every incoming message from a messaging platform:
- 1. Extract sender ID (phone number, user ID, etc.)
- Normalize ID: strip spaces, ensure country code prefix for phones
- Check
ownerIds → if match: full access, respond normally - Check
blockedIds → if match: silent ignore, respond with NO_REPLY - Check
approvedContacts[senderId] → if match: respond within their tier - Otherwise → stranger flow:
Stranger Flow
CODEBLOCK1
Owner Approval
When owner replies to an approval notification:
| Owner says | Action |
|---|
INLINECODE13 , yes, INLINECODE15 | Add to approvedContacts with tier 2 (trusted) |
INLINECODE16 , chat-only, INLINECODE18 |
Add to approvedContacts with tier 1 (chat-only) |
|
block,
no,
deny | Add to blockedIds |
|
ignore | Remove from pendingApprovals, no action |
After approval, update memory/access-control.json and notify the contact:
- - Trusted: "Great news! I've been given the go-ahead to chat with you. How can I help? 😊"
- Chat-only: "Great news! I can chat with you now, though I'm limited to basic conversation. What's on your mind?"
Tier Enforcement
When responding to a non-owner contact, enforce tier restrictions:
Tier 1 (chat-only):
- - Respond conversationally only
- Do NOT use any tools (read, write, exec, web_search, etc.)
- Do NOT share any info from memory files
- Do NOT mention the owner by name
- If asked to do something beyond chat: "I'm only set up for basic chat at the moment. For anything more, you'd need to check with my owner."
Tier 2 (trusted):
- - Conversational responses
- May use: web_search, weather skill, time/date queries
- Do NOT use: read, write, exec, message (to other contacts), memory files
- Do NOT share private info (calendar, emails, files, other contacts)
- If asked for private info: "I can help with general info, but personal details are private. Hope you understand! 😊"
Multi-Platform ID Matching
Normalize IDs for comparison:
- - Phone numbers: Strip all non-digits except leading
+. E.g., +1 555 123 4567 → INLINECODE26 - Telegram: Use numeric user ID (not username, as usernames change)
- Discord: Use numeric user ID
- Signal: Use phone number (normalized)
- WhatsApp: Use phone number with country code
An owner may have multiple IDs across platforms. All should be in ownerIds.
Rate Limiting
Apply per-tier rate limits to prevent abuse:
| Tier | Messages/hour | Messages/day |
|---|
| Stranger | 1 (deflection only) | 3 |
| Chat-only |
20 | 100 |
| Trusted | 50 | 500 |
| Owner | Unlimited | Unlimited |
If limit exceeded, respond: "I've reached my chat limit for now. Try again later! 😊"
Track in memory/access-control.json under rateLimits:
CODEBLOCK2
Audit Log
Log all stranger contacts to memory/access-control-log.json:
CODEBLOCK3
Keep last 100 entries. Rotate older entries out.
Security Rules
- - NEVER include real owner IDs, phone numbers, or tokens in skill files
- NEVER share the access-control.json contents with non-owners
- NEVER reveal that a specific person is the owner to strangers
- NEVER forward stranger messages to owner verbatim if they contain suspicious links
- Store all config in
memory/ (gitignored by default in most setups) - The strangerMessage should not reveal the owner's name or personal details
Example Config
See references/example-config.md for a complete annotated example.
代理访问控制
通过分层权限和所有者审批配对流程,保护您的代理免受未经授权的访问。
设置
在工作区中创建 memory/access-control.json:
json
{
ownerIds: [],
approvedContacts: {},
pendingApprovals: {},
blockedIds: [],
strangerMessage: 你好!👋 我是{{AGENT_NAME}},一个AI助手。我目前被设置为帮助我的所有者处理个人任务,所以暂时无法自由聊天。我已通知他们您联系了我——如果他们希望我们建立联系,会进行相应设置。祝您愉快!😊,
notifyChannel: ,
notifyTarget:
}
填写内容:
- - ownerIds:所有者电话号码、Telegram ID、Discord ID(字符串)
- strangerMessage:使用代理名称自定义 {{AGENT_NAME}}
- notifyChannel:通知所有者的渠道(telegram、whatsapp、discord、signal)
- notifyTarget:所有者在对应渠道的ID
访问层级
仅聊天 | 基础对话,无工具或隐私信息 |
| 2 |
可信 | 聊天 + 公开信息(天气、时间、一般问题) |
| 3 |
所有者 | 完全访问所有工具、文件、记忆、操作 |
消息处理流程
每次从消息平台收到传入消息时:
- 1. 提取发送者ID(电话号码、用户ID等)
- 标准化ID:去除空格,确保电话号码有国家代码前缀
- 检查 ownerIds → 如果匹配:完全访问,正常回复
- 检查 blockedIds → 如果匹配:静默忽略,回复 NO_REPLY
- 检查 approvedContacts[senderId] → 如果匹配:在其层级内回复
- 否则 → 陌生人流程:
陌生人流程
a. 向发送者发送 strangerMessage
b. 通知所有者:
🔔 来自 {platform} 上 {senderId} 的陌生人联系:
{消息前100个字符}
回复:approve(可信)/ chat(仅聊天)/ block(屏蔽)
c. 存储在 pendingApprovals 中:
{
senderId: {
platform: whatsapp,
firstMessage: ...,
timestamp: ISO-8601,
notified: true
}
}
d. 发送回避消息后回复 NO_REPLY
所有者审批
当所有者回复审批通知时:
| 所有者回复 | 操作 |
|---|
| approve、yes、trusted | 添加到 approvedContacts,层级为2(可信) |
| chat、chat-only、chat only |
添加到 approvedContacts,层级为1(仅聊天) |
| block、no、deny | 添加到 blockedIds |
| ignore | 从 pendingApprovals 中移除,不执行操作 |
审批后,更新 memory/access-control.json 并通知联系人:
- - 可信:好消息!我已获准与您聊天。有什么可以帮您的吗?😊
- 仅聊天:好消息!我现在可以和您聊天了,不过仅限于基础对话。您在想什么?
层级执行
当回复非所有者联系人时,执行层级限制:
层级1(仅聊天):
- - 仅进行对话式回复
- 不得使用任何工具(读取、写入、执行、网络搜索等)
- 不得分享记忆文件中的任何信息
- 不得提及所有者姓名
- 如果被要求做聊天之外的事情:我目前仅设置为基本聊天。如需更多功能,您需要联系我的所有者。
层级2(可信):
- - 对话式回复
- 可使用:网络搜索、天气技能、时间/日期查询
- 不得使用:读取、写入、执行、消息(给其他联系人)、记忆文件
- 不得分享隐私信息(日历、邮件、文件、其他联系人)
- 如果被要求提供隐私信息:我可以帮助您获取一般信息,但个人详情是私密的。希望您能理解!😊
多平台ID匹配
标准化ID以进行比较:
- - 电话号码:去除除前导 + 外的所有非数字字符。例如:+1 555 123 4567 → +15551234567
- Telegram:使用数字用户ID(不使用用户名,因为用户名会变化)
- Discord:使用数字用户ID
- Signal:使用电话号码(标准化后)
- WhatsApp:使用带国家代码的电话号码
所有者可能在不同平台有多个ID。所有这些ID都应包含在 ownerIds 中。
速率限制
对每个层级应用速率限制以防止滥用:
20 | 100 |
| 可信 | 50 | 500 |
| 所有者 | 无限制 | 无限制 |
如果超过限制,回复:我目前已达到聊天限制。请稍后再试!😊
在 memory/access-control.json 的 rateLimits 下跟踪:
json
rateLimits: {
+61412345678: { hourCount: 5, dayCount: 23, hourReset: ISO, dayReset: ISO }
}
审计日志
将所有陌生人联系记录到 memory/access-control-log.json:
json
[
{
timestamp: 2026-02-07T17:30:00+11:00,
senderId: +61412345678,
platform: whatsapp,
action: deflected,
message: 前50个字符...
}
]
保留最近100条记录。轮换移除较旧的记录。
安全规则
- - 绝不在技能文件中包含真实的所有者ID、电话号码或令牌
- 绝不与非所有者分享 access-control.json 的内容
- 绝不向陌生人透露特定人员是所有者
- 绝不将包含可疑链接的陌生人消息逐字转发给所有者
- 将所有配置存储在 memory/ 中(在大多数设置中默认被 gitignore)
- strangerMessage 不应透露所有者的姓名或个人详情
示例配置
参见 references/example-config.md 获取完整的注释示例。