Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -403,31 +403,54 @@ for tc, tm in zip(tools, tools_meta):
|
|
| 403 |
|
| 404 |
# Plan gating: block tools above tier max risk
|
| 405 |
if risk_rank.get(tm["risk"], 3) > tier_max_rank:
|
| 406 |
-
outputs.append({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
continue
|
|
|
|
|
|
|
| 408 |
if mode == "sandbox" and tm["risk"] != "low":
|
| 409 |
-
outputs.append({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
continue
|
| 411 |
|
| 412 |
try:
|
| 413 |
-
outputs.append({
|
|
|
|
|
|
|
|
|
|
| 414 |
except Exception as e:
|
| 415 |
-
outputs.append({
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
|
| 432 |
# ---------------- Admin actions ----------------
|
| 433 |
def create_agent_admin(session_token: str, agent_id: str, display_name: str, risk_tier: str, verification_level: str):
|
|
|
|
| 403 |
|
| 404 |
# Plan gating: block tools above tier max risk
|
| 405 |
if risk_rank.get(tm["risk"], 3) > tier_max_rank:
|
| 406 |
+
outputs.append({
|
| 407 |
+
"tool_id": tm["tool_id"],
|
| 408 |
+
"blocked": True,
|
| 409 |
+
"reason": f"plan_blocks_{tm['risk']}_risk"
|
| 410 |
+
})
|
| 411 |
continue
|
| 412 |
+
|
| 413 |
+
# Sandbox gating (policy-based)
|
| 414 |
if mode == "sandbox" and tm["risk"] != "low":
|
| 415 |
+
outputs.append({
|
| 416 |
+
"tool_id": tm["tool_id"],
|
| 417 |
+
"blocked": True,
|
| 418 |
+
"reason": "sandbox_mode"
|
| 419 |
+
})
|
| 420 |
continue
|
| 421 |
|
| 422 |
try:
|
| 423 |
+
outputs.append({
|
| 424 |
+
"tool_id": tm["tool_id"],
|
| 425 |
+
"output": run_tool(tm["tool_id"], tc.get("args", {}))
|
| 426 |
+
})
|
| 427 |
except Exception as e:
|
| 428 |
+
outputs.append({
|
| 429 |
+
"tool_id": tm["tool_id"],
|
| 430 |
+
"error": str(e)
|
| 431 |
+
})
|
| 432 |
+
|
| 433 |
+
# receipts + audit chain (MUST be after the loop)
|
| 434 |
+
receipt = {
|
| 435 |
+
"ts_unix": now_unix(),
|
| 436 |
+
"agent_id": agent_id,
|
| 437 |
+
"user_id": user["user_id"],
|
| 438 |
+
"intent": intent,
|
| 439 |
+
"mode": mode,
|
| 440 |
+
"decision": decision,
|
| 441 |
+
"outputs_hash": sha256_hex(canonical_json(outputs)),
|
| 442 |
+
}
|
| 443 |
+
receipt["signature"] = sign_hmac(receipt, RECEIPT_SIGNING_KEY)
|
| 444 |
+
audit = audit_append(
|
| 445 |
+
agent_id,
|
| 446 |
+
user["user_id"],
|
| 447 |
+
"secure_call.run",
|
| 448 |
+
{"intent": intent, "tools": tools},
|
| 449 |
+
{"outputs": outputs, "receipt": receipt},
|
| 450 |
+
)
|
| 451 |
+
|
| 452 |
+
conn.close()
|
| 453 |
+
return {"outputs": outputs, "receipt": receipt, "audit": audit}
|
| 454 |
|
| 455 |
# ---------------- Admin actions ----------------
|
| 456 |
def create_agent_admin(session_token: str, agent_id: str, display_name: str, risk_tier: str, verification_level: str):
|