Skip to main content

Configurable document generation & audit framework built on Claude Agent SDK

Project description

Scrivai

中文

PyPI version Python 3.11+ License

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrivai-0.2.0.tar.gz (76.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrivai-0.2.0-py3-none-any.whl (97.4 kB view details)

Uploaded Python 3

File details

Details for the file scrivai-0.2.0.tar.gz.

File metadata

  • Download URL: scrivai-0.2.0.tar.gz
  • Upload date:
  • Size: 76.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for scrivai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0b333294b45c819c6a17dceb098a3f9251f4f830c26d8aec612e618e254660f6
MD5 2d6b4b67b7aab984c1b2045c4559ef86
BLAKE2b-256 3919fd2de1b51b31924c118ab1607e58a1a17a7c1b3c416626911ef611307900

See more details on using hashes here.

File details

Details for the file scrivai-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: scrivai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 97.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for scrivai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 610253db3473b0a5c5c25ea8c581a6256953bc6ea405ca84a46ce19fc85896dc
MD5 92f890fc4ef558e4f63d632d495b26a6
BLAKE2b-256 a77306f55c10c2aabb0f0b67f0935951bc188d426ccc7c030e3b088e93c93887

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page