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.9.tar.gz (74.2 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.9-py3-none-any.whl (95.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scrivai-0.1.9.tar.gz
  • Upload date:
  • Size: 74.2 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.9.tar.gz
Algorithm Hash digest
SHA256 53de6fe17e06dbe7f94c0cdb665a15fe532760f3c92b38132cc917ec437d80af
MD5 67a5fa589a51d495277e58cc34808f88
BLAKE2b-256 78515e5946c86244013c8550960d7d714191306f683a20f1c4d6c9283ce06fd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrivai-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 95.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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b53294a9ffcbff6692cb7cb11daa088fccd079759f464dbb6c0dc4d344317303
MD5 3393607e77b5351c51a49ee547f85de8
BLAKE2b-256 d4e1efa8323112ef614099cd4d03f4956c3c9dc7188677261687ccf34a694d40

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