Scrivai
Configurable document generation & audit framework built on Claude Agent SDK.
Scrivai wraps the Claude Agent SDK in a three-phase execution engine called PES (Plan→Execute→Summarize), where each phase produces file-contract outputs that the framework validates automatically. It ships three built-in agents — ExtractorPES, AuditorPES, and GeneratorPES — and includes a self-improving skill system that proposes, evaluates, and promotes better agent behaviors from trajectory feedback.
Install
pip install scrivai
Quick Start
import asyncio
from pathlib import Path
from pydantic import BaseModel
from scrivai import (
ExtractorPES,
ModelConfig,
WorkspaceSpec,
build_workspace_manager,
load_pes_config,
)
class KeyItems(BaseModel):
items: list[str]
async def main():
ws_mgr = build_workspace_manager()
ws = ws_mgr.create(WorkspaceSpec(run_id="demo", project_root=Path.cwd(), force=True))
config = load_pes_config(Path("scrivai/agents/extractor.yaml"))
pes = ExtractorPES(
config=config,
model=ModelConfig(model="claude-sonnet-4-20250514"),
workspace=ws,
runtime_context={"output_schema": KeyItems},
)
run = await pes.run("Extract all key items from data/source.md")
print(run.final_output)
asyncio.run(main())
Core Concepts
Every agent in Scrivai follows the same three-phase contract:
┌──────┐ ┌─────────┐ ┌───────────┐
│ plan │ ───▶ │ execute │ ───▶ │ summarize │
└──────┘ └─────────┘ └───────────┘
│ │ │
▼ ▼ ▼
plan.json findings/*.json output.json
Each phase declares required_outputs in a YAML config. The framework checks those file contracts at phase exit and automatically retries up to max_retries times on failure. This makes every PES unit testable and auditable without extra instrumentation.
Key APIs
| Symbol | Description |
|---|---|
BasePES |
Three-phase execution engine base class |
ExtractorPES |
Extract structured data from documents |
AuditorPES |
Audit documents against checkpoints |
GeneratorPES |
Generate documents from templates |
ModelConfig |
LLM provider configuration |
load_pes_config() |
Load PES config from YAML |
build_workspace_manager() |
Create isolated workspaces |
Examples
| Script | Covers | Estimated time |
|---|---|---|
examples/01_audit_single_doc.py |
AuditorPES checkpoint audit |
~2–3 min |
examples/02_generate_with_revision.py |
GeneratorPES template generation |
~1–2 min |
examples/03_evolve_skill_workflow.py |
Skill evolution end-to-end | ~3–5 min |
Documentation
Full API reference and guides: https://iomgaa-ycz.github.io/Scrivai/
Configuration
Required
export ANTHROPIC_API_KEY=sk-ant-...
Gateway override (optional — for private endpoints or alternative models)
export ANTHROPIC_BASE_URL=https://your-gateway.example.com
export SCRIVAI_DEFAULT_MODEL=your-model-name
These environment variables are read automatically at startup. You can also pass base_url, model, and api_key directly to ModelConfig to override them at the code level.
Contributing
See CONTRIBUTING.md for development setup, coding standards, and the pull-request workflow.
License
Apache 2.0 — see LICENSE for details.
Metadata
Release files for scrivai 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scrivai-0.2.3.tar.gz | 83.7 kB | Without provenance | Details for scrivai-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scrivai-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for scrivai-0.2.3-py3-none-any.whl |
Total release size: 189.6 kB
Release files / scrivai-0.2.3.tar.gz
| Download URL | scrivai-0.2.3.tar.gz |
|---|---|
| Size | 83.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bd51b4f048b482736147f6bd965a8604ea6e99124016e0d49619a35eae4748f
|
|
BLAKE2b-256 checksum How to use checksums |
f8473ec9c9c06f1e74c45606826222c83b580fa579142ff0711508443c462ef4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / scrivai-0.2.3-py3-none-any.whl
| Download URL | scrivai-0.2.3-py3-none-any.whl |
|---|---|
| Size | 105.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e26aa4491a32753234b7332f31e6b269d8817e7ffda9256476e1b45bdd302c9d
|
|
BLAKE2b-256 checksum How to use checksums |
b6b62041df7833ecb8f0e2dc2a40794181f46017cc532e6a3c16ad18ea3bc2fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for scrivai 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.