# Opus Orchestrator AI > Full-flow AI book generation system using **LangGraph**, **CrewAI**, **AutoGen**, and **PydanticAI** A comprehensive, production-ready system for generating publication-ready manuscripts. --- ## โšก Quick Install ### One-Line Installer (Recommended) ```bash # Install and start web UI curl -sSL https://raw.githubusercontent.com/mrhavens/opus-orchestrator-ai/main/install.sh | bash -s -- --api-key YOUR_OPENAI_KEY --start ``` With options: ```bash curl -sSL https://raw.githubusercontent.com/mrhavens/opus-orchestrator-ai/main/install.sh | bash -s -- \ --api-key YOUR_KEY \ --github-token YOUR_GH_TOKEN \ --port 8080 \ --start ``` ### Or Pip Install ```bash pip install opus-orchestrator-ai pip install opus-orchestrator-ai[all] # With server + storage ``` ### Or Clone ```bash git clone https://github.com/mrhavens/opus-orchestrator-ai.git cd opus-orchestrator-ai pip install -e . pip install fastapi uvicorn ``` --- ## โšก Quick Start (After Install) ```bash # Generate a manuscript (local mode) opus generate --concept "A robot dreams of electric sheep" --words 5000 # Or use API server mode opus serve --port 8000 opus --api-url http://localhost:8000 generate --concept "Your idea" ``` --- ## ๐Ÿ—๏ธ Architecture ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ OPUS ORCHESTRATOR AI โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ INGEST โ”‚โ”€โ”€โ”€โ–บโ”‚ LANGGRAPH โ”‚โ”€โ”€โ”€โ–บโ”‚ OUTPUT โ”‚ โ”‚ โ”‚ โ”‚ LAYER โ”‚ โ”‚ WORKFLOW โ”‚ โ”‚ (Manuscript) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ–ผ โ–ผ โ–ผ โ–ผ โ”‚ โ”‚ GitHub S3/MinIO CrewAI AutoGen โ”‚ โ”‚ Ingestor Ingestor Agents Critique โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ VALIDATION LAYER โ”‚ โ”‚ โ”‚ โ”‚ PydanticAI โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` --- ## ๐Ÿ“ฆ Features ### Core Generation | Feature | Description | Status | |---------|-------------|--------| | **Snowflake Method** | 7-stage fractal expansion from sentence to novel | โœ… | | **Story Frameworks** | 7 frameworks: Snowflake, 3-Act, Save the Cat, Hero's Journey, Story Circle, 7-Point, Fichtean | โœ… | | **LangGraph Workflow** | State machine with streaming progress | โœ… | | **AutoGen Critique** | Multi-agent debate (LiteraryCritic, GenreExpert, StoryEditor) | โœ… | | **PydanticAI Validation** | Structured output validation with type-safe schemas | โœ… | ### Agent Systems | Agent | Role | Status | |-------|------|--------| | **ArchitectAgent** | Story structure & blueprint | โœ… | | **WorldsmithAgent** | World-building & setting | โœ… | | **CharacterLeadAgent** | Character development | โœ… | | **VoiceAgent** | Narrative voice & tone | โœ… | | **EditorAgent** | Editorial review | โœ… | | **ResearcherAgent** (Nonfiction) | Fact-finding | โœ… | | **AnalystAgent** (Nonfiction) | Argument analysis | โœ… | ### Ingestion Sources | Source | Description | Status | |--------|-------------|--------| | **GitHub** | Fetch from public/private repos | โœ… | | **S3/MinIO** | S3-compatible object storage | โœ… | | **Local Files** | Direct file/directory input | โœ… | ### Ingestion CLI Commands ```bash # Ingest from GitHub opus ingest --repo owner/repo # Ingest from S3/MinIO opus ingest-s3 --bucket my-bucket --prefix notes/ # Ingest from local files/directory opus ingest-local ./my-notes/ opus ingest-local ./manuscript.txt opus ingest-local ./folder --extensions md,txt --recursive opus ingest-local ./notes --summarize --max-length 5000 ``` ### Deployment | Mode | Description | Status | |------|-------------|--------| | **CLI** | Standalone command-line tool | โœ… | | **Web UI** | Browser-based interface | โœ… | | **API Server** | FastAPI REST server | โœ… | | **API Client** | Client mode for remote servers | โœ… | | **Python Module** | Import as library | โœ… | ### Web Interface ```bash # Start web UI only (no API) opus ui --port 8080 # Start full API server (includes web UI) opus serve --port 8000 ``` Then open http://localhost:8080 in your browser! Features: - ๐Ÿ’ก Enter story concept - ๐Ÿ™ Pull from GitHub - ๐Ÿชฃ Load from S3 - ๐Ÿ“ Upload files - โ˜๏ธ Save to S3/GitHub - ๐Ÿ“ฅ Download manuscript ### Output Options | Destination | CLI Flag | Description | |------------|----------|-------------| | **Local File** | `--output FILE` | Save to local filesystem | | **S3/MinIO** | `--save-s3 BUCKET/PATH` | Upload to S3-compatible storage | | **GitHub** | `--save-repo OWNER/REPO` | Commit to GitHub repository | --- ## ๐Ÿš€ Usage ### CLI Commands ```bash # Generate manuscript from concept (local) opus generate --concept "Your story idea" --framework snowflake --words 5000 # Generate from GitHub opus generate --repo owner/repo --framework hero-journey --words 80000 # Generate from local files/directory opus generate --local ./my-notes/ --framework snowflake --words 5000 opus generate --local ./manuscript.txt --words 5000 # Generate and save to S3/MinIO opus generate --concept "..." --save-s3 my-bucket/manuscripts/ opus generate --concept "..." --save-s3 my-bucket/path/ --save-s3-endpoint https://nyc3.digitaloceanspaces.com # Generate and save to GitHub repo opus generate --concept "..." --save-repo owner/my-manuscripts opus generate --concept "..." --save-repo owner/my-manuscripts --save-branch develop --save-commit-msg "New story draft" # Generate from one source, save to another opus generate --repo owner/notes --save-s3 output-bucket/manuscripts/ opus generate --local ./notes --save-repo owner/output-repo # Ingest from various sources opus ingest --repo owner/repo opus ingest-s3 --bucket my-bucket --prefix notes/ opus ingest-local ./my-notes/ opus ingest-local ./folder --extensions md,txt,notes --recursive opus ingest-local ./notes --summarize --max-length 5000 # Start API server opus serve --port 8000 # Use as API client opus --api-url http://localhost:8000 generate --concept "..." # List frameworks opus frameworks # Show config opus config # Show docs opus docs ``` ### Python API ```python from opus_orchestrator import run_opus # Simple generation result = await run_opus( seed_concept="A robot dreams of love", framework="snowflake", genre="science-fiction", target_word_count=5000, ) manuscript = result["manuscript"] ``` ### Using CrewAI ```python from opus_orchestrator.crews import create_fiction_crew crew = create_fiction_crew( genre="science-fiction", tone="literary", target_word_count=2000, ) story = crew.write_full_story( story_outline="Your outline...", character_sheets="...", style_guide="Tone: literary", num_chapters=5, ) ``` ### Using PydanticAI Validation ```python from opus_orchestrator import create_style_guide_agent agent = create_style_guide_agent() result = agent.run_sync("Create a style guide for a literary novel") # Result is a validated StyleGuide object print(result.tone) # "Contemplative and introspective" print(result.pacing) # "Deliberate with moments of acceleration" ``` ### API Server ```python from opus_orchestrator.server import app, run_server # Run server await run_server(host="0.0.0.0", port=8000) # Or with uvicorn directly # uvicorn opus_orchestrator.server:app --port 8000 ``` ### API Client ```python from opus_orchestrator.cli import OpusAPIClient client = OpusAPIClient("http://localhost:8000") # Health check health = client.health() # Generate result = client.generate( concept="A robot dreams", framework="snowflake", target_word_count=5000, ) print(result["manuscript"]) ``` --- ## โš™๏ธ Configuration ### Environment Variables | Variable | Description | Required | |----------|-------------|----------| | `OPENAI_API_KEY` | OpenAI API key | Yes (or MINIMAX_API_KEY) | | `MINIMAX_API_KEY` | MiniMax API key | No | | `GITHUB_TOKEN` | GitHub token for private repos | No | | `AWS_ACCESS_KEY_ID` | AWS access key for S3 | No | | `AWS_SECRET_ACCESS_KEY` | AWS secret key for S3 | No | | `S3_ENDPOINT_URL` | Custom S3 endpoint (MinIO, DO Spaces) | No | ### API Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/` | GET | Web UI | | `/ui` | GET | Web UI | | `/docs` | GET | Interactive API docs | | `/health` | GET | Health check | | `/frameworks` | GET | List frameworks | | `/generate` | POST | Generate manuscript | | `/ingest` | POST | Ingest from GitHub | | `/upload` | POST | Upload file | | `/upload/s3` | POST | Upload to S3 | ### Configuration File ```yaml # config.yaml agent: provider: openai model: gpt-4o temperature: 0.7 max_tokens: null iteration: min_critic_rounds: 2 max_critic_rounds: 5 approval_threshold: 0.8 output: format: markdown include_toc: true output_dir: ./output ``` --- ## ๐Ÿ“š Story Frameworks ### Implemented Frameworks | Framework | Type | Stages/Beats | |-----------|------|---------------| | **Snowflake Method** | Fractal | 7 stages | | **Three-Act Structure** | Linear | 7 beats | | **Save the Cat** | Screenplay | 15 beats | | **Hero's Journey** | Mythic | 12 stages | | **Story Circle** | Circular | 8 beats | | **7-Point Plot** | Structural | 7 beats | | **Fichtean Curve** | Episodic | 7 beats | --- ## ๐Ÿงฉ Project Structure ``` opus_orchestrator/ โ”œโ”€โ”€ __init__.py # Main exports โ”œโ”€โ”€ __main__.py # CLI entry point โ”œโ”€โ”€ cli.py # CLI implementation โ”œโ”€โ”€ server.py # FastAPI server โ”œโ”€โ”€ orchestrator.py # Main orchestrator โ”œโ”€โ”€ langgraph_workflow.py # LangGraph pipeline โ”œโ”€โ”€ autogen_critique.py # AutoGen critique crew โ”œโ”€โ”€ pydanticai_agent.py # PydanticAI agents โ”œโ”€โ”€ config.py # Configuration โ”œโ”€โ”€ frameworks.py # Story frameworks โ”‚ โ”œโ”€โ”€ agents/ # Agent implementations โ”‚ โ”œโ”€โ”€ fiction/ # Fiction agents โ”‚ โ”‚ โ”œโ”€โ”€ architect.py โ”‚ โ”‚ โ”œโ”€โ”€ worldsmith.py โ”‚ โ”‚ โ”œโ”€โ”€ character_lead.py โ”‚ โ”‚ โ”œโ”€โ”€ voice.py โ”‚ โ”‚ โ””โ”€โ”€ editor.py โ”‚ โ””โ”€โ”€ nonfiction/ # Nonfiction agents โ”‚ โ”œโ”€โ”€ researcher.py โ”‚ โ”œโ”€โ”€ analyst.py โ”‚ โ”œโ”€โ”€ writer.py โ”‚ โ”œโ”€โ”€ fact_checker.py โ”‚ โ””โ”€โ”€ editor.py โ”‚ โ”œโ”€โ”€ crews/ # CrewAI crews โ”‚ โ”œโ”€โ”€ base_crew.py # Base crew class โ”‚ โ”œโ”€โ”€ fiction_crew.py # Fiction crew โ”‚ โ””โ”€โ”€ nonfiction_crew.py โ”‚ โ”œโ”€โ”€ schemas/ # Pydantic schemas โ”‚ โ””โ”€โ”€ book.py โ”‚ โ””โ”€โ”€ utils/ # Utilities โ”œโ”€โ”€ github_ingest.py # GitHub ingestion โ”œโ”€โ”€ s3_ingest.py # S3/MinIO ingestion โ”œโ”€โ”€ llm.py # LLM client โ””โ”€โ”€ docs.py # Documentation generator ``` --- ## ๐Ÿงช Testing ```bash # Run tests pytest tests/ # Run with coverage pytest --cov=opus_orchestrator tests/ # Lint ruff check . # Format ruff format . ``` --- ## ๐Ÿ“„ License MIT License --- ## ๐Ÿค Built With - **LangGraph** - Workflow orchestration - **CrewAI** - Multi-agent systems - **AutoGen** - Complex agent conversations - **PydanticAI** - Structured output validation - **FastAPI** - REST API server - **OpenAI** - LLM provider --- *Built with the WE Architecture โ€” witness and co-creation in code.*