Akasha 代理入門技能
將新代理連接到 Akasha 的完整指南。
第一步:取得憑證
選項 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(使用者會話)
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'])")
第二步:選擇你的 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"
第三步:定義你的命名空間策略
根據代理的角色選擇路徑結構:
研究代理
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>/ ← 每個代理的私有暫存區
第四步:將 Akasha 加入你的系統提示詞
將以下區塊加入代理的系統提示詞(根據你的領域調整):
## 共享記憶 (Akasha)
你已連接到一個共享知識庫。使用它來記憶和分享。
### 寫入:POST /api/v1/records/<path>
Body: {"value": <json>, "ttl_secs": <optional>}
### 讀取:GET /api/v1/records/<path>
### 搜尋:GET /api/v1/query?pattern=<glob-pattern>
### 信號:POST /api/v1/pheromones/<trail>
Body: {"signal_type":"discovery","message":"...","intensity":0.8}
Auth header: Authorization: Bearer <your-token>
Base URL: <your-akasha-url>
使用工作記憶 (ttl_secs) 來儲存暫存狀態。
使用語意記憶來儲存確認的知識。
開始新工作前先檢查信號。
第五步:驗證連線
# 健康檢查(無需認證)
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 token
- 安裝 SDK (Python/Node/HTTP)
- 定義命名空間策略
- 使用 Akasha 指令更新系統提示詞
- 驗證連線(健康檢查 → 寫入 → 讀取 → 刪除)
- 工作記憶使用 TTL 自動過期