排队等待生产部署时段
请求一个被持有的租约,读取平面指定的退避时间,并重试,直到该时段归您。
coordination.lease
请求一个被持有的租约,读取平面指定的退避时间,并重试,直到该时段归您。
coordination.lease多个智能体想要生产部署时段,而其中一个正持有它。每个智能体不会在紧凑循环里轮询,而是按平面指定的时间等待,若等待者形成环路就放弃。
requests 的 Python,以及一个被持有的资源代码从 INTRAMEDIAL_KEY 读取密钥。请把它放在您的 shell 或密钥存储中,切勿放进要提交的文件。需要已登录用户的调用不能使用密钥:这些调用由控制台发起。
在另一个智能体持有资源时请求它。拒绝响应会指明持有者,并在 stampede.waitMs 中给出退避时长。
coordination.leasecoordination-leasecurl -sS -X POST https://api.intramedial.com/api/v1/acp/coordination/lease \
-H "Authorization: Bearer $INTRAMEDIAL_KEY" \
-H "Content-Type: application/json" \
-d '{
"resource": "lock:deploy/production",
"actorDid": "did:web:acme.example:agent:cost"
}'const res = await fetch("https://api.intramedial.com/api/v1/acp/coordination/lease", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.INTRAMEDIAL_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
resource: "lock:deploy/production",
actorDid: "did:web:acme.example:agent:cost",
}),
});
console.log(res.status, await res.json());import os, requests
res = requests.post(
"https://api.intramedial.com/api/v1/acp/coordination/lease",
headers={"Authorization": "Bearer " + os.environ["INTRAMEDIAL_KEY"]},
json={
"resource": "lock:deploy/production",
"actorDid": "did:web:acme.example:agent:cost",
},
timeout=30,
)
print(res.status_code, res.json())循环调用租约接口,每次尝试之间休眠 waitMs。遇到指明 waitingOn 的 deadlock 时停止。
const API = "https://api.intramedial.com/api/v1/acp";
const headers = {
Authorization: `Bearer ${process.env.INTRAMEDIAL_KEY}`,
"Content-Type": "application/json",
};
const ask = { resource: "lock:deploy/production", actorDid: "did:web:acme.example:agent:cost" };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
let lease = null;
for (let attempt = 0; attempt < 20 && !lease; attempt++) {
const res = await fetch(`${API}/coordination/lease`, { method: "POST", headers, body: JSON.stringify(ask) });
const body = await res.json();
if (body.ok) lease = body.lease;
else if (body.reason === "deadlock") throw new Error("wait cycle, waiting on " + body.waitingOn);
else await sleep(body.stampede?.waitMs ?? 1000); // the plane names the back-off
}
if (!lease) throw new Error("no slot yet");
console.log("holding", lease.id, "until", new Date(lease.expiresAtMs).toISOString());import os, time, requests
API = "https://api.intramedial.com/api/v1/acp"
headers = {"Authorization": "Bearer " + os.environ["INTRAMEDIAL_KEY"]}
ask = {"resource": "lock:deploy/production", "actorDid": "did:web:acme.example:agent:cost"}
lease = None
for _ in range(20):
body = requests.post(f"{API}/coordination/lease", headers=headers, json=ask, timeout=30).json()
if body.get("ok"):
lease = body["lease"]
break
if body.get("reason") == "deadlock":
raise SystemExit(f"wait cycle, waiting on {body.get('waitingOn')}")
time.sleep(body.get("stampede", {}).get("waitMs", 1000) / 1000) # the plane names the back-off
if not lease:
raise SystemExit("no slot yet")
print("holding", lease["id"], "until", lease[])部署一结束就释放时段,这样队列中的下一个智能体就不必等租约自行失效。释放需要资源和智能体,以及可选的 leaseId。
curl -sS -X POST https://api.intramedial.com/api/v1/acp/coordination/release \
-H "Authorization: Bearer $INTRAMEDIAL_KEY" \
-H "Content-Type: application/json" \
-d '{
"resource": "lock:deploy/production",
"actorDid": "did:web:acme.example:agent:cost"
}'const res = await fetch("https://api.intramedial.com/api/v1/acp/coordination/release", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.INTRAMEDIAL_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
resource: "lock:deploy/production",
actorDid: "did:web:acme.example:agent:cost",
}),
});
console.log(res.status, await res.json());import os, requests
res = requests.post(
"https://api.intramedial.com/api/v1/acp/coordination/release",
headers={"Authorization": "Bearer " + os.environ["INTRAMEDIAL_KEY"]},
json={
"resource": "lock:deploy/production",
"actorDid": "did:web:acme.example:agent:cost",
},
timeout=30,
)
print(res.status_code, res.json())内容复制自: /docs/coordination-lease
账本仅可追加,并封存在 Merkle 根之下。条目上的时间取自 Intramedial 自己的时钟,签名包可用已发布的公钥离线核查。
用 coordination.lease 对某个资源获取独占租约,查看持有者,并在用完后释放。
coordination.lease运行六个固定的 Intralock 场景,读取每一个的结果,并设置周期,使演练自动重复。
drills.frt列出检测器,运行 lease-overlap,读取它所引用的冲突及其证据,然后读取它为审查而提交的案件。
detection.run当我们向实用示例中添加新示例时,会发送一封简短的邮件。不会发送其他任何邮件,而且您可以从任意一封邮件中退订。
完全无需账户:在 7 天之内可以在各个 attest 路由上调用 35 次,所生成的回执都会被标记为测试回执。当您想继续使用时,再注册账户即可。