Akasha 代理接入技能
将新代理连接到 Akasha 的完整指南。
步骤 1:获取凭据
选项 A:API 密钥(推荐用于代理)
请管理员通过仪表板或 API 创建密钥:
curl -sk -X POST "$AKASHA_URL/api/v1/admin/keys" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "my-new-agent",
"namespaces": ["memory/working/my-new-agent/**", "memory/semantic/**", "memory/episodic/**"],
"role": "agent"
}'
保存返回的 key — 它只显示一次。
选项 B:JWT 令牌(用户会话)
TOKEN=$(curl -sk -X POST "$AKASHA_URL/api/v1/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"my-user","password":"my-password"}' \
| python3 -c "import json,sys; print(json.load(sys.stdin)['token'])")
步骤 2:选择你的 SDK
Python(gRPC — 性能推荐)
pip install akasha-client
from akasha import AkashaClient
with AkashaClient("localhost:50051") as client:
# 写入
client.put("memory/working/my-agent/status", {"state": "ready"})
# 读取
record = client.get("memory/working/my-agent/status")
print(record.value) # {"state": "ready"}
# 查询
results = client.query("memory/working/**")
Python(HTTP — 更简单,无需 proto 编译)
from akasha import AkashaHttpClient
client = AkashaHttpClient(
"https://localhost:7777",
verify_ssl=False # 用于自签名 TLS 证书
)
client.login("my-user", "my-password")
# 或者使用 API 密钥:
# client = AkashaHttpClient("https://...", api_key="ak_my-agent_xxx")
client.put("memory/working/my-agent/status", {"state": "ready"})
Node.js
const { AkashaClient } = require('@akasha/client');
const client = new AkashaClient({
address: 'localhost:50051',
// 或者 HTTP:
// url: 'https://localhost:7777',
// token: 'ak_my-agent_xxx'
});
await client.put('memory/working/my-agent/status', { state: 'ready' });
const record = await client.get('memory/working/my-agent/status');
原生 HTTP(任何语言)
# 在代理的环境中设置这些变量
export AKASHA_URL="https://localhost:7777"
export AKASHA_TOKEN="ak_my-agent_xxxxxxxxxxxx"
# 写入
curl -sk -X POST "$AKASHA_URL/api/v1/records/memory/working/my-agent/status" \
-H "Authorization: Bearer $AKASHA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"value": {"state": "ready"}}'
# 读取
curl -sk "$AKASHA_URL/api/v1/records/memory/working/my-agent/status" \
-H "Authorization: Bearer $AKASHA_TOKEN"
步骤 3:定义你的命名空间策略
根据代理的角色选择路径结构:
研究代理
memory/working/<agent-id>/task ← 当前任务上下文
memory/episodic/research/<finding-id> ← 原始发现
memory/semantic/research/<insight> ← 已确认的知识
代码代理
memory/working/<agent-id>/context ← 当前代码上下文
memory/procedural/coding/<pattern> ← 可复用的代码模式
memory/semantic/architecture/<decision> ← 架构决策
监控代理
memory/working/<agent-id>/alerts ← 活跃告警
memory/episodic/incidents/<incident-id> ← 事件时间线
memory/semantic/runbooks/<procedure> ← 已验证的修复步骤
多代理团队
shared/ ← 团队范围的共享状态
├── config/<setting> ← 共享配置
├── tasks/<task-id> ← 任务分配
└── results/<task-id> ← 任务结果
memory/working/<agent-id>/ ← 每个代理的私有临时存储
步骤 4:将 Akasha 添加到系统提示
将此块添加到代理的系统提示中(根据你的领域调整):
## 共享内存(Akasha)
你连接到一个共享知识库。用它来记忆和分享。
### 写入:POST /api/v1/records/<path>
请求体:{"value": <json>, "ttl_secs": <可选>}
### 读取:GET /api/v1/records/<path>
### 搜索:GET /api/v1/query?pattern=<glob-模式>
### 信号:POST /api/v1/pheromones/<trail>
请求体:{"signal_type":"discovery","message":"...","intensity":0.8}
认证头:Authorization: Bearer <你的令牌>
基础 URL:<你的 akasha-url>
使用工作记忆(ttl_secs)存储临时状态。
使用语义记忆存储已确认的知识。
在开始新工作之前检查信号。
步骤 5:验证连接
# 健康检查(无需认证)
curl -sk $AKASHA_URL/api/v1/health
# 写入测试
curl -sk -X POST "$AKASHA_URL/api/v1/records/test/hello" \
-H "Authorization: Bearer $AKASHA_TOKEN" \
-d '{"value": {"message": "Agent connected!"}}'
# 读取测试
curl -sk "$AKASHA_URL/api/v1/records/test/hello" \
-H "Authorization: Bearer $AKASHA_TOKEN"
# 清理
curl -sk -X DELETE "$AKASHA_URL/api/v1/records/test/hello" \
-H "Authorization: Bearer $AKASHA_TOKEN"
检查清单
- 已获取 API 密钥或 JWT 令牌
- 已安装 SDK(Python/Node/HTTP)
- 已定义命名空间策略
- 系统提示已更新,包含 Akasha 指令
- 已验证连接(健康 → 写入 → 读取 → 删除)
- 工作记忆使用 TTL 自动过期