|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import os |
| 4 | +from typing import Any |
| 5 | + |
| 6 | +TRUE_VALUES = {"1", "true", "yes", "on"} |
| 7 | + |
| 8 | + |
| 9 | +def configured_value(name: str) -> str: |
| 10 | + value = os.getenv(name, "").strip() |
| 11 | + if not value or value.startswith(("<", "{{")): |
| 12 | + return "" |
| 13 | + return value |
| 14 | + |
| 15 | + |
| 16 | +def env_flag(name: str, default: bool = False) -> bool: |
| 17 | + raw_value = os.getenv(name) |
| 18 | + if raw_value is None: |
| 19 | + return default |
| 20 | + return raw_value.strip().lower() in TRUE_VALUES |
| 21 | + |
| 22 | + |
| 23 | +def configured_skill_space_ids() -> list[str]: |
| 24 | + return [ |
| 25 | + item.strip() |
| 26 | + for item in os.getenv("SKILL_SPACE_ID", "").split(",") |
| 27 | + if item.strip() and not item.strip().startswith(("<", "{{")) |
| 28 | + ] |
| 29 | + |
| 30 | + |
| 31 | +def resolve_skill_sandbox_tool_id() -> tuple[str | None, str | None]: |
| 32 | + for env_name in ("AGENTKIT_TOOL_ID", "AGENTKIT_TOOL_ID_SKILLS"): |
| 33 | + value = configured_value(env_name) |
| 34 | + if value: |
| 35 | + return value, env_name |
| 36 | + return None, None |
| 37 | + |
| 38 | + |
| 39 | +def skill_sandbox_status() -> dict[str, Any]: |
| 40 | + tool_id, source = resolve_skill_sandbox_tool_id() |
| 41 | + skill_space_ids = configured_skill_space_ids() |
| 42 | + enabled = env_flag("ENABLE_SKILL_SANDBOX", False) |
| 43 | + exposed = env_flag("EXPOSE_SKILL_SANDBOX_TO_AGENT", False) |
| 44 | + ready = bool(tool_id and skill_space_ids) |
| 45 | + |
| 46 | + warnings: list[str] = [] |
| 47 | + next_actions: list[str] = [] |
| 48 | + if not tool_id: |
| 49 | + warnings.append("AGENTKIT_TOOL_ID is not configured.") |
| 50 | + next_actions.append("Bind a Skills Sandbox Tool to the AgentKit Runtime.") |
| 51 | + if not skill_space_ids: |
| 52 | + warnings.append("SKILL_SPACE_ID is not configured.") |
| 53 | + next_actions.append( |
| 54 | + "Set SKILL_SPACE_ID to the Skills space that contains published Skills." |
| 55 | + ) |
| 56 | + if ready and not exposed: |
| 57 | + next_actions.append( |
| 58 | + "Set ENABLE_SKILL_SANDBOX=true and EXPOSE_SKILL_SANDBOX_TO_AGENT=true " |
| 59 | + "to expose execute_skills to the Agent." |
| 60 | + ) |
| 61 | + |
| 62 | + return { |
| 63 | + "ok": ready, |
| 64 | + "stage": "skill_sandbox_config", |
| 65 | + "data": { |
| 66 | + "enabled": enabled, |
| 67 | + "exposed_to_agent": enabled and exposed, |
| 68 | + "tool_id_configured": bool(tool_id), |
| 69 | + "tool_id_source": source, |
| 70 | + "skill_space_ids": skill_space_ids, |
| 71 | + }, |
| 72 | + "warnings": warnings, |
| 73 | + "next_actions": next_actions, |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | +def should_expose_skill_sandbox() -> bool: |
| 78 | + status = skill_sandbox_status() |
| 79 | + return bool( |
| 80 | + status["ok"] |
| 81 | + and status["data"]["enabled"] |
| 82 | + and status["data"]["exposed_to_agent"] |
| 83 | + ) |
0 commit comments