Metadata-Version: 2.5
Name: acgp
Version: 1.0.0a7
Summary: Official Python SDK for the Agentic Cognitive Governance Protocol (ACGP)
Project-URL: Homepage, https://github.com/Meaningstack-foundation/acgp-protocol
Project-URL: Documentation, https://acgp-protocol.org
Project-URL: Repository, https://github.com/Meaningstack-foundation/acgp-protocol
Project-URL: Issues, https://github.com/Meaningstack-foundation/acgp-protocol/issues
Author: MeaningStack
Maintainer-email: ACGP Maintainers <maintainers@acgp-protocol.org>
License-Expression: MIT
License-File: LICENSE
Keywords: acgp,agents,ai,governance,safety
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: eval-type-backport>=0.2.2; python_version < '3.10'
Requires-Dist: google-re2>=1.1
Requires-Dist: httpx>=0.27
Requires-Dist: jcs>=0.2.1
Requires-Dist: jsonschema>=4.0
Requires-Dist: pydantic>=2.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: requests>=2.28
Requires-Dist: typing-extensions>=4.5
Provides-Extra: dev
Requires-Dist: black>=23.0; extra == 'dev'
Requires-Dist: cryptography<51,>=44; extra == 'dev'
Requires-Dist: fastapi<1,>=0.115; extra == 'dev'
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Requires-Dist: tomli>=2.0; (python_version < '3.11') and extra == 'dev'
Provides-Extra: frameworks
Requires-Dist: acgp-langchain<2,>=1.0.0-alpha.2; (python_version >= '3.10') and extra == 'frameworks'
Requires-Dist: acgp-langgraph<2,>=1.0.0-alpha.2; (python_version >= '3.10') and extra == 'frameworks'
Provides-Extra: langchain
Requires-Dist: acgp-langchain<2,>=1.0.0-alpha.2; (python_version >= '3.10') and extra == 'langchain'
Provides-Extra: langgraph
Requires-Dist: acgp-langgraph<2,>=1.0.0-alpha.2; (python_version >= '3.10') and extra == 'langgraph'
Provides-Extra: mcp
Requires-Dist: mcp==2.3.0; (python_version >= '3.10') and extra == 'mcp'
Provides-Extra: postgres
Requires-Dist: psycopg[binary]<4,>=3.2; extra == 'postgres'
Provides-Extra: release
Requires-Dist: build>=1.2; extra == 'release'
Requires-Dist: readme-renderer[md]>=44.0; extra == 'release'
Requires-Dist: twine>=6.0; extra == 'release'
Description-Content-Type: text/markdown

# ACGP Python SDK

The Python SDK is the canonical runtime implementation for ACGP `v1.0-alpha`.

Python SDK package version: `1.0.0a7`
Protocol claim surface: `1.0.0-alpha.2` Standard Alpha

This is a Python SDK patch release over the current Standard Alpha protocol surface.
It does not promote new feature vectors into the frozen standard-alpha claim suite.

## Bounded condition paths and observable state

Tripwire expressions support dot identifiers, non-negative array indexes,
`[*]` wildcards, and JSON double-quoted object keys. State predicates keep
missing, explicit `null`, redacted, and truncated values distinct:

```yaml
condition:
  all_of:
    - expr: is_present(args.items[0].amount)
    - expr: any_match(args.items[*].amount, "gte", 100)
    - expr: is_missing(args.optional_note)
```

Use `is_present`, `is_missing`, `is_null`, `is_redacted`, or `is_truncated`
for existential matching and the corresponding `all_*` form for universal
matching. Use `any_match` or `all_match` for wildcard comparisons. Empty
wildcard selections return `false` for both quantifiers. Direct wildcard
comparisons are rejected, and unavailable/mixed comparison inputs fail closed.
See [ACGP-4](../../docs/specs/4-tripwires-safety-semantics.md) for the complete
grammar, markers, truth table, and evaluation limits.

Use it for:

- local Standard Profile evaluation
- server-managed runtime event clients for production adapters
- conformance testing
- Python-native agent integrations
- evaluator-service runtime internals

## Recommended alpha implementation path

For `v1.0-alpha`, the canonical runtime implementation is the Python SDK.

Use the Python SDK when you want local Standard Profile evaluation.
Use the Steward/evaluator service when integrating from JavaScript, TypeScript, JVM, Go, or other runtimes.

TypeScript SDK support is under development and will be included in a future release.

## Which path should I use?

| Situation | Recommended path |
|---|---|
| I want to try ACGP quickly | Local Python SDK |
| I am building a Python agent | Local Python SDK |
| I am integrating a production LangChain/LangGraph agent | Adapter `StewardMonitor` wrapper |
| I am building a custom production framework adapter | Runtime events client |
| I want to run conformance vectors | Local Python SDK |
| I am building a JavaScript or TypeScript app | Evaluator service |
| I am building a JVM, Go, Rust, or other non-Python service | Evaluator service |
| I need centralized governance and audit persistence | Evaluator service |
| I need production-like deployment | Evaluator service |
| I want TypeScript local runtime support | Coming soon |

## Start here

From the repository root:

```bash
python -m venv .venv
source .venv/bin/activate
pip install -e sdk/python-sdk
python sdk/python-sdk/examples/basic_usage.py
```

From `sdk/python-sdk/` directly:

```bash
python -m venv .venv
source .venv/bin/activate
pip install -e .
python examples/basic_usage.py
```

## Minimal local evaluation

```python
from acgp import CognitiveTrace, GovernanceSteward
from acgp.state_storage import SQLiteStateStorage

steward = GovernanceSteward(
    blueprint_file="examples/blueprint-standard.yaml",
    conformance_level="standard",
    state_storage=SQLiteStateStorage("acgp-runtime.sqlite"),
    enable_warnings=False,
)

decision = steward.evaluate(
    CognitiveTrace(
        trace_id="trace-001",
        agent_id="urn:acgp:agent:demo:local:001",
        session_id="session-001",
        hook="tool_call",
        context={},
        governance_tier="GT-2",
        reasoning="User wants to buy a $50 item",
        action={"name": "purchase", "parameters": {"amount": 50, "item_id": "ABC123"}},
    )
)

if decision.intervention.value == "block":
    raise RuntimeError(decision.message)

print(decision.intervention.value)
```

## Server-managed runtime events

Production framework adapters should use server-managed runtime events instead of app-owned local monitor/enforce state:

```python
from acgp_langchain import StewardMonitor

agent = StewardMonitor.wrap(
    agent,
    steward_url="https://steward.example.com",
    api_key=STEWARD_API_KEY,
    agent_id="urn:acgp:agent:refund-agent:prod",
    governance_tier="GT-2",
)
```

Custom frameworks can use `RuntimeEventsClient`, `RuntimeEventPayloadV1`, and the runtime ID helpers directly. See [RUNTIME_EVENTS.md](RUNTIME_EVENTS.md).

`GovernanceSteward` remains supported for local/evaluator use. Framework wrappers such as `GovernedChain` and `GovernedGraph` are retired from the production path in favor of `StewardMonitor`, but they remain available for local governance, tests, and migrations.

## Standard Alpha conformance

From the repository root:

```bash
python conformance/run_conformance.py --suite standard-alpha
```

## Relationship to the evaluator service

The evaluator service wraps the Python SDK behind an HTTP boundary.

Use the evaluator service when integrating from non-Python runtimes or when governance should be backend-owned.

## Runtime posture

- `memory`: tests only
- `sqlite`: local and single-node development only
- `postgres`: production runtime-state path

Standard and active decisions require a committed audit record before return.
Provide a file-backed SQLite or PostgreSQL state store; an asynchronous logger
alone is insufficient. Audit failures raise `AuditPersistenceError` and must
stop the action. See [Decision audit durability](../../docs/develop/guides/decision-audit-durability.md)
for storage upgrades, crash guarantees, and recoverable review completion.
Identical HITL/appeal retries return the original result and stable `permit_id`;
effect receivers must deduplicate that ID. All review completion requires
durable storage, including passive development reviews.

## Links

- Standard Profile: [../../docs/specs/standard-profile.md](../../docs/specs/standard-profile.md)
- Runtime Events: [RUNTIME_EVENTS.md](RUNTIME_EVENTS.md)
- Standard quickstart: [../../docs/learn/getting-started/quickstart-standard.md](../../docs/learn/getting-started/quickstart-standard.md)
- Integration walkthrough: [../../docs/develop/guides/integration-walkthrough.md](../../docs/develop/guides/integration-walkthrough.md)
- Reference deployment: [../../deploy/reference/README.md](../../deploy/reference/README.md)

## License

MIT

Shadow rule and tripwire conditions use disposable state overlays. Direct
`StateStorage` callbacks and `functools.partial` wrappers are rebound to those
snapshots, including callbacks supplied through trace context. Opaque custom
callbacks cannot be isolated and produce a non-enforcing evaluation error instead
of executing side effects. Observe checks report when evaluation is skipped.
Local enforced decisions and review flags also participate in remote tripwire
results, with the strictest intervention retained.

Drained runtime queue events reserve capacity until delivery is settled. The
transport settles automatically; manual `drain_batch()` consumers must call
`settle_drained()` after acknowledgment or `requeue_front()` for retry. Sender
exceptions retain the failed event and unattempted suffix in FIFO order. Retries
can deliver an event again when acknowledgment is uncertain. Byte truncation
includes extensions and marks removed payloads and the event as truncated.

Runtime transport defaults to `fail_open=False`: timeout or unavailability stops
a declared blockable before-hook. After/error observations remain non-blocking.
Explicit `fail_open=True` permits continuation with a `failed_open` receipt and
no server authorization; strict declared coverage rejects this opt-in.

Release maintainers can build and install exact source-verified distributions
with the [Python release verification guide](../../docs/develop/guides/python-release-verification.md).
The provenance manifest identifies source and packaging inputs plus wheel/sdist
hashes, including dirty source snapshots.

## Tier-0 admission and remote verification

TRACE `governance_tier` must be exactly `GT-0`, `GT-1`, `GT-2`, `GT-3`,
`GT-4`, or `GT-5`. Missing values, aliases, whitespace, lowercase spellings,
and other types are rejected. The steward rechecks tiers at evaluation admission,
including models created with `model_construct`, copied without validation, or
mutated after construction. An optional `tier0_remote_verify_min_governance_tier`
uses the same canonical values and is validated at startup even when Tier-0 is
disabled; `None` means no minimum.

For a Tier-0-only bundle, `tier0_remote_sample_rate` selects full policy evaluation
using fresh cryptographically secure randomness per evaluation, independent of
caller trace IDs, actions, and tiers. Rates `0` and `1` mean never and always
sample. Intermediate rates are probabilistic: they do not guarantee that a given
action or repeated submissions receive full verification. To require verification
for every action, force-disable the fast path, use rate `1`, or configure an
applicable mandatory minimum tier. Sampling is assurance telemetry and selective
verification, not retry-proof admission control.

## Bounded MCP integration

Install the opt-in extra from this repository checkout on Python 3.10+:

```bash
pip install './sdk/python-sdk[mcp]'
```

```python
from acgp.integrations.mcp import MCPGovernanceAdapter
```

This adapter supports `mcp==2.3.0`, MCP protocol `2025-11-25` and Streamable
HTTP with a trusted host route and a credential-bearing server that enforces
exact-action broker admission. See the [MCP guide](../../docs/develop/integrations/mcp-integration.md)
for the executable local example, receipt recovery and explicit coverage limits.
It is an opt-in extension outside frozen Standard Alpha conformance.
