cortexhub 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.
- cortexhub-0.1.0/.gitignore +100 -0
- cortexhub-0.1.0/PKG-INFO +275 -0
- cortexhub-0.1.0/README.md +215 -0
- cortexhub-0.1.0/pyproject.toml +145 -0
- cortexhub-0.1.0/src/cortexhub/__init__.py +143 -0
- cortexhub-0.1.0/src/cortexhub/adapters/__init__.py +5 -0
- cortexhub-0.1.0/src/cortexhub/adapters/base.py +131 -0
- cortexhub-0.1.0/src/cortexhub/adapters/claude_agents.py +322 -0
- cortexhub-0.1.0/src/cortexhub/adapters/crewai.py +297 -0
- cortexhub-0.1.0/src/cortexhub/adapters/langgraph.py +386 -0
- cortexhub-0.1.0/src/cortexhub/adapters/openai_agents.py +192 -0
- cortexhub-0.1.0/src/cortexhub/audit/__init__.py +25 -0
- cortexhub-0.1.0/src/cortexhub/audit/events.py +165 -0
- cortexhub-0.1.0/src/cortexhub/auto_protect.py +128 -0
- cortexhub-0.1.0/src/cortexhub/backend/__init__.py +5 -0
- cortexhub-0.1.0/src/cortexhub/backend/client.py +348 -0
- cortexhub-0.1.0/src/cortexhub/client.py +2149 -0
- cortexhub-0.1.0/src/cortexhub/config.py +37 -0
- cortexhub-0.1.0/src/cortexhub/context/__init__.py +5 -0
- cortexhub-0.1.0/src/cortexhub/context/enricher.py +172 -0
- cortexhub-0.1.0/src/cortexhub/errors.py +123 -0
- cortexhub-0.1.0/src/cortexhub/frameworks.py +83 -0
- cortexhub-0.1.0/src/cortexhub/guardrails/__init__.py +3 -0
- cortexhub-0.1.0/src/cortexhub/guardrails/injection.py +180 -0
- cortexhub-0.1.0/src/cortexhub/guardrails/pii.py +378 -0
- cortexhub-0.1.0/src/cortexhub/guardrails/secrets.py +206 -0
- cortexhub-0.1.0/src/cortexhub/interceptors/__init__.py +3 -0
- cortexhub-0.1.0/src/cortexhub/interceptors/llm.py +62 -0
- cortexhub-0.1.0/src/cortexhub/interceptors/mcp.py +96 -0
- cortexhub-0.1.0/src/cortexhub/pipeline.py +92 -0
- cortexhub-0.1.0/src/cortexhub/policy/__init__.py +6 -0
- cortexhub-0.1.0/src/cortexhub/policy/effects.py +87 -0
- cortexhub-0.1.0/src/cortexhub/policy/evaluator.py +267 -0
- cortexhub-0.1.0/src/cortexhub/policy/loader.py +158 -0
- cortexhub-0.1.0/src/cortexhub/policy/models.py +123 -0
- cortexhub-0.1.0/src/cortexhub/policy/sync.py +183 -0
- cortexhub-0.1.0/src/cortexhub/telemetry/__init__.py +40 -0
- cortexhub-0.1.0/src/cortexhub/telemetry/otel.py +481 -0
- cortexhub-0.1.0/src/cortexhub/version.py +3 -0
- cortexhub-0.1.0/tests/__init__.py +1 -0
- cortexhub-0.1.0/tests/fixtures/__init__.py +1 -0
- cortexhub-0.1.0/tests/integration/__init__.py +1 -0
- cortexhub-0.1.0/tests/unit/__init__.py +1 -0
- cortexhub-0.1.0/tests/unit/test_guardrails.py +89 -0
- cortexhub-0.1.0/tests/unit/test_policy.py +72 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.ruff_cache/
|
|
24
|
+
.mypy_cache/
|
|
25
|
+
.coverage
|
|
26
|
+
htmlcov/
|
|
27
|
+
.venv/
|
|
28
|
+
venv/
|
|
29
|
+
ENV/
|
|
30
|
+
uv.lock
|
|
31
|
+
|
|
32
|
+
# Rust
|
|
33
|
+
target/
|
|
34
|
+
Cargo.lock
|
|
35
|
+
**/*.rs.bk
|
|
36
|
+
*.pdb
|
|
37
|
+
|
|
38
|
+
# Go
|
|
39
|
+
*.exe
|
|
40
|
+
*.exe~
|
|
41
|
+
*.dll
|
|
42
|
+
*.so
|
|
43
|
+
*.dylib
|
|
44
|
+
*.test
|
|
45
|
+
*.out
|
|
46
|
+
go.work
|
|
47
|
+
vendor/
|
|
48
|
+
|
|
49
|
+
# Java
|
|
50
|
+
target/
|
|
51
|
+
pom.xml.tag
|
|
52
|
+
pom.xml.releaseBackup
|
|
53
|
+
pom.xml.versionsBackup
|
|
54
|
+
pom.xml.next
|
|
55
|
+
release.properties
|
|
56
|
+
dependency-reduced-pom.xml
|
|
57
|
+
buildNumber.properties
|
|
58
|
+
.mvn/timing.properties
|
|
59
|
+
.mvn/wrapper/maven-wrapper.jar
|
|
60
|
+
*.class
|
|
61
|
+
*.jar
|
|
62
|
+
*.war
|
|
63
|
+
*.ear
|
|
64
|
+
hs_err_pid*
|
|
65
|
+
|
|
66
|
+
# TypeScript/JavaScript
|
|
67
|
+
node_modules/
|
|
68
|
+
dist/
|
|
69
|
+
build/
|
|
70
|
+
*.tsbuildinfo
|
|
71
|
+
.turbo/
|
|
72
|
+
.next/
|
|
73
|
+
.cache/
|
|
74
|
+
coverage/
|
|
75
|
+
|
|
76
|
+
# IDE
|
|
77
|
+
.vscode/
|
|
78
|
+
.idea/
|
|
79
|
+
*.swp
|
|
80
|
+
*.swo
|
|
81
|
+
*~
|
|
82
|
+
.DS_Store
|
|
83
|
+
|
|
84
|
+
# Logs
|
|
85
|
+
*.log
|
|
86
|
+
npm-debug.log*
|
|
87
|
+
yarn-debug.log*
|
|
88
|
+
yarn-error.log*
|
|
89
|
+
pnpm-debug.log*
|
|
90
|
+
|
|
91
|
+
# Environment
|
|
92
|
+
.env
|
|
93
|
+
.env.local
|
|
94
|
+
.env.*.local
|
|
95
|
+
|
|
96
|
+
# OS
|
|
97
|
+
.DS_Store
|
|
98
|
+
Thumbs.db
|
|
99
|
+
python/cortexhub_data
|
|
100
|
+
|
cortexhub-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexhub
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CortexHub Python SDK - Policy-as-Code for AI Agents
|
|
5
|
+
Project-URL: Homepage, https://cortexhub.ai
|
|
6
|
+
Project-URL: Documentation, https://docs.cortexhub.ai
|
|
7
|
+
Project-URL: Repository, https://github.com/cortexhub/sdks
|
|
8
|
+
Project-URL: Issues, https://github.com/cortexhub/sdks/issues
|
|
9
|
+
Author-email: CortexHub <hello@cortexhub.ai>
|
|
10
|
+
License: MIT
|
|
11
|
+
Keywords: agents,ai,authorization,cedar,governance,policy
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: <3.14,>=3.10
|
|
22
|
+
Requires-Dist: cedarpy>=4.0.0
|
|
23
|
+
Requires-Dist: detect-secrets>=1.5.0
|
|
24
|
+
Requires-Dist: httpx>=0.28.0
|
|
25
|
+
Requires-Dist: opentelemetry-api>=1.20.0
|
|
26
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.20.0
|
|
27
|
+
Requires-Dist: opentelemetry-sdk>=1.20.0
|
|
28
|
+
Requires-Dist: pip>=23.0
|
|
29
|
+
Requires-Dist: presidio-analyzer>=2.2.360
|
|
30
|
+
Requires-Dist: presidio-anonymizer>=2.2.360
|
|
31
|
+
Requires-Dist: pydantic>=2.9.0
|
|
32
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
33
|
+
Requires-Dist: structlog>=24.4.0
|
|
34
|
+
Provides-Extra: all
|
|
35
|
+
Requires-Dist: anthropic>=0.40.0; extra == 'all'
|
|
36
|
+
Requires-Dist: claude-agent-sdk>=0.0.1; extra == 'all'
|
|
37
|
+
Requires-Dist: crewai>=0.50.0; extra == 'all'
|
|
38
|
+
Requires-Dist: langchain-core>=0.2.0; extra == 'all'
|
|
39
|
+
Requires-Dist: langchain-openai>=0.1.0; extra == 'all'
|
|
40
|
+
Requires-Dist: langgraph>=0.2.0; extra == 'all'
|
|
41
|
+
Requires-Dist: openai-agents>=0.0.3; extra == 'all'
|
|
42
|
+
Provides-Extra: claude-agents
|
|
43
|
+
Requires-Dist: anthropic>=0.40.0; extra == 'claude-agents'
|
|
44
|
+
Requires-Dist: claude-agent-sdk>=0.0.1; extra == 'claude-agents'
|
|
45
|
+
Provides-Extra: crewai
|
|
46
|
+
Requires-Dist: crewai>=0.50.0; extra == 'crewai'
|
|
47
|
+
Provides-Extra: dev
|
|
48
|
+
Requires-Dist: mypy>=1.10.0; extra == 'dev'
|
|
49
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
50
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
51
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
52
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
53
|
+
Provides-Extra: langgraph
|
|
54
|
+
Requires-Dist: langchain-core>=0.2.0; extra == 'langgraph'
|
|
55
|
+
Requires-Dist: langchain-openai>=0.1.0; extra == 'langgraph'
|
|
56
|
+
Requires-Dist: langgraph>=0.2.0; extra == 'langgraph'
|
|
57
|
+
Provides-Extra: openai-agents
|
|
58
|
+
Requires-Dist: openai-agents>=0.0.3; extra == 'openai-agents'
|
|
59
|
+
Description-Content-Type: text/markdown
|
|
60
|
+
|
|
61
|
+
# CortexHub Python SDK
|
|
62
|
+
|
|
63
|
+
**Runtime Governance for AI Agents** - Policy enforcement, PII/secrets detection, complete audit trails with OpenTelemetry.
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Core SDK
|
|
69
|
+
pip install cortexhub
|
|
70
|
+
|
|
71
|
+
# With framework support (choose one or more)
|
|
72
|
+
pip install cortexhub[langchain] # LangChain/LangGraph
|
|
73
|
+
pip install cortexhub[crewai] # CrewAI
|
|
74
|
+
pip install cortexhub[openai-agents] # OpenAI Agents SDK
|
|
75
|
+
pip install cortexhub[llamaindex] # LlamaIndex
|
|
76
|
+
pip install cortexhub[litellm] # LiteLLM
|
|
77
|
+
|
|
78
|
+
# All frameworks (for development)
|
|
79
|
+
pip install cortexhub[all]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from cortexhub import init, Framework
|
|
86
|
+
|
|
87
|
+
# Initialize CortexHub FIRST, before importing your framework
|
|
88
|
+
cortex = init(
|
|
89
|
+
agent_id="customer_support_agent",
|
|
90
|
+
framework=Framework.LANGCHAIN, # or CREWAI, OPENAI_AGENTS, etc.
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# Now import and use your framework
|
|
94
|
+
from langchain_core.tools import tool
|
|
95
|
+
|
|
96
|
+
@tool
|
|
97
|
+
def process_refund(customer_id: str, amount: float) -> dict:
|
|
98
|
+
"""Process a customer refund."""
|
|
99
|
+
return {"status": "processed", "amount": amount}
|
|
100
|
+
|
|
101
|
+
# All tool calls are now governed!
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Supported Frameworks
|
|
105
|
+
|
|
106
|
+
| Framework | Enum Value | Install |
|
|
107
|
+
|-----------|------------|---------|
|
|
108
|
+
| LangChain | `Framework.LANGCHAIN` | `pip install cortexhub[langchain]` |
|
|
109
|
+
| LangGraph | `Framework.LANGCHAIN` | `pip install cortexhub[langchain]` |
|
|
110
|
+
| CrewAI | `Framework.CREWAI` | `pip install cortexhub[crewai]` |
|
|
111
|
+
| OpenAI Agents | `Framework.OPENAI_AGENTS` | `pip install cortexhub[openai-agents]` |
|
|
112
|
+
| LlamaIndex | `Framework.LLAMAINDEX` | `pip install cortexhub[llamaindex]` |
|
|
113
|
+
| LiteLLM | `Framework.LITELLM` | `pip install cortexhub[litellm]` |
|
|
114
|
+
|
|
115
|
+
## Configuration
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Required: API key for telemetry
|
|
119
|
+
export CORTEXHUB_API_KEY=ch_live_...
|
|
120
|
+
|
|
121
|
+
# Optional: Backend URL (defaults to production)
|
|
122
|
+
export CORTEXHUB_API_URL=https://api.cortexhub.ai
|
|
123
|
+
|
|
124
|
+
# Optional: OpenAI key for LLM-based examples
|
|
125
|
+
export OPENAI_API_KEY=sk-...
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Features
|
|
129
|
+
|
|
130
|
+
- **Policy Enforcement** - Cedar-based policies, local evaluation
|
|
131
|
+
- **PII Detection** - Presidio-powered, 50+ entity types, configurable
|
|
132
|
+
- **Secrets Detection** - detect-secrets integration, 30+ secret types
|
|
133
|
+
- **Configurable Guardrails** - Select specific PII/secret types to redact
|
|
134
|
+
- **Custom Patterns** - Add company-specific regex patterns
|
|
135
|
+
- **OpenTelemetry** - Industry-standard observability
|
|
136
|
+
- **Framework Adapters** - Automatic interception for all major frameworks
|
|
137
|
+
- **Privacy Mode** - Metadata-only by default, safe for production
|
|
138
|
+
|
|
139
|
+
## Privacy Modes
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
# Production (default) - only metadata sent
|
|
143
|
+
cortex = init(agent_id="...", framework=..., privacy=True)
|
|
144
|
+
# Sends: tool names, arg schemas, PII types detected
|
|
145
|
+
# Never: raw values, prompts, responses
|
|
146
|
+
|
|
147
|
+
# Development - full data for testing policies
|
|
148
|
+
cortex = init(agent_id="...", framework=..., privacy=False)
|
|
149
|
+
# Also sends: raw args, results, prompts (for policy testing)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Policy Enforcement
|
|
153
|
+
|
|
154
|
+
Policies are created in the CortexHub dashboard from detected risks. The SDK automatically fetches and enforces them:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from cortexhub.errors import PolicyViolationError, ApprovalRequiredError
|
|
158
|
+
|
|
159
|
+
# Policies are fetched automatically during init()
|
|
160
|
+
# If policies exist, enforcement mode is enabled
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
agent.run("Process a $10,000 refund")
|
|
164
|
+
except PolicyViolationError as e:
|
|
165
|
+
print(f"Blocked by policy: {e.policy_name}")
|
|
166
|
+
print(f"Reason: {e.reasoning}")
|
|
167
|
+
except ApprovalRequiredError as e:
|
|
168
|
+
print(f"\n⏸️ APPROVAL REQUIRED")
|
|
169
|
+
print(f" Approval ID: {e.approval_id}")
|
|
170
|
+
print(f" Tool: {e.tool_name}")
|
|
171
|
+
print(f" Reason: {e.reason}")
|
|
172
|
+
print(f" Expires: {e.expires_at}")
|
|
173
|
+
print(f"\n Decision endpoint: {e.decision_endpoint}")
|
|
174
|
+
print(f" Configure a webhook to receive approval.decisioned event")
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Guardrail Configuration
|
|
178
|
+
|
|
179
|
+
Guardrails detect PII and secrets in LLM prompts. Configure in the dashboard:
|
|
180
|
+
|
|
181
|
+
1. **Select types to redact**: Choose specific PII types (email, phone, etc.)
|
|
182
|
+
2. **Add custom patterns**: Regex for company-specific data (employee IDs, etc.)
|
|
183
|
+
3. **Choose action**: Redact, block, or monitor only
|
|
184
|
+
|
|
185
|
+
The SDK applies your configuration automatically:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# With guardrail policy active:
|
|
189
|
+
# Input prompt: "Contact john@email.com about employee EMP-123456"
|
|
190
|
+
# After redaction: "Contact [REDACTED-EMAIL_ADDRESS] about employee [REDACTED-CUSTOM_EMPLOYEE_ID]"
|
|
191
|
+
# Only configured types are redacted
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Examples
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
cd python/examples
|
|
198
|
+
|
|
199
|
+
# LangChain customer support
|
|
200
|
+
python langchain_example.py
|
|
201
|
+
|
|
202
|
+
# LangGraph fraud investigation
|
|
203
|
+
python langgraph_example.py
|
|
204
|
+
|
|
205
|
+
# CrewAI financial operations
|
|
206
|
+
python crewai_example.py
|
|
207
|
+
|
|
208
|
+
# OpenAI Agents research assistant
|
|
209
|
+
python openai_agents_example.py
|
|
210
|
+
|
|
211
|
+
# LiteLLM multi-provider
|
|
212
|
+
python litellm_example.py
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Important: Initialization Order
|
|
216
|
+
|
|
217
|
+
**Always initialize CortexHub FIRST**, before importing your framework:
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
# ✅ CORRECT
|
|
221
|
+
from cortexhub import init, Framework
|
|
222
|
+
cortex = init(agent_id="my_agent", framework=Framework.LANGCHAIN)
|
|
223
|
+
|
|
224
|
+
from langchain_core.tools import tool # Import AFTER init
|
|
225
|
+
|
|
226
|
+
# ❌ WRONG
|
|
227
|
+
from langchain_core.tools import tool # Framework imported first
|
|
228
|
+
from cortexhub import init, Framework
|
|
229
|
+
cortex = init(...) # Too late!
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
This ensures:
|
|
233
|
+
1. CortexHub sets up OpenTelemetry before frameworks that also use it
|
|
234
|
+
2. Framework decorators/classes are properly wrapped
|
|
235
|
+
|
|
236
|
+
## Architecture
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
Agent Decides → [CortexHub] → Agent Executes
|
|
240
|
+
│
|
|
241
|
+
┌─────┴─────┐
|
|
242
|
+
│ │
|
|
243
|
+
Policy Guardrails
|
|
244
|
+
Engine (PII/Secrets)
|
|
245
|
+
│ │
|
|
246
|
+
└─────┬─────┘
|
|
247
|
+
│
|
|
248
|
+
OpenTelemetry
|
|
249
|
+
(to backend)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Development
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
cd python
|
|
256
|
+
|
|
257
|
+
# Install with all frameworks
|
|
258
|
+
uv sync --all-extras
|
|
259
|
+
|
|
260
|
+
# Run tests
|
|
261
|
+
uv run pytest
|
|
262
|
+
|
|
263
|
+
# Lint
|
|
264
|
+
uv run ruff check .
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Links
|
|
268
|
+
|
|
269
|
+
- [Documentation](https://docs.cortexhub.ai)
|
|
270
|
+
- [Dashboard](https://app.cortexhub.ai)
|
|
271
|
+
- [Issues](https://github.com/cortexhub/sdks/issues)
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# CortexHub Python SDK
|
|
2
|
+
|
|
3
|
+
**Runtime Governance for AI Agents** - Policy enforcement, PII/secrets detection, complete audit trails with OpenTelemetry.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Core SDK
|
|
9
|
+
pip install cortexhub
|
|
10
|
+
|
|
11
|
+
# With framework support (choose one or more)
|
|
12
|
+
pip install cortexhub[langchain] # LangChain/LangGraph
|
|
13
|
+
pip install cortexhub[crewai] # CrewAI
|
|
14
|
+
pip install cortexhub[openai-agents] # OpenAI Agents SDK
|
|
15
|
+
pip install cortexhub[llamaindex] # LlamaIndex
|
|
16
|
+
pip install cortexhub[litellm] # LiteLLM
|
|
17
|
+
|
|
18
|
+
# All frameworks (for development)
|
|
19
|
+
pip install cortexhub[all]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from cortexhub import init, Framework
|
|
26
|
+
|
|
27
|
+
# Initialize CortexHub FIRST, before importing your framework
|
|
28
|
+
cortex = init(
|
|
29
|
+
agent_id="customer_support_agent",
|
|
30
|
+
framework=Framework.LANGCHAIN, # or CREWAI, OPENAI_AGENTS, etc.
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Now import and use your framework
|
|
34
|
+
from langchain_core.tools import tool
|
|
35
|
+
|
|
36
|
+
@tool
|
|
37
|
+
def process_refund(customer_id: str, amount: float) -> dict:
|
|
38
|
+
"""Process a customer refund."""
|
|
39
|
+
return {"status": "processed", "amount": amount}
|
|
40
|
+
|
|
41
|
+
# All tool calls are now governed!
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Supported Frameworks
|
|
45
|
+
|
|
46
|
+
| Framework | Enum Value | Install |
|
|
47
|
+
|-----------|------------|---------|
|
|
48
|
+
| LangChain | `Framework.LANGCHAIN` | `pip install cortexhub[langchain]` |
|
|
49
|
+
| LangGraph | `Framework.LANGCHAIN` | `pip install cortexhub[langchain]` |
|
|
50
|
+
| CrewAI | `Framework.CREWAI` | `pip install cortexhub[crewai]` |
|
|
51
|
+
| OpenAI Agents | `Framework.OPENAI_AGENTS` | `pip install cortexhub[openai-agents]` |
|
|
52
|
+
| LlamaIndex | `Framework.LLAMAINDEX` | `pip install cortexhub[llamaindex]` |
|
|
53
|
+
| LiteLLM | `Framework.LITELLM` | `pip install cortexhub[litellm]` |
|
|
54
|
+
|
|
55
|
+
## Configuration
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Required: API key for telemetry
|
|
59
|
+
export CORTEXHUB_API_KEY=ch_live_...
|
|
60
|
+
|
|
61
|
+
# Optional: Backend URL (defaults to production)
|
|
62
|
+
export CORTEXHUB_API_URL=https://api.cortexhub.ai
|
|
63
|
+
|
|
64
|
+
# Optional: OpenAI key for LLM-based examples
|
|
65
|
+
export OPENAI_API_KEY=sk-...
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Features
|
|
69
|
+
|
|
70
|
+
- **Policy Enforcement** - Cedar-based policies, local evaluation
|
|
71
|
+
- **PII Detection** - Presidio-powered, 50+ entity types, configurable
|
|
72
|
+
- **Secrets Detection** - detect-secrets integration, 30+ secret types
|
|
73
|
+
- **Configurable Guardrails** - Select specific PII/secret types to redact
|
|
74
|
+
- **Custom Patterns** - Add company-specific regex patterns
|
|
75
|
+
- **OpenTelemetry** - Industry-standard observability
|
|
76
|
+
- **Framework Adapters** - Automatic interception for all major frameworks
|
|
77
|
+
- **Privacy Mode** - Metadata-only by default, safe for production
|
|
78
|
+
|
|
79
|
+
## Privacy Modes
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
# Production (default) - only metadata sent
|
|
83
|
+
cortex = init(agent_id="...", framework=..., privacy=True)
|
|
84
|
+
# Sends: tool names, arg schemas, PII types detected
|
|
85
|
+
# Never: raw values, prompts, responses
|
|
86
|
+
|
|
87
|
+
# Development - full data for testing policies
|
|
88
|
+
cortex = init(agent_id="...", framework=..., privacy=False)
|
|
89
|
+
# Also sends: raw args, results, prompts (for policy testing)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Policy Enforcement
|
|
93
|
+
|
|
94
|
+
Policies are created in the CortexHub dashboard from detected risks. The SDK automatically fetches and enforces them:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from cortexhub.errors import PolicyViolationError, ApprovalRequiredError
|
|
98
|
+
|
|
99
|
+
# Policies are fetched automatically during init()
|
|
100
|
+
# If policies exist, enforcement mode is enabled
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
agent.run("Process a $10,000 refund")
|
|
104
|
+
except PolicyViolationError as e:
|
|
105
|
+
print(f"Blocked by policy: {e.policy_name}")
|
|
106
|
+
print(f"Reason: {e.reasoning}")
|
|
107
|
+
except ApprovalRequiredError as e:
|
|
108
|
+
print(f"\n⏸️ APPROVAL REQUIRED")
|
|
109
|
+
print(f" Approval ID: {e.approval_id}")
|
|
110
|
+
print(f" Tool: {e.tool_name}")
|
|
111
|
+
print(f" Reason: {e.reason}")
|
|
112
|
+
print(f" Expires: {e.expires_at}")
|
|
113
|
+
print(f"\n Decision endpoint: {e.decision_endpoint}")
|
|
114
|
+
print(f" Configure a webhook to receive approval.decisioned event")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Guardrail Configuration
|
|
118
|
+
|
|
119
|
+
Guardrails detect PII and secrets in LLM prompts. Configure in the dashboard:
|
|
120
|
+
|
|
121
|
+
1. **Select types to redact**: Choose specific PII types (email, phone, etc.)
|
|
122
|
+
2. **Add custom patterns**: Regex for company-specific data (employee IDs, etc.)
|
|
123
|
+
3. **Choose action**: Redact, block, or monitor only
|
|
124
|
+
|
|
125
|
+
The SDK applies your configuration automatically:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
# With guardrail policy active:
|
|
129
|
+
# Input prompt: "Contact john@email.com about employee EMP-123456"
|
|
130
|
+
# After redaction: "Contact [REDACTED-EMAIL_ADDRESS] about employee [REDACTED-CUSTOM_EMPLOYEE_ID]"
|
|
131
|
+
# Only configured types are redacted
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Examples
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
cd python/examples
|
|
138
|
+
|
|
139
|
+
# LangChain customer support
|
|
140
|
+
python langchain_example.py
|
|
141
|
+
|
|
142
|
+
# LangGraph fraud investigation
|
|
143
|
+
python langgraph_example.py
|
|
144
|
+
|
|
145
|
+
# CrewAI financial operations
|
|
146
|
+
python crewai_example.py
|
|
147
|
+
|
|
148
|
+
# OpenAI Agents research assistant
|
|
149
|
+
python openai_agents_example.py
|
|
150
|
+
|
|
151
|
+
# LiteLLM multi-provider
|
|
152
|
+
python litellm_example.py
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Important: Initialization Order
|
|
156
|
+
|
|
157
|
+
**Always initialize CortexHub FIRST**, before importing your framework:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
# ✅ CORRECT
|
|
161
|
+
from cortexhub import init, Framework
|
|
162
|
+
cortex = init(agent_id="my_agent", framework=Framework.LANGCHAIN)
|
|
163
|
+
|
|
164
|
+
from langchain_core.tools import tool # Import AFTER init
|
|
165
|
+
|
|
166
|
+
# ❌ WRONG
|
|
167
|
+
from langchain_core.tools import tool # Framework imported first
|
|
168
|
+
from cortexhub import init, Framework
|
|
169
|
+
cortex = init(...) # Too late!
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
This ensures:
|
|
173
|
+
1. CortexHub sets up OpenTelemetry before frameworks that also use it
|
|
174
|
+
2. Framework decorators/classes are properly wrapped
|
|
175
|
+
|
|
176
|
+
## Architecture
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
Agent Decides → [CortexHub] → Agent Executes
|
|
180
|
+
│
|
|
181
|
+
┌─────┴─────┐
|
|
182
|
+
│ │
|
|
183
|
+
Policy Guardrails
|
|
184
|
+
Engine (PII/Secrets)
|
|
185
|
+
│ │
|
|
186
|
+
└─────┬─────┘
|
|
187
|
+
│
|
|
188
|
+
OpenTelemetry
|
|
189
|
+
(to backend)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
cd python
|
|
196
|
+
|
|
197
|
+
# Install with all frameworks
|
|
198
|
+
uv sync --all-extras
|
|
199
|
+
|
|
200
|
+
# Run tests
|
|
201
|
+
uv run pytest
|
|
202
|
+
|
|
203
|
+
# Lint
|
|
204
|
+
uv run ruff check .
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Links
|
|
208
|
+
|
|
209
|
+
- [Documentation](https://docs.cortexhub.ai)
|
|
210
|
+
- [Dashboard](https://app.cortexhub.ai)
|
|
211
|
+
- [Issues](https://github.com/cortexhub/sdks/issues)
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
MIT
|