Metadata-Version: 2.4
Name: rends-agent-sdk
Version: 2.0.0
Summary: Runtime interception SDK for AI agent governance
Author-email: Rends AI <hello@rends.ai>
License: MIT
Project-URL: Homepage, https://rends.ai/docs/sdk
Project-URL: Repository, https://github.com/eishops23/agentcompliant
Keywords: ai,agent,governance,compliance,langchain,crewai,autogen,openai-agents,google-adk,haystack,llamaindex,pydantic-ai,langgraph
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.25.0
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.2.0; extra == "langchain"
Provides-Extra: crewai
Requires-Dist: crewai>=0.28.0; extra == "crewai"
Provides-Extra: autogen
Requires-Dist: pyautogen>=0.2.0; extra == "autogen"
Provides-Extra: haystack
Requires-Dist: haystack-ai>=2.9.0; extra == "haystack"
Provides-Extra: llamaindex
Requires-Dist: llama-index-core>=0.11.0; extra == "llamaindex"
Provides-Extra: pydanticai
Requires-Dist: pydantic-ai>=1.0.0; extra == "pydanticai"
Provides-Extra: langgraph
Requires-Dist: langgraph>=0.2.0; extra == "langgraph"
Requires-Dist: langchain-core>=0.2.0; extra == "langgraph"
Provides-Extra: all
Requires-Dist: langchain-core>=0.2.0; extra == "all"
Requires-Dist: crewai>=0.28.0; extra == "all"
Requires-Dist: pyautogen>=0.2.0; extra == "all"
Requires-Dist: haystack-ai>=2.9.0; extra == "all"
Requires-Dist: llama-index-core>=0.11.0; extra == "all"
Requires-Dist: pydantic-ai>=1.0.0; extra == "all"
Requires-Dist: langgraph>=0.2.0; extra == "all"
Dynamic: license-file

# rends-agent-sdk

[![PyPI version](https://img.shields.io/pypi/v/rends-agent-sdk.svg)](https://pypi.org/project/rends-agent-sdk/)
[![Python versions](https://img.shields.io/pypi/pyversions/rends-agent-sdk.svg)](https://pypi.org/project/rends-agent-sdk/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Docs](https://img.shields.io/badge/docs-rends.ai%2Fdocs-blue.svg)](https://rends.ai/docs)

**Runtime governance for AI agents.** A small async SDK that wraps tool calls with synchronous policy enforcement, hash-chained audit logging, and compliance evidence — backed by the [Rends](https://rends.ai) platform.

```python
result = await client.govern(action, tool_fn=lambda p: db.query(p["q"]))
# → policy checked, decision logged, tool runs only if allowed
```

If the action violates policy, the tool function is **never invoked** and a `GovernanceBlockError` is raised. Every decision lands in a hash-chained audit trail that satisfies EU AI Act Article 12 logging requirements.

> Looking for TypeScript? See [`@rends/agent-sdk`](https://www.npmjs.com/package/@rends/agent-sdk) on npm ([source](../agent-sdk)).

## Install

```bash
pip install rends-agent-sdk

# With optional framework adapters
pip install "rends-agent-sdk[langchain]"
pip install "rends-agent-sdk[crewai]"
pip install "rends-agent-sdk[autogen]"
pip install "rends-agent-sdk[all]"
```

Requires Python ≥ 3.10.

## Quick start

```python
import os
from rends_sdk import RendsClient, RendsClientConfig, ActionContext

async with RendsClient(RendsClientConfig(
    api_key=os.environ["RENDS_API_KEY"],     # 'ac_live_...'
    org_id=os.environ["RENDS_ORG_ID"],
    agent_id=os.environ["RENDS_AGENT_ID"],
    mode="enforce",                          # 'enforce' | 'monitor' | 'dry-run'
)) as client:
    result = await client.govern(
        ActionContext(
            action_type="database_query",
            action_name="select_users",
            resource_type="customer_records",
            input_summary="SELECT * FROM users WHERE region = us-east-1",
            metadata={"data_classification": "pii"},
        ),
        tool_fn=lambda params: db.query(
            "SELECT * FROM users WHERE region = $1", params["region"]
        ),
    )

# result.allowed                       — bool
# result.status                        — CheckStatus.PASS / WARN / BLOCK
# result.result                        — the tool's return value (None if blocked)
# result.check.violations              — rules that returned severity=block
# result.telemetry_action_id           — id of the audit-trail row
```

You can sign up for an API key at [rends.ai/sign-up](https://rends.ai/sign-up).

## Enforcement modes

| Mode | Behavior |
|---|---|
| `enforce` | `block` → raises `GovernanceBlockError`; `pass`/`warn` → tool executes |
| `monitor` | All decisions logged; nothing blocked, except an agent stopped by the kill switch |
| `dry-run` | Policy checked, tool **not** executed, telemetry **not** sent |

`monitor` is the safe rollout default — turn enforcement on once you've reviewed a few days of decisions in the dashboard.

## Kill switch

When an agent is paused or terminated in Rends, its checks are refused and `govern()` raises `AgentStoppedError`
(a `GovernanceBlockError`) in `enforce` **and** `monitor` mode, so the tool does not run. Once the agent is resumed,
its checks are decided normally again.

Verified against production on 2026-10-30 with this release: paused agent → `AgentStoppedError`
("Agent is paused (kill switch); the action was not run") in `enforce` and `monitor`, tool not run; resumed → allowed,
tool ran; terminated → `AgentStoppedError`, tool not run.


## Framework adapters

All five adapters are reachable from `rends_sdk.adapters`. Each wraps a framework-native tool/function so the agent can keep using its idiomatic API while enforcement runs underneath.

### LangChain

```python
from rends_sdk.adapters import govern_tools, RendsCallbackHandler

governed = govern_tools(client, [search, calculator], resource_type="tool")
agent = create_react_agent(llm, tools=governed)

# Or attach a callback for monitor-only telemetry on existing tools:
agent.invoke({"input": "..."}, config={"callbacks": [RendsCallbackHandler(client)]})
```

→ [LangChain integration](https://rends.ai/docs/integrations/langchain) (if available; see API ref otherwise)

### CrewAI

```python
from rends_sdk.adapters import govern_crewai_tool

search = SerperDevTool()
governed = govern_crewai_tool(client, search, resource_type="web_search")
agent = Agent(tools=[governed], ...)
```

### AutoGen

```python
from rends_sdk.adapters import govern_autogen_tool

def search_web(query: str) -> str:
    return tavily.search(query)

governed = govern_autogen_tool(client, search_web, "search_web", resource_type="web_search")
agent.register_function(function_map={"search_web": governed})
```

### OpenAI Agents SDK

```python
from agents import Agent, function_tool
from rends_sdk.adapters import govern_openai_tool

@function_tool
def search_web(query: str) -> str:
    return tavily.search(query)

govern_openai_tool(client, search_web, resource_type="web_search")
agent = Agent(name="Assistant", tools=[search_web])
```

→ [OpenAI Agents SDK integration](https://rends.ai/docs/integrations/openai-agents)

### Google ADK

```python
from rends_sdk.adapters import govern_adk_tools, RendsADKCallback

governed = govern_adk_tools(client, tools, resource_type="tool")
agent = LlmAgent(name="assistant", tools=governed)
```

→ [Google ADK integration](https://rends.ai/docs/integrations/google-adk)

## OpenTelemetry

The SDK ships an OTel adapter that emits a span per governance decision with attributes you can pivot on in any OTLP backend (Jaeger, Datadog, Grafana Tempo, Honeycomb).

```python
from opentelemetry import trace
from rends_sdk.adapters import RendsOtelTracer

tracer = trace.get_tracer("my-app")
RendsOtelTracer(tracer).instrument(client)

# Every govern() call now emits a span automatically.
```

Span attributes: `rends.action_type`, `rends.action_name`, `rends.resource_type`, `rends.status` (`allowed`/`blocked`/`failed`), `rends.risk_level`, `rends.duration_ms`, `rends.org_id`, `rends.agent_id`, `rends.framework`. Policy violations are recorded as `policy.violation` span events.

`opentelemetry-api` is an **optional dependency** — install it only if you want OTel:

```bash
pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
```

→ [OpenTelemetry integration docs](https://rends.ai/docs/integrations/opentelemetry)

## Pipeline

Every `govern()` call runs five stages:

1. **beforeAction** — validates the action shape, computes a SHA-256 input hash.
2. **policyCheck** — `POST /v1/compliance/check-action` (synchronous, ≤ `timeout_s`).
3. **decisionReturn** — parses `{ allowed, status, violations, warnings }`.
4. **executionGate** — runs the tool when allowed; raises `GovernanceBlockError` otherwise (in `enforce`).
5. **telemetryEmit** — `POST /v1/telemetry/ingest` writes a hash-chained row to the audit trail.

Decisions are Redis-cached on the platform side for sub-50ms p95 latency on the hot path.

## API reference

### `RendsClientConfig`

| Field | Type | Default | Description |
|---|---|---|---|
| `api_key` | `str` | required | API key (`ac_live_...`) |
| `org_id` | `str` | required | Organization UUID |
| `agent_id` | `str` | required | Agent UUID registered in Deploy |
| `endpoint` | `str` | `https://rends.ai/api/v1` | Platform API base URL |
| `mode` | `EnforcementMode` | `ENFORCE` | `enforce` / `monitor` / `dry-run` |
| `timeout_s` | `float` | `10.0` | Policy-check timeout per call |
| `retries` | `int` | `2` | Retry count for transient failures |
| `fail_open` | `bool` | `False` | Allow action if policy check errors |
| `on_decision` | `Callable` | `None` | Fires after every decision |
| `on_error` | `Callable` | `None` | Fires on SDK-level errors |
| `headers` | `dict[str, str]` | `{}` | Extra HTTP headers |

### `ActionContext`

| Field | Type | Max | Description |
|---|---|---|---|
| `action_type` | `str` | 200 | Category — `tool_call`, `api_request`, `data_access`, … |
| `action_name` | `str` | 500 | Specific action — `database_query`, `send_email` |
| `resource_type` | `str` | 200 | Target — `customer_records`, `email_server` |
| `input_summary` | `str` | 8000 | Free-text description of the input |
| `metadata` | `dict` | — | Extra context (sent with telemetry, not policy check) |
| `policy_attributes` | `dict[str, str \| int \| float \| bool]` | 16 keys | Authority add-on: attributes such as `amount`, `currency`. Sent only when set (as `policyAttributes`). |
| `transaction_id` | `str` (uuid) | — | Marks the action as a step of one business transaction. Sent only when set. |

**Authority fields, today.** The production API accepts `policy_attributes` and `transaction_id` (verified 2026-10-30:
HTTP 200, no error). In the org tested, a check with `{"amount": 1, "currency": "USD"}` and a `transaction_id` returned
the same decision as without them, and the response carried no `authority` block. Whether a decision uses them depends
on the org's Authority configuration; that path has not been verified in production with this release.

### Errors

All exported from `rends_sdk`:

- `GovernanceBlockError` — raised in `enforce` mode when policy denies the action.
- `GovernancePendingError` — a `GovernanceBlockError` raised when the action is held for human approval; carries `decision_id` for `client.resume()`.
- `AgentStoppedError` — a `GovernanceBlockError` raised in `enforce` and `monitor` mode when the agent is paused or terminated (kill switch).
- `PolicyCheckTimeoutError` — raised when `timeout_s` is exceeded and `fail_open=False`.
- `ApiError` — non-2xx response from the platform.
- `ConfigError` — invalid client configuration.
- `RendsError` — base class.

## Pre-flight check

Want to inspect the policy decision **without** running the tool?

```python
check = await client.policy_check(ActionContext(
    action_type="data_export",
    action_name="export_pii",
    resource_type="user_data",
    input_summary="Export all PII to CSV",
))
# check.allowed, check.status, check.violations
```

## Documentation

- **Quick start** — [rends.ai/docs/quick-start](https://rends.ai/docs/quick-start)
- **Full API reference** — [rends.ai/docs](https://rends.ai/docs)
- **OWASP Agentic Top 10 mapping** — [rends.ai/docs/owasp-agentic-top-10](https://rends.ai/docs/owasp-agentic-top-10)
- **EU AI Act for AI Agents** — [rends.ai/docs/eu-ai-act-agents](https://rends.ai/docs/eu-ai-act-agents)
- **Audit trail** — [rends.ai/docs/audit-trail](https://rends.ai/docs/audit-trail)

## Contributing

Issues and pull requests welcome. See [CONTRIBUTING.md](.github/CONTRIBUTING.md).

## License

[MIT](./LICENSE) © 2026 Rends AI
