governor-sdk 0.2.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.
Files changed (55) hide show
  1. governor_sdk-0.2.0/PKG-INFO +50 -0
  2. governor_sdk-0.2.0/governor/__init__.py +109 -0
  3. governor_sdk-0.2.0/governor/__main__.py +4 -0
  4. governor_sdk-0.2.0/governor/cli.py +210 -0
  5. governor_sdk-0.2.0/governor/client.py +369 -0
  6. governor_sdk-0.2.0/governor/decorator.py +121 -0
  7. governor_sdk-0.2.0/governor/integrations/__init__.py +47 -0
  8. governor_sdk-0.2.0/governor/integrations/_compat.py +17 -0
  9. governor_sdk-0.2.0/governor/integrations/autogpt/__init__.py +133 -0
  10. governor_sdk-0.2.0/governor/integrations/autogpt/commands.py +522 -0
  11. governor_sdk-0.2.0/governor/integrations/autogpt/plugin.py +730 -0
  12. governor_sdk-0.2.0/governor/integrations/azure/__init__.py +221 -0
  13. governor_sdk-0.2.0/governor/integrations/azure/agent.py +970 -0
  14. governor_sdk-0.2.0/governor/integrations/azure/auth.py +310 -0
  15. governor_sdk-0.2.0/governor/integrations/azure/guardrails.py +1073 -0
  16. governor_sdk-0.2.0/governor/integrations/bedrock/__init__.py +150 -0
  17. governor_sdk-0.2.0/governor/integrations/bedrock/agent.py +736 -0
  18. governor_sdk-0.2.0/governor/integrations/bedrock/auth.py +617 -0
  19. governor_sdk-0.2.0/governor/integrations/bedrock/interceptor.py +835 -0
  20. governor_sdk-0.2.0/governor/integrations/bedrock/tools.py +613 -0
  21. governor_sdk-0.2.0/governor/integrations/crewai/__init__.py +144 -0
  22. governor_sdk-0.2.0/governor/integrations/crewai/agent.py +298 -0
  23. governor_sdk-0.2.0/governor/integrations/crewai/callbacks.py +386 -0
  24. governor_sdk-0.2.0/governor/integrations/crewai/crew.py +417 -0
  25. governor_sdk-0.2.0/governor/integrations/crewai/task.py +349 -0
  26. governor_sdk-0.2.0/governor/integrations/databricks/__init__.py +92 -0
  27. governor_sdk-0.2.0/governor/integrations/databricks/agent.py +710 -0
  28. governor_sdk-0.2.0/governor/integrations/databricks/auth.py +534 -0
  29. governor_sdk-0.2.0/governor/integrations/databricks/mlflow.py +787 -0
  30. governor_sdk-0.2.0/governor/integrations/databricks/unity.py +684 -0
  31. governor_sdk-0.2.0/governor/integrations/gcp/__init__.py +145 -0
  32. governor_sdk-0.2.0/governor/integrations/gcp/adk.py +565 -0
  33. governor_sdk-0.2.0/governor/integrations/gcp/agent.py +621 -0
  34. governor_sdk-0.2.0/governor/integrations/gcp/auth.py +410 -0
  35. governor_sdk-0.2.0/governor/integrations/gcp/tools.py +501 -0
  36. governor_sdk-0.2.0/governor/integrations/langchain/__init__.py +80 -0
  37. governor_sdk-0.2.0/governor/integrations/langchain/agent.py +624 -0
  38. governor_sdk-0.2.0/governor/integrations/langchain/callback.py +474 -0
  39. governor_sdk-0.2.0/governor/integrations/langchain/tools.py +437 -0
  40. governor_sdk-0.2.0/governor/integrations/langgraph/__init__.py +25 -0
  41. governor_sdk-0.2.0/governor/integrations/langgraph/tool_node.py +271 -0
  42. governor_sdk-0.2.0/governor/integrations/llamaindex/__init__.py +62 -0
  43. governor_sdk-0.2.0/governor/integrations/llamaindex/query_engine.py +394 -0
  44. governor_sdk-0.2.0/governor/integrations/llamaindex/tools.py +638 -0
  45. governor_sdk-0.2.0/governor_sdk.egg-info/PKG-INFO +50 -0
  46. governor_sdk-0.2.0/governor_sdk.egg-info/SOURCES.txt +53 -0
  47. governor_sdk-0.2.0/governor_sdk.egg-info/dependency_links.txt +1 -0
  48. governor_sdk-0.2.0/governor_sdk.egg-info/entry_points.txt +2 -0
  49. governor_sdk-0.2.0/governor_sdk.egg-info/requires.txt +36 -0
  50. governor_sdk-0.2.0/governor_sdk.egg-info/top_level.txt +1 -0
  51. governor_sdk-0.2.0/pyproject.toml +190 -0
  52. governor_sdk-0.2.0/setup.cfg +4 -0
  53. governor_sdk-0.2.0/setup.py +45 -0
  54. governor_sdk-0.2.0/tests/test_client.py +479 -0
  55. governor_sdk-0.2.0/tests/test_framework_integrations.py +717 -0
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: governor-sdk
3
+ Version: 0.2.0
4
+ Summary: Python SDK for GovernorAI - The execution boundary for autonomous AI
5
+ Author: GovernorAI Team
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/governor/governor
8
+ Project-URL: Documentation, https://github.com/governor/governor#readme
9
+ Project-URL: Repository, https://github.com/governor/governor.git
10
+ Project-URL: Issues, https://github.com/governor/governor/issues
11
+ Keywords: governor,ai,governance,agent,policy,safety
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: requests>=2.28.0
25
+ Provides-Extra: langchain
26
+ Requires-Dist: langchain<2.0.0,>=1.2.0; extra == "langchain"
27
+ Requires-Dist: langchain-core<2.0.0,>=1.2.0; extra == "langchain"
28
+ Provides-Extra: llamaindex
29
+ Requires-Dist: llama-index<0.15.0,>=0.14.0; extra == "llamaindex"
30
+ Provides-Extra: crewai
31
+ Requires-Dist: crewai<0.12.0,>=0.11.0; python_version < "3.14" and extra == "crewai"
32
+ Provides-Extra: langgraph
33
+ Requires-Dist: langgraph<2.0.0,>=1.1.0; extra == "langgraph"
34
+ Requires-Dist: langchain-core<2.0.0,>=1.2.0; extra == "langgraph"
35
+ Provides-Extra: all
36
+ Requires-Dist: langchain<2.0.0,>=1.2.0; extra == "all"
37
+ Requires-Dist: langchain-core<2.0.0,>=1.2.0; extra == "all"
38
+ Requires-Dist: llama-index<0.15.0,>=0.14.0; extra == "all"
39
+ Requires-Dist: crewai<0.12.0,>=0.11.0; python_version < "3.14" and extra == "all"
40
+ Requires-Dist: langgraph<2.0.0,>=1.1.0; extra == "all"
41
+ Provides-Extra: dev
42
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
43
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
44
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
45
+ Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
46
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
47
+ Requires-Dist: black>=23.0.0; extra == "dev"
48
+ Requires-Dist: mypy>=1.7.0; extra == "dev"
49
+ Requires-Dist: types-requests>=2.31.0; extra == "dev"
50
+ Dynamic: requires-python
@@ -0,0 +1,109 @@
1
+ """GovernorAI SDK - Python client for GovernorAI AI governance.
2
+
3
+ Quickstart:
4
+ pip install governor-sdk
5
+ export GOVERNOR_URL=https://gateway.governorai.ai
6
+ export GOVERNOR_API_KEY=gov_xxx
7
+
8
+ # One-line governance for any supported framework:
9
+ from governor import govern
10
+ governed_agent = govern(your_agent)
11
+ """
12
+
13
+ from .client import (
14
+ AsyncGovernorAIClient,
15
+ GovernorAIApprovalRequired,
16
+ GovernorAIClient,
17
+ GovernorAIDenied,
18
+ GovernorAIError,
19
+ )
20
+ from .decorator import governed, governed_tool_call
21
+
22
+ __version__ = "0.2.0"
23
+ __all__ = [
24
+ "AsyncGovernorAIClient",
25
+ "GovernorAIClient",
26
+ "GovernorAIError",
27
+ "GovernorAIDenied",
28
+ "GovernorAIApprovalRequired",
29
+ "governed",
30
+ "governed_tool_call",
31
+ "govern",
32
+ ]
33
+
34
+
35
+ def govern(agent, *, governor_url=None, api_key=None, agent_id=None, namespace="default"):
36
+ """Universal one-line governance wrapper.
37
+
38
+ Auto-detects the framework and wraps the agent/executor with GovernorAI
39
+ governance. Supports LangChain, CrewAI, LangGraph, and LlamaIndex.
40
+
41
+ Args:
42
+ agent: The agent/executor/crew/engine to govern
43
+ governor_url: Gateway URL (falls back to GOVERNOR_URL env var)
44
+ api_key: API key (falls back to GOVERNOR_API_KEY env var)
45
+ agent_id: Agent identifier (auto-derived if omitted)
46
+ namespace: Namespace for policy lookup
47
+
48
+ Returns:
49
+ A governed wrapper that intercepts tool calls through GovernorAI.
50
+
51
+ Example:
52
+ from governor import govern
53
+ governed = govern(your_langchain_executor)
54
+ result = governed.invoke({"input": "query"})
55
+ """
56
+ agent_type = type(agent).__name__
57
+ module = type(agent).__module__ or ""
58
+
59
+ # LangChain AgentExecutor or Runnable
60
+ if "langchain" in module or agent_type in ("AgentExecutor", "RunnableSequence"):
61
+ from .integrations.langchain import wrap_agent
62
+ return wrap_agent(
63
+ agent,
64
+ governor_url=governor_url,
65
+ api_key=api_key,
66
+ agent_id=agent_id,
67
+ namespace=namespace,
68
+ )
69
+
70
+ # CrewAI Crew
71
+ if "crewai" in module or agent_type == "Crew":
72
+ from .integrations.crewai import GovernorAICrew
73
+ client = GovernorAIClient(base_url=governor_url, api_key=api_key)
74
+ return GovernorAICrew(
75
+ crew=agent,
76
+ governor_client=client,
77
+ crew_id=agent_id or "crewai-crew",
78
+ namespace=namespace,
79
+ )
80
+
81
+ # LangGraph ToolNode
82
+ if "langgraph" in module or agent_type == "ToolNode":
83
+ from .integrations.langgraph import GovernedToolNode
84
+ return GovernedToolNode(
85
+ tools=getattr(agent, "tools_by_name", {}).values() if hasattr(agent, "tools_by_name") else [],
86
+ governor_url=governor_url,
87
+ api_key=api_key,
88
+ agent_id=agent_id or "langgraph-agent",
89
+ )
90
+
91
+ # LlamaIndex QueryEngine
92
+ if "llama_index" in module or "llamaindex" in module or "QueryEngine" in agent_type:
93
+ from .integrations.llamaindex import GovernorAIQueryEngine
94
+ client = GovernorAIClient(base_url=governor_url, api_key=api_key)
95
+ return GovernorAIQueryEngine(
96
+ query_engine=agent,
97
+ governor_client=client,
98
+ agent_id=agent_id or "llamaindex-agent",
99
+ namespace=namespace,
100
+ )
101
+
102
+ raise TypeError(
103
+ f"Cannot auto-detect framework for {agent_type} from {module}. "
104
+ f"Use framework-specific wrappers instead:\n"
105
+ f" from governor.integrations.langchain import wrap_agent\n"
106
+ f" from governor.integrations.crewai import GovernorAICrew\n"
107
+ f" from governor.integrations.langgraph import GovernedToolNode\n"
108
+ f" from governor.integrations.llamaindex import GovernedQueryEngine"
109
+ )
@@ -0,0 +1,4 @@
1
+ """Allow running GovernorAI CLI as: python -m governor"""
2
+ from .cli import main
3
+
4
+ main()
@@ -0,0 +1,210 @@
1
+ """GovernorAI CLI — terminal-first developer experience.
2
+
3
+ Usage:
4
+ python -m governor init # Configure access
5
+ python -m governor test # Send a test governed action
6
+ python -m governor status # Check connection and policy status
7
+ """
8
+
9
+ import argparse
10
+ import json
11
+ import os
12
+ import sys
13
+ from pathlib import Path
14
+
15
+ from .client import GovernorAIClient, GovernorAIError
16
+
17
+
18
+ CONFIG_FILE = ".governor.env"
19
+ ENV_URL = "GOVERNOR_URL"
20
+ ENV_KEY = "GOVERNOR_API_KEY"
21
+
22
+
23
+ def get_client():
24
+ """Create a client from env vars or config file."""
25
+ url = os.environ.get(ENV_URL)
26
+ key = os.environ.get(ENV_KEY)
27
+
28
+ if not url or not key:
29
+ # Try .env-style config file (KEY=VALUE format, no YAML dependency)
30
+ config_path = Path(CONFIG_FILE)
31
+ if config_path.exists():
32
+ with open(config_path) as f:
33
+ for line in f:
34
+ line = line.strip()
35
+ if line.startswith("#") or "=" not in line:
36
+ continue
37
+ k, v = line.split("=", 1)
38
+ k, v = k.strip(), v.strip()
39
+ if k == "GOVERNOR_URL" and not url:
40
+ url = v
41
+ elif k == "GOVERNOR_API_KEY" and not key:
42
+ key = v
43
+
44
+ if not url:
45
+ print(f"Error: Set {ENV_URL} or create {CONFIG_FILE}")
46
+ sys.exit(1)
47
+ if not key:
48
+ print(f"Error: Set {ENV_KEY} or create {CONFIG_FILE}")
49
+ sys.exit(1)
50
+
51
+ return GovernorAIClient(base_url=url, api_key=key)
52
+
53
+
54
+ def cmd_init(args):
55
+ """Configure GovernorAI access."""
56
+ url = args.url or input(f"GovernorAI Gateway URL [{os.environ.get(ENV_URL, 'https://gateway.governorai.ai')}]: ").strip()
57
+ if not url:
58
+ url = os.environ.get(ENV_URL, "https://gateway.governorai.ai")
59
+
60
+ key = args.key or input("API Key: ").strip()
61
+ if not key:
62
+ print("Error: API key is required.")
63
+ sys.exit(1)
64
+
65
+ # Test connectivity
66
+ print(f"\nTesting connection to {url}...")
67
+ client = GovernorAIClient(base_url=url, api_key=key)
68
+ try:
69
+ # Try a simple health check or list policies
70
+ result = client.execute(
71
+ agent_id="governorai-cli-test",
72
+ tool="cli.init.ping",
73
+ args={"purpose": "connectivity_test"},
74
+ )
75
+ print(f"✓ Connected! Decision: {result.get('decision', 'ALLOW')}")
76
+ except GovernorAIError as e:
77
+ # Even a DENY is a successful connection
78
+ if "denied" in str(e).lower() or "blocked" in str(e).lower():
79
+ print(f"✓ Connected! (Policy denied test action — governance is working)")
80
+ else:
81
+ print(f"✗ Connection failed: {e}")
82
+ sys.exit(1)
83
+ except Exception as e:
84
+ print(f"✗ Connection failed: {e}")
85
+ sys.exit(1)
86
+
87
+ # Save config (.env format — no YAML dependency)
88
+ print(f"\nSaving to {CONFIG_FILE}...")
89
+ with open(CONFIG_FILE, "w") as f:
90
+ f.write(f"# GovernorAI configuration\n")
91
+ f.write(f"GOVERNOR_URL={url}\n")
92
+ f.write(f"GOVERNOR_API_KEY={key}\n")
93
+ print(f"✓ Config saved to {CONFIG_FILE}")
94
+ print(f"\nYou can also set environment variables:")
95
+ print(f" export {ENV_URL}={url}")
96
+ print(f" export {ENV_KEY}={key}")
97
+
98
+
99
+ def cmd_test(args):
100
+ """Send a test governed action."""
101
+ client = get_client()
102
+ agent_id = args.agent or "cli-test-agent"
103
+ tool = args.tool or "cli.test.action"
104
+ raw_args = args.args
105
+
106
+ test_args = {}
107
+ if raw_args:
108
+ try:
109
+ test_args = json.loads(raw_args)
110
+ except json.JSONDecodeError:
111
+ print(f"Error: --args must be valid JSON, got: {raw_args}")
112
+ sys.exit(1)
113
+ else:
114
+ # Default test payload that should trigger a deny with the starter policy
115
+ test_args = {
116
+ "destination_external": True,
117
+ "contains_pii": True,
118
+ "payload_preview": "Test PII data",
119
+ }
120
+
121
+ print(f"Sending governed action...")
122
+ print(f" Agent: {agent_id}")
123
+ print(f" Tool: {tool}")
124
+ print(f" Args: {json.dumps(test_args, indent=2)}")
125
+ print()
126
+
127
+ try:
128
+ result = client.execute(
129
+ agent_id=agent_id,
130
+ tool=tool,
131
+ args=test_args,
132
+ )
133
+ decision = result.get("decision", "UNKNOWN")
134
+ reason = result.get("reason", "")
135
+ latency = result.get("latency_ms", "?")
136
+
137
+ if decision == "ALLOW":
138
+ print(f" ✓ Decision: ALLOW")
139
+ elif decision == "DENY":
140
+ print(f" ✗ Decision: DENY")
141
+ else:
142
+ print(f" ⚡ Decision: {decision}")
143
+
144
+ if reason:
145
+ print(f" Reason: {reason}")
146
+ print(f" Latency: {latency}ms")
147
+ print(f"\nView in dashboard → Events page")
148
+
149
+ except GovernorAIError as e:
150
+ print(f" ✗ Error: {e}")
151
+ sys.exit(1)
152
+
153
+
154
+ def cmd_status(args):
155
+ """Check connection and governance status."""
156
+ client = get_client()
157
+
158
+ print(f"GovernorAI Status")
159
+ print(f" URL: {client.base_url}")
160
+ print(f" Key: {client.api_key[:10]}..." if client.api_key else " Key: not set")
161
+ print()
162
+
163
+ # Test connectivity
164
+ try:
165
+ result = client.execute(
166
+ agent_id="governorai-cli-status",
167
+ tool="cli.status.ping",
168
+ args={"purpose": "status_check"},
169
+ )
170
+ print(f" Connection: ✓ OK")
171
+ print(f" Decision: {result.get('decision', 'ALLOW')}")
172
+ except GovernorAIError as e:
173
+ if "denied" in str(e).lower():
174
+ print(f" Connection: ✓ OK (policy active)")
175
+ else:
176
+ print(f" Connection: ✗ Failed ({e})")
177
+ except Exception as e:
178
+ print(f" Connection: ✗ Failed ({e})")
179
+
180
+
181
+ def main():
182
+ parser = argparse.ArgumentParser(
183
+ prog="governorai",
184
+ description="GovernorAI CLI — AI governance from your terminal",
185
+ )
186
+ subparsers = parser.add_subparsers(dest="command", required=True)
187
+
188
+ # init
189
+ init_parser = subparsers.add_parser("init", help="Configure GovernorAI access")
190
+ init_parser.add_argument("--url", help="Gateway URL")
191
+ init_parser.add_argument("--key", help="API key")
192
+ init_parser.set_defaults(func=cmd_init)
193
+
194
+ # test
195
+ test_parser = subparsers.add_parser("test", help="Send a test governed action")
196
+ test_parser.add_argument("--agent", help="Agent ID (default: cli-test-agent)")
197
+ test_parser.add_argument("--tool", help="Tool name (default: cli.test.action)")
198
+ test_parser.add_argument("--args", help="JSON args (default: PII test payload)")
199
+ test_parser.set_defaults(func=cmd_test)
200
+
201
+ # status
202
+ status_parser = subparsers.add_parser("status", help="Check connection status")
203
+ status_parser.set_defaults(func=cmd_status)
204
+
205
+ args = parser.parse_args()
206
+ args.func(args)
207
+
208
+
209
+ if __name__ == "__main__":
210
+ main()