An experimentation stack for workflow automation built around JSON Schema–driven OpenAI API calls and Node-RED flows.
Instead of focusing primarily on cellular automata, this repo now treats cellular automata as one optional sandbox inside a broader system for iterating on, judging, and evolving automation workflows.
X40 Schemas is designed to help you:
- Prototype workflow automations as Node-RED flows.
- Define strict contracts for LLM inputs/outputs using JSON Schema.
- Call OpenAI models via schema-aware helpers that validate and hydrate responses.
- Run experiments automatically, log results, and compute composite fitness scores.
- Close the loop with an autonomous Node-RED controller that proposes, runs, and judges experiments continuously.
Core areas of the repo:
openai_json_schemas/– Shell + Node helpers for JSON Schema–first OpenAI calls.src/schemas/– Canonical schemas for hypotheses, judgments, Node-RED flows, and more.node_red/flows/– Node-RED flows for the autonomous researcher and LLM judge.x40_experiments/– On-disk registry of experiments, analytics, and fitness scores.src/– Python utilities (including the legacy cellular automata sandbox).
Cellular automata lives in src/rich_cellular_automata.py and related modules and now serves as an example environment, not the primary focus.
- OpenAI JSON helpers in
openai_json_schemas/:openai_json_of_schema.sh– Call OpenAI and validate the JSON response against a schema.openai_gen_json_schema.sh/openai_gen_vetted_schema.sh– Generate and vet schemas.ajv_validate.sh,compare_hydrators.py, and tests underschemas/+objects/.
- Shared schemas in
src/schemas/:hypothesis_schema.json– Next‑experiment proposals.experiment_judgment_schema.json– Structured verdicts for completed runs.node_red_flow_schema.jsonand related flow schemas.
Together, these pieces enforce typed, inspectable contracts between OpenAI, Node-RED, and the Python tooling.
- Experiments are stored under
x40_experiments/with prompts, flows, metrics, and judgments. x40_experiments/scripts/compute_fitness.py:- Scans experiment directories and emits:
analytics/fitness_summary.json– Compact view used by the controller.analytics/fitness_details.json– Full archive of scores and signals.analytics/novelty_archive.json– Tracks behavior fingerprints for novelty.
- Computes a composite fitness based on:
technical_success,novelty,simplicity,interaction,efficiency,reuse, and placeholders for external/revenue signals.
- Adapts weights across generations (explore → pattern finding → exploit).
- Scans experiment directories and emits:
Key flows live in node_red/flows/:
autonomous_researcher.json- Orchestrates the full loop:
- Recompute fitness via
compute_fitness.py. - Call the hypothesis LLM (using
hypothesis_schema.json) to propose the next experiment. - Materialize a new experiment directory (prompt, slug, refs, node types).
- Invoke
run_experiment.shto execute the flow. - Append lifecycle events to
analytics/meta_log.jsonl. - Call the judge service and then self‑loop for the next iteration.
- Recompute fitness via
- Orchestrates the full loop:
judge_experiments.json- Exposes an HTTP endpoint (default
POST /judgeon port1891). - Loads traces + metrics, builds a rich prompt, and calls
openai_json_of_schema.sh. - Writes
judgment.jsonalongside each experiment and updatesregistry.json. - Always returns a structured response and fails conservatively when parsing issues occur.
- Exposes an HTTP endpoint (default
See docs/autonomous_research_workflow.md for a deep dive into this architecture.
The original project started as an AI‑powered cellular automata sandbox:
src/rich_cellular_automata.py– Rich‑based terminal simulation driver.src/cellular_automata.py,src/llm_cellular_automata.py,src/visualization.py.openai_json_schemas/+src/schemas/cell_schema.json,environment_schema.json, etc. for structured LLM‑driven cell behavior.
These components are still available for experimentation and demos, but the primary active work is now around workflow automation and Node-RED experiments rather than cellular automata research.
-
Python + dependencies
From the repo root:
pip install -r requirements.txt
-
Node.js / Node-RED
Install Node-RED globally (or via Docker) and ensure it can run custom user directories.
-
OpenAI API key
export OPENAI_API_KEY='your-api-key-here'
You can recompute experiment fitness manually at any time:
python3 x40_experiments/scripts/compute_fitness.py --top-k 15This populates x40_experiments/analytics/fitness_*.json and novelty_archive.json.
Run the Node-RED judge flow on port 1891:
node-red \
--userDir x40_experiments/JUDGE_scorer/userdir \
--flowFile ../node_red/flows/judge_experiments.json \
--port 1891This exposes POST /judge (default http://127.0.0.1:1891/judge), which:
- Validates input (
experiment_id). - Loads metrics, traces, and registry context.
- Builds a prompt and writes it to
/tmp/x40_judge_prompt.txt. - Calls
openai_json_schemas/openai_json_of_schema.shusingexperiment_judgment_schema.json. - Persists
judgment.jsonand updatesregistry.json.
Import node_red/flows/autonomous_researcher.json into a Node-RED runtime and start the flow:
- A single manual inject kicks off the loop.
- The flow then:
- Refreshes fitness summaries.
- Calls the hypothesis LLM using
hypothesis_schema.json. - Materializes and runs new experiments.
- Sends them to the judge.
- Loops back for the next iteration.
The system stays in continuous experiment mode: generating prompts, launching flows, evaluating them, and updating fitness metrics without manual babysitting.
If you’d like to explore the original cellular automata environment as a side experiment:
-
Ensure dependencies are installed (see above).
-
Run a simple rule‑based simulation (no OpenAI required):
python src/rich_cellular_automata.py --ticks 50 --cells 15 --speed 0.3
-
Enable LLM‑driven behavior (requires
OPENAI_API_KEY):python src/rich_cellular_automata.py --llm --ticks 20 --cells 5 --speed 1.0
These simulations demonstrate how JSON Schema–validated LLM calls can drive complex local dynamics, but they are no longer the main focus of the repo.
- OpenAI / schema issues
- Verify
OPENAI_API_KEYis set:echo $OPENAI_API_KEY. - Use
openai_json_schemas/ajv_validate.shto check schemas and outputs. - Check API quota, network connectivity, and any local proxy settings.
- Verify
- Node-RED flow issues
- Confirm the correct
--userDirand--flowFilepaths. - Use Node-RED’s debug sidebar and logs to inspect payloads.
- Ensure filesystem paths in
execnodes are absolute and match your checkout.
- Confirm the correct
- Fitness / experiment registry
- Re-run
compute_fitness.pyto refresh analytics. - Inspect
x40_experiments/analytics/*.jsonfor signal breakdowns.
- Re-run
For more detail, see docs/autonomous_research_workflow.md.
Contributions are welcome, especially around:
- New workflow patterns and Node-RED components.
- Additional JSON Schemas for common automation tasks.
- Improvements to the fitness heuristics and novelty detection.
- Better observability and dashboards for experiment telemetry.
- Refinements to the autonomous loop, including new judges or hypothesis strategies.
This project is open source. Please check the license file for details.
Happy automating and experimenting! 🧬🧠⚙️