2026-05-04 18:55:18 +00:00
# scriptorium
2026-05-05 10:09:31 -05:00
Scriptorium is a generic prompt-definition execution engine written in Go.
2026-05-04 20:36:12 -05:00
2026-05-05 10:09:31 -05:00
Given named input artifacts and a prompt definition, Scriptorium:
2026-05-04 21:08:40 -05:00
2026-05-05 10:09:31 -05:00
1. Loads the prompt definition.
2026-05-05 08:45:10 -05:00
2. Resolves input artifact references.
3. Renders prompt messages from templates.
4. Calls an OpenAI-compatible LLM endpoint.
5. Validates output if configured.
6. Optionally performs bounded structured-output repair.
7. Returns a generated artifact plus run metadata.
2026-05-04 21:08:40 -05:00
2026-05-05 08:45:10 -05:00
## Where Scriptorium Fits
2026-05-04 21:23:48 -05:00
2026-05-05 08:45:10 -05:00
Scriptorium is not an orchestrator.
2026-05-04 21:23:48 -05:00
2026-05-05 08:45:10 -05:00
In the D&D workflow:
- Narratio orchestrates the full pipeline.
- WhisperX transcribes audio.
- Seriatim merges transcripts.
- Audita polishes transcripts.
- Scriptorium generates final artifacts from prepared inputs.
D&D-specific behavior belongs in profiles, schemas, fixtures, and caller inputs, not in core Go logic.
## Core Concepts
2026-05-05 10:09:31 -05:00
- Prompt definition: YAML config for templates, inputs, output format, and validation behavior.
- Execution profile: conceptual runtime config (endpoint/model/timeouts/auth source). In this transition, execution settings are supplied as run-time overrides.
- Named inputs: logical names (for example `transcript` , `glossary` ) mapped to artifact references.
- Artifact refs: currently `file` and `inline` are supported.
- Template variables: key/value vars passed at run time and referenced as `{{.var_name}}` .
- Execution target: endpoint/model plus generation/runtime parameters (`temperature` , `max_tokens` , `top_p` , `timeout_seconds` , `reasoning_effort` , `api_key_env` ).
2026-05-05 08:45:10 -05:00
- Output format: `text` , `markdown` , or `json` .
- Validation mode: `none` , `basic` , `json` , `json_schema` .
- Repair attempts: bounded retries for structured modes (`json` , `json_schema` ) when output validation fails.
## Build and Test
```bash
go build -o scriptorium ./cmd/scriptorium
go test ./...
```
## CLI Usage
### `scriptorium run`
Required flags:
2026-05-05 10:58:22 -05:00
- `--prompt-dir`
2026-05-05 08:45:10 -05:00
- `--profile-dir`
2026-05-05 10:58:22 -05:00
- `--prompt`
2026-05-05 08:45:10 -05:00
- `--input` (repeatable `name=path` )
2026-05-04 21:23:48 -05:00
2026-05-05 10:09:31 -05:00
Common optional flags:
2026-05-04 21:23:48 -05:00
2026-05-05 10:58:22 -05:00
- `--profile` (execution profile selector; falls back to prompt `default_profile` )
2026-05-05 08:45:10 -05:00
- `--var` (repeatable `name=value` )
- `--out`
- `--llm-base-url`
- `--model`
2026-05-05 10:09:31 -05:00
- `--api-key-env`
2026-05-05 08:45:10 -05:00
- `--temperature`
- `--max-tokens`
- `--schema-dir`
- `--timeout`
2026-05-05 10:09:31 -05:00
Current transitional behavior: execution-profile loading is not implemented yet, so run-time execution settings must be supplied via overrides. In practice, provide at least endpoint and model (`--llm-base-url` and `--model` ).
2026-05-05 08:45:10 -05:00
2026-05-05 10:09:31 -05:00
Example:
2026-05-04 21:08:40 -05:00
```bash
2026-05-05 10:09:31 -05:00
export SCRIPTORIUM_API_KEY="your-key"
2026-05-04 21:23:48 -05:00
go run ./cmd/scriptorium run \
2026-05-05 10:58:22 -05:00
--prompt-dir ./prompts \
2026-05-04 21:23:48 -05:00
--profile-dir ./profiles \
2026-05-05 10:58:22 -05:00
--prompt generic.markdown_summary \
--profile local-fast \
2026-05-04 21:23:48 -05:00
--input transcript=./examples/fixtures/transcript.md \
--input glossary=./examples/fixtures/glossary.yml \
--llm-base-url http://localhost:8000/v1 \
--model gpt-4o-mini \
2026-05-05 10:09:31 -05:00
--api-key-env SCRIPTORIUM_API_KEY \
2026-05-05 08:45:10 -05:00
--out ./out.md
2026-05-04 21:23:48 -05:00
```
2026-05-05 08:45:10 -05:00
Output behavior:
2026-05-04 21:23:48 -05:00
2026-05-05 08:45:10 -05:00
- Artifact content goes to stdout unless `--out` is set.
- Summaries and errors are written to stderr.
2026-05-05 10:09:31 -05:00
- Exit code `2` means the run succeeded but validation status is `failed` .
2026-05-05 08:45:10 -05:00
### `scriptorium serve`
Starts HTTP API.
Required flags:
2026-05-05 10:58:22 -05:00
- `--prompt-dir`
2026-05-05 08:45:10 -05:00
- `--profile-dir`
Common optional flags:
- `--addr` (default `:8080` )
- `--schema-dir` (default `.` )
- `--model`
- `--timeout` (default `10m` )
## HTTP API
2026-05-05 10:09:31 -05:00
Endpoint:
2026-05-05 08:45:10 -05:00
- `POST /v1/runs`
2026-05-05 10:09:31 -05:00
No built-in authentication is provided by the server itself. Deploy behind a trusted boundary or gateway.
2026-05-05 08:45:10 -05:00
Request example:
```json
{
2026-05-05 10:09:31 -05:00
"prompt_id": "generic.structured_events",
"prompt_version": "1.0.0",
"profile_id": "local-default",
2026-05-05 08:45:10 -05:00
"inputs": {
"transcript": {"type": "file", "uri": "./examples/fixtures/transcript.md"},
"glossary": {"type": "file", "uri": "./examples/fixtures/glossary.yml"}
},
"vars": {
"session_date": "2026-05-04"
},
"model": {
"endpoint": "http://localhost:8000/v1",
"model": "gpt-4o-mini",
"temperature": 0.0,
"max_tokens": 600,
"top_p": 1.0,
2026-05-05 10:09:31 -05:00
"timeout_seconds": 120,
"api_key_env": "SCRIPTORIUM_API_KEY"
2026-05-05 08:45:10 -05:00
}
}
```
Response shape:
```json
{
"artifact": {
"name": "output",
"content_type": "application/json",
"body": "{...}",
"uri": "",
"size": 123,
"hash": "..."
},
"validation": {
"status": "passed",
"mode": "json_schema",
"errors": [],
"schema_path": "structured_events.schema.json",
"repair_attempts": 0,
"is_valid": true
},
"metadata": {
"run_id": "xxxxxxxx-xxxx-4xxx-8xxx-xxxxxxxxxxxx",
2026-05-05 10:09:31 -05:00
"prompt_id": "generic.structured_events",
"prompt_version": "1.0.0",
"prompt_hash": "...",
"rendered_prompt_hash": "...",
"selected_profile_id": "local-default",
2026-05-05 08:45:10 -05:00
"model_name": "gpt-4o-mini",
"endpoint": "http://localhost:8000/v1",
"model_params": {
"endpoint": "http://localhost:8000/v1",
"model": "gpt-4o-mini",
"temperature": 0,
"max_tokens": 600,
"top_p": 1,
2026-05-05 10:09:31 -05:00
"timeout_seconds": 120,
"api_key_env": "SCRIPTORIUM_API_KEY"
2026-05-04 21:23:48 -05:00
},
2026-05-05 08:45:10 -05:00
"input_hashes": {"transcript": "...", "glossary": "..."},
"usage": {"prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30},
"start_time": "...",
"end_time": "...",
"duration_ms": 1523,
"validation_mode": "json_schema",
"validation_status": "passed",
"repair_attempts_used": 0
},
"raw_model_output": "{...}"
}
2026-05-04 21:23:48 -05:00
```
2026-05-05 10:09:31 -05:00
Validation content failures return `200` with `validation.status = "failed"` and preserve `raw_model_output` .
2026-05-05 08:45:10 -05:00
Error response shape:
```json
{
"error": {
"code": "artifact_read_failed",
"message": "failed to read input artifact"
}
}
```
2026-05-05 10:09:31 -05:00
## Prompt Definition Authoring
2026-05-05 08:45:10 -05:00
2026-05-05 10:09:31 -05:00
### Minimal Markdown prompt definition
2026-05-05 08:45:10 -05:00
```yaml
id: generic.markdown_summary
version: "1.0.0"
2026-05-05 10:09:31 -05:00
default_profile: local-default
inputs:
- name: transcript
required: true
2026-05-05 08:45:10 -05:00
templates:
- role: system
content: "You are a concise assistant."
- role: user
content: |
Summarize:
{{input "transcript"}}
output_format: markdown
validation:
validation_mode: basic
```
2026-05-05 10:09:31 -05:00
### Structured JSON prompt definition with schema validation
2026-05-05 08:45:10 -05:00
```yaml
id: generic.structured_events
version: "1.0.0"
2026-05-05 10:09:31 -05:00
default_profile: local-default
inputs:
- name: transcript
required: true
2026-05-05 08:45:10 -05:00
templates:
- role: system
content: "Return only JSON."
- role: user
content: |
Extract events from:
{{input "transcript"}}
output_format: json
validation:
format: json
validation_mode: json_schema
schema_path: structured_events.schema.json
repair_attempts: 1
```
2026-05-05 10:09:31 -05:00
`repair_attempts` is strictly bounded and only applies to structured validation modes.
2026-05-05 08:45:10 -05:00
## Validation Modes
- `none` : skipped validation result.
2026-05-05 10:09:31 -05:00
- `basic` : fails for empty/whitespace output.
2026-05-05 08:45:10 -05:00
- `json` : output must parse as JSON.
2026-05-05 10:09:31 -05:00
- `json_schema` : output must parse as JSON and satisfy configured schema.
2026-05-05 08:45:10 -05:00
2026-05-05 10:09:31 -05:00
Validation content failures are returned in the structured result; raw model output is preserved.
2026-05-05 08:45:10 -05:00
2026-05-05 10:09:31 -05:00
## Examples
2026-05-05 08:45:10 -05:00
2026-05-05 10:58:22 -05:00
- Prompt definitions: `prompts/`
- Execution profiles: `profiles/`
2026-05-05 08:45:10 -05:00
- Schemas: `schemas/`
- Fixtures: `examples/fixtures/`
- Local experimentation: `local-test/`
## Development Notes
2026-05-05 10:09:31 -05:00
- Core follows ports-and-adapters and remains domain-generic.
- Domain/usecase packages do not depend on HTTP/CLI wire DTOs.
2026-05-05 08:45:10 -05:00
- To add a new LLM adapter: implement `internal/llm.Client` .
2026-05-05 10:09:31 -05:00
- To add a new artifact reader: extend `internal/artifact.Reader` routing.
- To add a new validation mode: extend `internal/validate` and preserve run semantics.