verbox 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
verbox-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: verbox
3
+ Version: 0.1.0
4
+ Summary: Behavioral governance, policy-as-code guardrails, and telemetry SDK for autonomous AI agents.
5
+ Keywords: ai-agents,governance,guardrails,telemetry,opentelemetry,langgraph
6
+ Author: Akshat Gupta
7
+ Author-email: Akshat Gupta <akshatguptamtr@gmail.com>
8
+ License-Expression: MIT
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Dist: python-dotenv>=1.0.0
17
+ Requires-Dist: requests>=2.31.0
18
+ Requires-Python: >=3.11
19
+ Project-URL: Homepage, https://github.com/PranavJa1n/VerboX
20
+ Project-URL: Repository, https://github.com/PranavJa1n/VerboX
21
+ Description-Content-Type: text/markdown
22
+
23
+ # verbox
24
+
25
+ Behavioral governance, policy-as-code guardrails, and telemetry SDK for autonomous AI agents.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install verbox
31
+ ```
32
+
33
+ ## Quickstart
34
+
35
+ Set your API key and backend URL in `.env` (or environment variables):
36
+
37
+ ```env
38
+ VERBOX_KEY="vbx_live_..."
39
+ VERBOX_BACKEND_URL="https://verbox-backend.blackpond-d6fc90cf.eastus.azurecontainerapps.io/api/v1"
40
+ VERBOX_FAIL_OPEN="true"
41
+ ```
42
+
43
+ Decorate your agent tools with `@guard` and `@trace`:
44
+
45
+ ```python
46
+ from verbox import guard, trace, new_trace_id, complete_trace, PolicyBlockedError
47
+
48
+ trace_id = new_trace_id()
49
+
50
+ @guard(agent_id="remediation_engineer")
51
+ @trace(agent_id="remediation_engineer")
52
+ def scale_asg_tool(asg_name: str, new_capacity: int):
53
+ return {"asg_name": asg_name, "new_capacity": new_capacity}
54
+
55
+ # When the swarm finishes a run:
56
+ complete_trace(trace_id)
57
+ ```
58
+
59
+ You can also pass `api_key="vbx_live_..."` explicitly to `@guard`, `@trace`, or `complete_trace`.
verbox-0.1.0/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # verbox
2
+
3
+ Behavioral governance, policy-as-code guardrails, and telemetry SDK for autonomous AI agents.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install verbox
9
+ ```
10
+
11
+ ## Quickstart
12
+
13
+ Set your API key and backend URL in `.env` (or environment variables):
14
+
15
+ ```env
16
+ VERBOX_KEY="vbx_live_..."
17
+ VERBOX_BACKEND_URL="https://verbox-backend.blackpond-d6fc90cf.eastus.azurecontainerapps.io/api/v1"
18
+ VERBOX_FAIL_OPEN="true"
19
+ ```
20
+
21
+ Decorate your agent tools with `@guard` and `@trace`:
22
+
23
+ ```python
24
+ from verbox import guard, trace, new_trace_id, complete_trace, PolicyBlockedError
25
+
26
+ trace_id = new_trace_id()
27
+
28
+ @guard(agent_id="remediation_engineer")
29
+ @trace(agent_id="remediation_engineer")
30
+ def scale_asg_tool(asg_name: str, new_capacity: int):
31
+ return {"asg_name": asg_name, "new_capacity": new_capacity}
32
+
33
+ # When the swarm finishes a run:
34
+ complete_trace(trace_id)
35
+ ```
36
+
37
+ You can also pass `api_key="vbx_live_..."` explicitly to `@guard`, `@trace`, or `complete_trace`.
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "verbox"
3
+ version = "0.1.0"
4
+ description = "Behavioral governance, policy-as-code guardrails, and telemetry SDK for autonomous AI agents."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ authors = [
8
+ { name = "Akshat Gupta", email = "akshatguptamtr@gmail.com" },
9
+ ]
10
+ keywords = ["ai-agents", "governance", "guardrails", "telemetry", "opentelemetry", "langgraph"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ ]
20
+ requires-python = ">=3.11"
21
+ dependencies = [
22
+ "python-dotenv>=1.0.0",
23
+ "requests>=2.31.0",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/PranavJa1n/VerboX"
28
+ Repository = "https://github.com/PranavJa1n/VerboX"
29
+
30
+ [build-system]
31
+ requires = ["uv_build>=0.11.29,<0.12.0"]
32
+ build-backend = "uv_build"
33
+
34
+ [dependency-groups]
35
+ dev = [
36
+ "pytest>=9.1.1",
37
+ "pytest-mock>=3.15.1",
38
+ "ruff>=0.16.2",
39
+ ]
@@ -0,0 +1,19 @@
1
+ from verbox.client.http_client import check_evaluation, complete_trace, send_trace
2
+ from verbox.core.config import SDKConfig, config
3
+ from verbox.core.context import get_trace_id, new_trace_id, set_trace_id
4
+ from verbox.guardrail.decorator import PolicyBlockedError, guard
5
+ from verbox.tracing.decorator import trace
6
+
7
+ __all__ = [
8
+ "PolicyBlockedError",
9
+ "SDKConfig",
10
+ "check_evaluation",
11
+ "complete_trace",
12
+ "config",
13
+ "get_trace_id",
14
+ "guard",
15
+ "new_trace_id",
16
+ "send_trace",
17
+ "set_trace_id",
18
+ "trace",
19
+ ]
@@ -0,0 +1,105 @@
1
+ import logging
2
+ import requests
3
+ from verbox.core.config import config
4
+
5
+ logger = logging.getLogger("verbox_sdk")
6
+
7
+
8
+ def _resolve_api_key(api_key: str | None) -> str:
9
+ return (api_key if api_key is not None else config.api_key).strip()
10
+
11
+
12
+ def check_evaluation(agent_id: str, tool_name: str, arguments: dict, api_key: str | None = None) -> dict:
13
+ """
14
+ Calls POST /evaluate with X-API-Key. Returns a dict with action/reason/cached_result.
15
+ If API key is missing/invalid (401), logs a warning and allows the normal tool to run.
16
+ """
17
+ resolved_key = _resolve_api_key(api_key)
18
+ if not resolved_key:
19
+ logger.warning("VerboX api_key is empty - skipping guardrail, allowing '%s'", tool_name)
20
+ return {
21
+ "action": "allow",
22
+ "reason": "Missing api_key - VerboX skipped, normal execution continued",
23
+ "cached_result": None,
24
+ }
25
+
26
+ url = f"{config.backend_base_url}/evaluate/"
27
+ payload = {
28
+ "agent_id": agent_id,
29
+ "tool_name": tool_name,
30
+ "arguments": arguments,
31
+ "policy": "system_defaults",
32
+ }
33
+ headers = {"X-API-Key": resolved_key}
34
+
35
+ try:
36
+ response = requests.post(url=url, json=payload, headers=headers, timeout=config.timeout_seconds)
37
+ if response.status_code == 401:
38
+ logger.warning("VerboX API key unauthorized (401) - skipping guardrail, allowing '%s'", tool_name)
39
+ return {
40
+ "action": "allow",
41
+ "reason": "Invalid API key (401) - VerboX skipped, normal execution continued",
42
+ "cached_result": None,
43
+ }
44
+ response.raise_for_status()
45
+ return response.json()
46
+
47
+ except requests.RequestException as exc:
48
+ if config.fail_mode:
49
+ logger.warning("Verbox backend unreachable for /evaluate (%s) - fail open, allowing '%s'", exc, tool_name)
50
+ return {
51
+ "action": "allow",
52
+ "reason": f"verboX unreachable, failed open: {exc}",
53
+ "cached_result": None,
54
+ }
55
+ raise
56
+
57
+
58
+ def send_trace(span: dict, api_key: str | None = None) -> dict | None:
59
+ """
60
+ Calls POST /traces with X-API-Key. Failures (including 401) are logged and swallowed.
61
+ """
62
+ resolved_key = _resolve_api_key(api_key)
63
+ if not resolved_key:
64
+ logger.warning("VerboX api_key is empty - trace dropped")
65
+ return None
66
+
67
+ url = f"{config.backend_base_url}/traces/"
68
+ headers = {"X-API-Key": resolved_key}
69
+
70
+ try:
71
+ response = requests.post(url=url, json=span, headers=headers, timeout=config.timeout_seconds)
72
+ if response.status_code == 401:
73
+ logger.warning("VerboX API key unauthorized (401) - trace dropped")
74
+ return None
75
+ response.raise_for_status()
76
+ return response.json()
77
+
78
+ except requests.RequestException as exc:
79
+ logger.warning("Verbox backend unreachable for /traces (%s) - span dropped", exc)
80
+ return None
81
+
82
+
83
+ def complete_trace(trace_id: str, api_key: str | None = None) -> dict | None:
84
+ """
85
+ Calls POST /traces/{trace_id}/complete with X-API-Key, triggering Module 2 contradiction pass.
86
+ """
87
+ resolved_key = _resolve_api_key(api_key)
88
+ if not resolved_key:
89
+ logger.warning("VerboX api_key is empty - complete_trace skipped")
90
+ return None
91
+
92
+ url = f"{config.backend_base_url}/traces/{trace_id}/complete"
93
+ headers = {"X-API-Key": resolved_key}
94
+
95
+ try:
96
+ response = requests.post(url=url, headers=headers, timeout=config.timeout_seconds)
97
+ if response.status_code == 401:
98
+ logger.warning("VerboX API key unauthorized (401) - complete_trace skipped")
99
+ return None
100
+ response.raise_for_status()
101
+ return response.json()
102
+
103
+ except requests.RequestException as exc:
104
+ logger.warning("Verbox backend unreachable for /traces/complete (%s).", exc)
105
+ return None
@@ -0,0 +1,21 @@
1
+ import os
2
+ from pathlib import Path
3
+ from dotenv import load_dotenv
4
+
5
+ _parents = Path(__file__).resolve().parents
6
+ _monorepo_env = (_parents[4] if len(_parents) > 4 else _parents[-1]) / ".env"
7
+
8
+ if _monorepo_env.exists():
9
+ load_dotenv(dotenv_path=_monorepo_env, override=True)
10
+ else:
11
+ load_dotenv()
12
+
13
+
14
+ class SDKConfig:
15
+ backend_base_url: str = os.getenv("VERBOX_BACKEND_URL", "http://localhost:8000/api/v1").rstrip("/")
16
+ api_key: str = os.getenv("VERBOX_KEY") or os.getenv("VERBOX_API_KEY", "")
17
+ timeout_seconds: float = float(os.getenv("VERBOX_TIMEOUT_SECONDS", "5.0"))
18
+ fail_mode: bool = os.getenv("VERBOX_FAIL_OPEN", "true").lower() == "true"
19
+
20
+
21
+ config = SDKConfig()
@@ -0,0 +1,27 @@
1
+ import contextvars
2
+ import uuid
3
+
4
+ _trace_id_var: contextvars.ContextVar[str | None] = contextvars.ContextVar("verbox_trace_id", default=None)
5
+
6
+ def set_trace_id(trace_id: str) -> None:
7
+ """
8
+ This function is used to set the trace ID. Call once per run before dispatching to any agent
9
+ """
10
+ _trace_id_var.set(trace_id)
11
+
12
+ def new_trace_id() -> str:
13
+ """
14
+ Generate and register a new trace ID. Use at the start of every run
15
+ """
16
+ trace_id = str(uuid.uuid4())
17
+ set_trace_id(trace_id)
18
+ return trace_id
19
+
20
+ def get_trace_id() -> str:
21
+ """
22
+ Return the active trace ID. If no trace ID is active the generate and register a new trace ID instead of crashing.
23
+ """
24
+ trace_id = _trace_id_var.get()
25
+ if trace_id is None:
26
+ trace_id = new_trace_id()
27
+ return trace_id
@@ -0,0 +1,48 @@
1
+ import functools
2
+ from verbox.client.http_client import check_evaluation
3
+
4
+
5
+ class PolicyBlockedError(Exception):
6
+ """Raised when verboX's Tier 1 policy check blocks a tool call."""
7
+ pass
8
+
9
+
10
+ def guard(agent_id: str, api_key: str | None = None):
11
+ """
12
+ Decorator for a tool function. Before the real tool runs, calls verboX's /evaluate endpoint:
13
+ - "block" -> raises PolicyBlockedError, real tool never runs.
14
+ - "cache_hit" -> returns the cached result directly, real tool never runs.
15
+ - "allow" -> runs the real tool normally.
16
+
17
+ If `api_key` is omitted, reads `VERBOX_KEY` from the environment / `.env`.
18
+
19
+ Usage:
20
+ @guard(agent_id="remediation_engineer")
21
+ def my_tool(...):
22
+ ...
23
+ """
24
+ def decorator(func):
25
+ @functools.wraps(func)
26
+ def wrapper(*args, **kwargs):
27
+ tool_name = func.__name__
28
+ arguments = kwargs if kwargs else {"args": args}
29
+
30
+ decision = check_evaluation(
31
+ agent_id=agent_id,
32
+ tool_name=tool_name,
33
+ arguments=arguments,
34
+ api_key=api_key,
35
+ )
36
+ action = decision.get("action")
37
+
38
+ if action == "block":
39
+ raise PolicyBlockedError(decision.get("reason", "Blocked by verboX policy"))
40
+
41
+ if action == "cache_hit":
42
+ return decision.get("cached_result")
43
+
44
+ return func(*args, **kwargs)
45
+
46
+ return wrapper
47
+
48
+ return decorator
File without changes
@@ -0,0 +1,49 @@
1
+ import functools
2
+ import uuid
3
+ from datetime import datetime, timezone
4
+ from verbox.client.http_client import send_trace
5
+ from verbox.core.context import get_trace_id
6
+
7
+
8
+ def trace(agent_id: str, api_key: str | None = None):
9
+ """
10
+ Decorator for a tool function. Runs the real function,
11
+ then sends a span describing what happened to verboX's /traces endpoint.
12
+ Never affects the wrapped function's return value or exceptions.
13
+
14
+ If `api_key` is omitted, reads `VERBOX_KEY` from the environment / `.env`.
15
+
16
+ Usage:
17
+ @trace(agent_id="remediation_engineer")
18
+ def my_tool(...):
19
+ ...
20
+ """
21
+ def decorator(func):
22
+ @functools.wraps(func)
23
+ def wrapper(*args, **kwargs):
24
+ span_id = str(uuid.uuid4())
25
+ start_time = datetime.now(timezone.utc)
26
+
27
+ result = func(*args, **kwargs)
28
+
29
+ end_time = datetime.now(timezone.utc)
30
+
31
+ span = {
32
+ "trace_id": get_trace_id(),
33
+ "span_id": span_id,
34
+ "agent_id": agent_id,
35
+ "gen_ai.operation.name": "tool_call",
36
+ "gen_ai.tool.name": func.__name__,
37
+ "gen_ai.tool.call.arguments": kwargs if kwargs else {"args": args},
38
+ "gen_ai.tool.call.result": result,
39
+ "start_time": start_time.isoformat(),
40
+ "end_time": end_time.isoformat(),
41
+ }
42
+
43
+ send_trace(span, api_key=api_key)
44
+
45
+ return result
46
+
47
+ return wrapper
48
+
49
+ return decorator