Planner Context Window and Prompts

Iris (our OpenClaw AI agent) does not plan from a generic greenhouse prompt. Every planning event gets a generated context window that describes the current room, the active plan, recent outcomes, forecast pressure, crop targets, equipment state, lessons, and data-health caveats.

The context window is built before OpenClaw receives the event. OpenClaw routes the message; MCP tools validate writes; the ESP32 enforces the physical state machine.

Dynamic Data Window

scripts/gather-plan-context.sh builds the live greenhouse packet. It reads TimescaleDB views, Home Assistant state where needed, and current ESP32/forecast data. The packet is plain text because it has to be robust under both local and cloud planner routes.

Current sections include:

SectionWhat Iris getsPlanning use
System healthData-health and dependency completenessDecides whether to trust inputs or degrade.
Active planFuture transitions and Tier 1 valuesPrevents stale or contradictory posture.
Zone conditionsTemp, RH, VPD, CO2, outdoor weather, water, enthalpyDiagnoses current stress and zone imbalance.
ESP32 stateCurrent firmware state if availableDistinguishes plan intent from real controller mode.
24h hourly patternTemperature, VPD, RH, CO2, luxShows what just happened before forecast reasoning.
Planner scorecardToday’s score and recent trendConnects decisions to measured outcomes.
Compliance24h zone band percentagesSeparates temp and VPD failure modes.
DIF and DLIDay/night differential and light estimatesAvoids overreacting to known sensor limitations.
Hydro and irrigationWater quality, schedules, historyKeeps climate tactics aware of plant-water context.
Equipment runtimeRelay/equipment hours and transitionsSpots churn, stuck equipment, and cost drivers.
Energy and waterkWh, therms, watts, water trendMakes cost/resource tradeoffs visible.
Crops and observationsActive crops and growing contextKeeps plan goals tied to plants, not abstract comfort.
Previous plan reviewGoverning plan, outcome fields, validation stateForces the next plan to grade the last hypothesis.
Structured hypothesisTyped predicted conditions and stress windowsLets Iris compare forecast belief against actuals.
Tunable constraintsFirmware min/max/step readbacksPrevents impossible or clamp-heavy writes.
Active lessonsDeduplicated high-value lessonsCarries durable learning into new decisions.
Current setpointsLatest effective valuesFills unchanged waypoint values without broad queries.
Forecast alertsHeat, VPD, frost, overcast, cold-front signalsTurns weather changes into tactical posture.
Context completenessReachability/staleness of dependenciesMakes missing data explicit.

Static Site Context

scripts/gather-static-context.sh also builds /srv/verdify/state/planner-static-context.md. It concatenates public Markdown pages from the site, excluding generated daily plans, dashboards, static assets, and scripts.

This gives Iris the greenhouse documentation in the same form launch readers see it:

  • structure, equipment, zones, crops, and known limits
  • safety architecture and data model
  • planning loop and AI-Writable Tunables
  • economics, evidence, and build notes
  • lessons and FAQ language that constrain public claims

Static context keeps the planner anchored to this greenhouse’s actual hardware and physical limitations.

Prompt Family

ingestor/iris_planner.py has a tailored prompt builder for each planning event:

EventPurposeNormal output
SUNRISEMorning tactical plan for the next daylight and overnight periodFull set_plan with 3-6 compact transitions.
SUNSETOvernight posture and cold/disease controlFull set_plan with nighttime transitions.
MIDNIGHTRequired full-plan audit path when scheduledFull plan or validation-mode acknowledgement.
TRANSITIONCrop-band or solar transition checkpointset_tunable or acknowledge_trigger.
FORECASTWeather delta reviewAdjust posture only if forecast changed enough.
DEVIATIONMeasured stress/deviation responseImmediate bounded correction or explanation.
MANUALOperator-requested ad hoc runWhatever the operator asked, still within MCP bounds.

Each event gets the same safety contract, the same writable tunable limits, and the same audit headers. The difference is how much change the event is expected to make.

Prompt Contract

The stable prompt contract is public-safe to summarize:

READ: scorecard, climate, forecast, active plan, crop bands, lessons, alerts.
DIAGNOSE: identify the binding compliance axis and stress type.
DECIDE: apply safety first, then validated lessons, then forecast reasoning.
ACT: write bounded tunables or a full plan through MCP tools only.
REPORT: summarize decisions and tradeoffs for the operator.

The standing directives also require:

  • use MCP tools only
  • do not run shell, direct SQL, or Docker commands
  • include trigger_id and planner_instance on every write
  • do not acknowledge required SUNRISE/SUNSET full-plan cycles unless validation mode is active
  • call acknowledge_trigger for routine no-op cycles so SLA monitoring can close them honestly
  • write compact local plans and avoid broad read tools when using Gemma 4 26B A4B (MoE), served locally under the gemma4-26b alias

Context Window Trim Policy

The local route is designed for bounded, event-scoped context. Trigger-scoped sessions prevent chat history from growing without limit, but the generated packet still needs an explicit trim policy before required full plans move back to local by default.

Context classKeepTrim first
Safety and write contractFirmware safety split, tunable bounds, audit headers, current setpointsNever trim from required planning events.
Live stateCurrent climate, equipment state, active alerts, forecast pressure, active planKeep the latest compact rows; avoid broad historical dumps.
Recent outcomesLast plan hypothesis, scorecard, stress windows, resource useKeep concise summaries and links to plan/archive rows.
LessonsActive curated lessons and high-confidence constraintsCollapse duplicate machine confirmations before local planning.
Static site contextArchitecture, safety, known limits, crops/zones/equipment summariesPrefer summaries and canonical links over full prose when local context is tight.
Long historyOld plans, raw extraction rows, full dashboard proseRetrieve only when the event specifically needs it.

The practical rule is: local routine events should receive enough context to make a bounded tactical decision, not a full copy of the website and history. Heavyweight cloud reviews can carry more context, but they still use the same MCP write boundary.

Audit Header

Every delivered prompt ends with an audit banner:

trigger_id=<uuid>
planner_instance="local" | "opus"

The planner must pass those values into set_plan, set_tunable, or acknowledge_trigger. That is how Verdify correlates:

plan_delivery_log -> OpenClaw gateway delivery -> MCP write -> plan_journal/setpoint_changes -> public archive

If any link is missing, the failure should be visible. Missed cycles remain in the planning archive because planner availability is part of the system being audited.

Why This Matters

The AI layer can sound sophisticated, but the launch claim depends on a narrower fact: every planning decision is a bounded physical hypothesis with public evidence. The context window is what makes the hypothesis specific enough to test. The AI-Writable Tunables table is the schema. The ESP32 state machine is the enforcement layer. The scorecard is the judge.