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.1.7.tar.gz (71.1 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.1.7-py3-none-any.whl (92.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for scrivai-0.1.7.tar.gz
Algorithm Hash digest
SHA256 08b4e3f315cc9649644c33b737d22191530c43286f54ece20980c0074780e932
MD5 e470369a381f69472b42c4b4e4227ebf
BLAKE2b-256 e99f7a8d22c101f386f25d12f3fd0c06fd76928ceb458d06febf1ccab74fec6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrivai-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 92.1 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.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5eab30195e1bcc406ac8c94fcc7de89814b779cf225fa26b7abd09c1ced9b5c8
MD5 1a681b7cd716aadfcc90eb181055ecbd
BLAKE2b-256 20a55d2f37bb5b3d84494036080b85f8f11411324e0103afd90c4e589a536aa0

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