获取租约并再次释放
用 coordination.lease 对某个资源获取独占租约,查看持有者,并在用完后释放。
coordination.lease
用 coordination.lease 对某个资源获取独占租约,查看持有者,并在用完后释放。
coordination.lease两个智能体不得同时部署到生产环境。您给资源设一个租约:第一个智能体持有它,第二个被拒绝,并被告知谁持有以及需要等待多久。从未释放的租约会自行失效。
代码从 INTRAMEDIAL_KEY 读取密钥。请把它放在您的 shell 或密钥存储中,切勿放进要提交的文件。需要已登录用户的调用不能使用密钥:这些调用由控制台发起。
以想要该资源的智能体身份请求它。空闲的资源会返回一个带过期时间的租约。
空闲资源返回 { ok: true, lease }。租约带有自己的 id、持有者和过期时间。
{
"ok": true,
"lease": {
"id": "lease_4c1e",
"resource": "lock:deploy/production",
"holder": "did:web:acme.example:agent:release",
"expiresAtMs": 1793545800000,
: { : , : [] },
: ,
: {}
}
}lease_held 被拒绝。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:release"
}'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:release",
}),
});
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:release",
},
timeout=30,
)
print(res.status_code, res.json())第二个智能体请求同一资源时会被拒绝,返回 lease_held、持有者的 DID,以及 stampede.waitMs 中的退避时间。每个租约都使用默认的 30,000 毫秒;该路由不读取 ttlMs。
curl -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",
}),
});
const body = await res.json();
if (!body.ok) console.log(body.reason, "held by", body.holder, "wait", body.stampede?.waitMs, "ms");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,
)
body = res.json()
if not body.get("ok"):
print(body["reason"], "held by", body["holder"], "wait", body["stampede"]["waitMs"], "ms")发送资源和智能体;release 返回 released 和 releasedIds。从未释放的租约会失效,并由告警将其收回。
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:release"
}'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:release",
}),
});
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:release",
},
timeout=30,
)
print(res.status_code, res.json())内容复制自: /docs/coordination-lease
账本仅可追加,并封存在 Merkle 根之下。条目上的时间取自 Intramedial 自己的时钟,签名包可用已发布的公钥离线核查。
当我们向实用示例中添加新示例时,会发送一封简短的邮件。不会发送其他任何邮件,而且您可以从任意一封邮件中退订。
完全无需账户:在 7 天之内可以在各个 attest 路由上调用 35 次,所生成的回执都会被标记为测试回执。当您想继续使用时,再注册账户即可。