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.8.tar.gz (72.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.8-py3-none-any.whl (93.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scrivai-0.1.8.tar.gz
  • Upload date:
  • Size: 72.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.8.tar.gz
Algorithm Hash digest
SHA256 18081cc546ab0581dd3e504b8804f865f785e09d7db9cc371d1e092c40fa3ddd
MD5 2a3685e1a467fcb6f7078652b89f56d9
BLAKE2b-256 d83c40cf2135c2a6781217a71b0000a7b4bbd9113b8bb59dbf7fbce45fecdf0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrivai-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 93.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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 87b5c146ffc08308410d05cf4b23dd9c9ca9bd6e5711d70fc1fc9edab0bd95e8
MD5 513ac44208338194ea3ee6f5d7859294
BLAKE2b-256 de5744775b6b4116e9a32cf74ffae44cbaf60283b93d5226f609fbdedcc8fcd6

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