A modern, production-ready template for building Temporal applications using the Temporal Python SDK. The repository now includes a spec_builder workflow package plus a local GUI stack that turns local artifacts into an implementation-ready Temporal specification with structured review checkpoints and persisted outputs.
- Complete testing setup with async support and coverage enforcement
- Pre-configured development tooling with Ruff, Poe, and pre-commit
- Documentation for Temporal patterns and testing
- AGENTS.md guidance for coding agents working in the repo
- A
src/workflows/spec_builder/workflow package with typed models, child workflows, Gemini-backed activities, and tests - A
src/spec_builder_gui/local web app backend and React frontend for job submission, review, and revision flows
- uv
- Temporal CLI
GEMINI_API_KEYorGOOGLE_API_KEYfor real Gemini-backed activity execution
GeminiExecutor now loads the nearest project .env automatically via python-dotenv, without overriding variables that are already exported in the shell.
Example:
GEMINI_API_KEY=your-key-here
SPEC_BUILDER_GEMINI_REQUEST_TIMEOUT_SECONDS=60
SPEC_BUILDER_GEMINI_MAX_ATTEMPTS=3-
Clone and set up the project
git clone https://github.com/kawofong/temporal-python-template.git cd temporal-python-template uv sync --dev -
Install development hooks
uv run poe pre-commit-install
-
Start Temporal
temporal server start-dev
-
Run the spec builder worker
export GEMINI_API_KEY=your-api-key uv run -m src.workflows.spec_builder.worker -
Build the local GUI frontend
cd src/spec_builder_gui/frontend npm install npm run build cd ../../. cd ../../...
-
Run the local GUI backend
uv run -m src.spec_builder_gui.server
-
Open the GUI
Visit
http://127.0.0.1:8080. The worker and the GUI backend are separate processes, so both must be running. -
Execute the sample spec builder workflow directly
uv run -m src.workflows.spec_builder.spec_builder_workflow
-
Run the tests
uv run poe test
The workflow package lives in src/workflows/spec_builder/ and is the backend contract for the local GUI in src/spec_builder_gui/. The workflow exposes stable queries and signals so the GUI can submit jobs, poll status, preview drafts, answer clarification requests, approve or reject results, cancel runs, and launch revision jobs from prior output.
- Accepts a typed
SpecBuilderInputwith local artifact references, user intent, output targets, and an output directory - Normalizes local markdown, text, image, diagram, slide, and PDF-like inputs into a persisted acquisition bundle
- Produces structured extraction and intent classification outputs before drafting
- Reviews the draft against Temporal best practices using a local best-practices corpus
- Supports bounded revision loops, clarification pauses, human approval gates, and cancellation
- Materializes final outputs into both
.spec_builder_runtime/<job_id>/and the requested localoutput_directory
The parent workflow coordinates seven fixed stages in this order:
acquire_contentactivityrun_structured_extractionactivityrun_intent_classificationactivityrun_extraction_criticactivityrun_draft_specactivityTemporalBestPracticesReviewWorkflowchild workflowrun_supervisor_decisionactivity
The supervisor can:
- accept the draft
- request a draft-only revision
- request a restart from acquisition/extraction
- ask for human clarification
When requireHumanApproval is enabled, a supervisor accept moves the workflow into a human approval wait state until approve_draft or reject_draft is received. The GUI can also send force_finalize_draft to finalize the current reviewed draft with an explicit human override note, even when high-severity best-practices violations are still present.
Queries:
get_statusget_live_stateget_current_phaseget_current_draftget_open_questionsget_best_practices_violationsget_traceability_summary
Signals:
submit_clarificationapprove_draftforce_finalize_draftreject_draftcancel_job
These handlers are the live integration surface used by the same-machine GUI status panel and review surface.
The GUI backend and frontend live under src/spec_builder_gui/. The browser talks only to the local aiohttp backend, which persists GUI job metadata under .spec_builder_runtime/gui/ and proxies Temporal workflow operations.
POST /api/artifacts: upload one PDF or image artifact into local runtime storagePOST /api/jobs: create and start aSpecBuilderWorkflowGET /api/jobs: list and refresh jobsGET /api/jobs/:jobId: load job detail, current draft markdown, stage state, violations, and review actionsPOST /api/jobs/:jobId/review: approve, reject, force-finalize, clarify, or cancel an active jobPOST /api/jobs/:jobId/revise: create a linked revision job from prior output plus revision notesGET /api/jobs/:jobId/download: download final markdown outputPOST /api/system/pick-output-directory: attempt a native local directory picker on supported hosts
New Job: upload artifacts, set the output directory, and launch a workflowJobs: browse active and historical jobs with search and status filtersJob Detail: inspect live phase/timeline state, markdown drafts, violations, and review controlsPast Specs: browse completed, failed, and cancelled jobs and launch revisions
cd src/spec_builder_gui/frontend
npm install
npm test
npm run buildThe workflow persists large artifacts under .spec_builder_runtime/<job_id>/ using stage-specific folders such as:
rawnormalizedacquisitionextractiondraftsreviewclarificationscorpusfinal
The final persistence step writes real local files into the requested output_directory, including:
spec.mdspec.jsontraceability.jsonbest_practices_review.jsonissues.json
Runtime configuration is handled by src/workflows/spec_builder/gemini_executor.py.
Required environment variables:
GEMINI_API_KEYorGOOGLE_API_KEY
Optional overrides:
SPEC_BUILDER_GEMINI_REQUEST_TIMEOUT_SECONDSSPEC_BUILDER_GEMINI_MAX_ATTEMPTSSPEC_BUILDER_GEMINI_EMBEDDING_MODELSPEC_BUILDER_GEMINI_ACQUIRE_CONTENT_MODELSPEC_BUILDER_GEMINI_STRUCTURED_EXTRACTION_MODELSPEC_BUILDER_GEMINI_INTENT_CLASSIFICATION_MODELSPEC_BUILDER_GEMINI_EXTRACTION_CRITIC_MODELSPEC_BUILDER_GEMINI_DRAFT_SPEC_MODELSPEC_BUILDER_GEMINI_BEST_PRACTICES_REVIEW_MODELSPEC_BUILDER_GEMINI_SUPERVISOR_DECISION_MODEL
src/workflows/spec_builder/custom_types.py: typed Pydantic contracts for workflow state, signals, queries, and stage outputssrc/workflows/spec_builder/spec_builder_workflow.py: parent workflow orchestration, queries, signals, approval gates, restart rules, and sample local executionsrc/workflows/spec_builder/spec_builder_activities.py: activity boundaries for acquisition, Gemini-backed stages, retrieval, and final artifact persistencesrc/workflows/spec_builder/prompts/activity_prompts.py: prompt builders for each model-backed stagesrc/workflows/spec_builder/gemini_executor.py: Gemini adapter with retries, typed parsing, model overrides, and attachmentssrc/workflows/spec_builder/worker.py: worker bootstrap for thespec-builder-task-queuesrc/workflows/spec_builder/tests/: workflow, activity, worker, and executor testssrc/spec_builder_gui/server.py: localaiohttpbackend that stores GUI metadata and proxies Temporal operationssrc/spec_builder_gui/frontend/: React + TypeScript frontend for the local GUIsrc/spec_builder_gui/server_tests.py: backend API/service testssrc/resources/sa_workflow_design_best_practices_critic_guide.md: default Temporal best-practices review corpus
- Run tests:
uv run poe test - Run lint:
uv run poe lint - Run formatting:
uv run poe format - Start the worker:
uv run -m src.workflows.spec_builder.worker - Start the GUI backend:
uv run -m src.spec_builder_gui.server - Run frontend tests:
cd src/spec_builder_gui/frontend && npm test - Build frontend assets:
cd src/spec_builder_gui/frontend && npm run build - Execute the sample workflow:
uv run -m src.workflows.spec_builder.spec_builder_workflow
- See
docs/temporal-patterns.mdfor advanced Temporal patterns - See
docs/testing.mdfor Temporal testing guidance - See
DEVELOPERS.mdfor local development tips and workflows