Skip to content

feat(sdk): add 2-line openadapt.wrap Python SDK - #2732

Merged
abrichr merged 3 commits into
mainfrom
feat/openadapt-wrap-sdk
Nov 28, 2026
Merged

abrichr merged 3 commits into
mainfrom
feat/openadapt-wrap-sdk

Conversation

@abrichr

@abrichr abrichr commented Nov 28, 2026

Copy link
Copy Markdown
Member

Summary

Adds openadapt/wrap_sdk.py, lazy-exported from openadapt (openadapt.wrap, WrapResult, WrapBlockedError, WrapVerificationError, WrapReceipt, WrapLedger, verify_wrap_receipt), so developers can add commit-boundary protections to any Python function, coroutine, Playwright helper, MCP tool, or agent object in 2 lines with zero YAML files required:

  • Call and decorator forms: Supports openadapt.wrap(fn, ...), @openadapt.wrap, and @openadapt.wrap(...) across sync functions, async def coroutines, callable instances, and agent objects exposing .run or .step (via WrappedAgentProxy without mutating the underlying object). Preserves __name__, __doc__, and __signature__ via functools.wraps for tool schema inspection.
  • Pinned identity and key checks: Refuses conflicting operator-pinned arguments (pinned={...}) and blank identity_keys before executing the wrapped callable (WrapBlockedError or structured refusal dict when on_block="return").
  • Uncertain-write and duplicate-submit ledger: Latches mid-flight exceptions and uncertain or refuted post-action checks in WrapLedger (in-memory or file-backed JSON) to block blind duplicate retries until wrapped.release(key) is called, and replays confirmed request_id / idempotent=True calls without double execution.
  • Post-action verification and receipts: Supports same_screen post-action callables (check=... or expect=...) with zero reload or API requirement, or routes through openadapt.verify.Contract (begin_write / verify_write) when contract= is passed. Attaches wrapped.last_receipt with outcome, checked_how, sha256 digest, and optional Ed25519 signature (signing_key=).
  • Stdlib-only import budget: openadapt/wrap_sdk.py imports only the Python standard library at module load time; openadapt_flow and cryptography load lazily only when contract= or signing_key= is supplied.
  • README quick example: Adds a concise 2-line Python SDK snippet under Quickstart in README.md (stacked cleanly on #2730).

Verification

Ran via ~/oa/scratch/cpu-slots/run.sh:

  • pytest tests/test_openadapt_wrap.py tests/test_shipped_only_copy.py tests/test_readme_replay_warning.py tests/test_pypi_description.py -q -> 22 passed
  • python3 scripts/check_file_size_ratchet.py --base origin/main -> exit 0
  • python3 packages/flow/scripts/check_verdict_folds.py -> Verdict folds OK (2615 baseline folds left)
  • ruff check openadapt tests/test_openadapt_wrap.py -> All checks passed!
  • ruff format --check openadapt tests/test_openadapt_wrap.py -> 27 files already formatted

Generality & Durability

  1. No per-app code in the engine: Yes. openadapt/wrap_sdk.py contains zero application-specific names, selectors, or branches.
  2. Fix the class, not the instance: Yes. Addresses the general class of unguarded Python tool and agent writes (target swaps on pinned keys, blind retries after uncertain mid-flight failures, and unchecked post-action state) across sync, async, callable, and .run/.step entry points.
  3. Held-out evidence: Exercised across unit tests covering sync/async callables, agent proxies, file-backed request_id replay, Ed25519 receipt verification, and SQLite Contract read-back; not yet measured on an external held-out live portal campaign.
  • Durable item advanced: Safe writes (pinned identity checks, idempotency, uncertain-write retry holds) and verifiable SHA-256 / Ed25519 receipts independent of which model or framework drives the action.

Add openadapt.wrap_sdk (lazy-exported as openadapt.wrap, WrapResult, WrapBlockedError, WrapVerificationError, WrapReceipt, and WrapLedger) using only the Python standard library at import time:
- Wrap sync functions, async coroutines, callable instances, and agent objects exposing .run or .step while preserving signatures via functools.wraps.
- Enforce operator-pinned keys and required identity_keys before executing wrapped callables.
- Track in-memory or file-backed uncertain writes and idempotent request_id replays with explicit .release(key) recovery.
- Verify post-action outcomes via same_screen callables by default or openadapt.verify.Contract when supplied, attaching SHA-256 and optional Ed25519 receipts.
@abrichr
abrichr enabled auto-merge November 28, 2026 00:33
@abrichr
abrichr added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 1a707d2 Nov 28, 2026
44 checks passed
@abrichr
abrichr deleted the feat/openadapt-wrap-sdk branch November 28, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant