# evalshift-sdk

> In-process Python capture SDK for AI agents. Wrap an agent's entry point, tool calls, and model calls; each run is recorded as a structured trace and written as a JSON capture file to `.evalshift/captures/<suite>/cap_<id>.json` on local disk, or to `.evalshift/captures/<suite>/conv_<16 hex>/cap_<id>.json` for a `capture.agent_session` / `agent_session_async` turn with a `conversation_id` (the hex is the start of `sha256(conversation_id)`; `@capture.agent` decorator captures are always flat; `EVALSHIFT_CAPTURE_LAYOUT=flat` writes every capture flat, as before 0.7.0; reading the folders needs evalshift CLI 1.6.0 or later, and an older evalshift CLI installed in the same environment makes the SDK write flat with a warning unless `EVALSHIFT_CAPTURE_LAYOUT=conversation`). Capture is off unless the `EVALSHIFT_CAPTURE` env var is truthy. Zero runtime dependencies (stdlib only), Python >= 3.10, no network code unless `EVALSHIFT_CAPTURE_STORE` names an object store you own. Captures are consumed by the separate [evalshift CLI](https://github.com/evalshift/evalshift-cli); the capture layout is the interface between SDK and CLI, on disk or in a bucket.

Key facts:

- Distribution name is `evalshift-sdk`; import name is `evalshift`. Current version 0.7.0, envelope schema version 2.1.0.
- Top-level public API: `capture` (with `.agent`, `.agent_session`, `.agent_session_async`, `.model_call`, `.tool`), `record_model_call`, `configure`, `Redactor`, `RedactSetting`, `default_redactor`, `FileSink`, `MemorySink`, `ObjectStoreSink`, `flush_captures`, `load_capture`, `load_envelope`, `register_migration`, `MigrationError`, `SCHEMA_VERSION`, `SinkConfigurationError`, `__version__`. LangChain adapter: `evalshift.adapters.langchain.EvalShiftCallbackHandler` (needs the `[langchain]` extra). Provider client wrappers: `evalshift.adapters.openai.wrap_openai`, `evalshift.adapters.anthropic.wrap_anthropic`, `evalshift.adapters.genai.wrap_genai` (extras `[openai]`, `[anthropic]`, `[google-genai]`) — a drop-in proxy over a client instance that records one `model_call` per request inside a capture session. Object stores: `evalshift.stores` (`ObjectStore`, `MemoryStore`, `open_store`, `parse_store_uri`) plus `evalshift.stores.s3.S3Store` / `.gcs.GCSStore` / `.azure.AzureBlobStore` — each needs the provider's client library (`pip install boto3` / `google-cloud-storage` / `azure-storage-blob azure-identity`), no extra needed.
- Redaction is required, not opt-in: `redact=` is a mandatory keyword on `capture.agent`, `capture.agent_session`, `capture.agent_session_async`, and `EvalShiftCallbackHandler` — `True` masks with `default_redactor`, `False` captures verbatim, a callable is your own redactor; anything else (including `None`) raises `TypeError`. There is no `configure(redact=...)`.
- Safety model: the capture path is fail-open (SDK faults can never break or slow the host agent; failed runs are still captured, then the original exception re-raises); redaction is fail-closed (a raising redactor drops the capture rather than writing unredacted data); the read path (`load_capture`/`load_envelope`) raises typed `MigrationError` subclasses.
- Hygiene defaults keep `captures/` bounded: dedup on (per-process, keyed `(suite, input_hash)`), newest-200 files kept per suite dir (of those the TTL leaves), by unit: a capture or a whole conversation folder; the newest conversations are kept whole while they fit, the one at the boundary keeps its newest turns, older ones are evicted whole. Sampling, when set, is decided once per agent invocation; per conversation when an `agent_session` is given a `conversation_id`. Configurable via `configure(...)` or `EVALSHIFT_MAX_CAPTURES` / `EVALSHIFT_DEDUP` / `EVALSHIFT_CAPTURE_TTL` / `EVALSHIFT_SAMPLE_RATE`; capture root via `EVALSHIFT_DIR`.

## Docs

- [DOCS.md](DOCS.md): full guide — installation, quickstart, how it works, instrumenting agents, configuration, sinks, redaction, complete API reference, troubleshooting
- [llms-full.txt](llms-full.txt): complete dense API and behavior reference for LLMs — hosted at https://www.evalshift.dev/sdk-llms-full.txt (stable URL for AGENTS.md / CLAUDE.md files)
- [CHANGELOG.md](CHANGELOG.md): release history

## Reference

- [docs/SCHEMA.md](docs/SCHEMA.md): capture envelope schema versioning, migration policy, the messages-list convention for model_call input, input_hash semantics
- [docs/REDACTION.md](docs/REDACTION.md): the redaction boundary, guarantees, default patterns, what a capture may still contain

## Examples

- [examples/support_agent/agent.py](examples/support_agent/agent.py): runnable deterministic demo agent using @capture.agent, @capture.tool, and record_model_call

## Optional

- [docs/DECISIONS.md](docs/DECISIONS.md): locked design decisions (D-refs) and rationale
- [README.md](README.md): short package overview
