Skip to content

Mitokic/09202026/custom model logic - #292

Merged
Mike Tokic (mitokic) merged 14 commits into
mainfrom
mitokic/09202026/custom-model-logic
Oct 20, 2026
Merged

Mike Tokic (mitokic) merged 14 commits into
mainfrom
mitokic/09202026/custom-model-logic

Conversation

@mitokic

Copy link
Copy Markdown
Collaborator

Summary

Add custom forecasting models to finnts. create_custom_model() turns plain-language business rules plus a simple example table into a validated, approved local or global model. That model then runs in standard forecasts (prep_models() → final_models()) and in Agent forecasts and updates, side by side with the built-in models.

Changes

  • Authoring: create_custom_model() uses an LLM to generate fit/predict code from instructions and checks it against worked examples in validation_examples. It approves the model manually in interactive sessions and automatically otherwise, and returns a finnts_custom_model. Draft/response round-trips are removed, so it is a single call.
  • Example tables: examples are a plain data frame with columns example, Date, target, drivers, expected, and optional edge_case, expected_error, how and tolerance. A new exported custom_model_examples_template() gives a starting table that users and coding agents can fill in.
  • New helpers: custom_model_feedback(), custom_model_control() and print() for custom models.
  • Runtime: sandboxed execution in a fit/predict engine, a registry, run storage and validation. Supports local and global modes, hierarchies, drivers/external regressors and parallel workers.
  • C1 recipe: a new C1 recipe (recipes_to_run) feeds custom models raw history and every eligible column as a driver. It works with built-in recipes, multistep, feature selection, averages/ensembles and Spark.
  • Enrollment: prep_models(models_to_run = NULL) runs all built-in models plus every supplied custom model. An explicit models_to_run must name each custom model, or the call errors.
  • Agent: custom models are mandatory from iteration 1 and are carried through iteration, summarization, fallback and update_forecast(), including restart, integrity checks, cohorts and worker paths.
  • Selection/finalization: custom models take part in model selection and ensembles. Agent finalization keeps numeric-looking run IDs and series names with leading zeros.
  • Docs: new pkgdown "Custom Models" reference section, plus vignette updates for the Agent, model selection, hierarchy and the models list. Agent guides and architecture map are updated too.

Notable / Breaking

  • New exports: create_custom_model, custom_model_examples_template, custom_model_feedback, custom_model_control.
  • prep_models() errors when custom models are supplied but missing from an explicit models_to_run.
  • Version bumped to 0.7.0.9010. No new hard dependencies. Authoring needs an ellmer chat object.
  • Not yet done: custom models are validated only against the user's examples, not back-test splits.

Testing

  • Added about 50 testthat files covering authoring, validation, example tables, runtime, registry, C1 recipe, hierarchy, global mode, standard enrollment/selection/workers and Agent iteration/update/restart/fallback.
  • Targeted tests passed; full validation (devtools::check(), the full suite) was not run.
  • Live Azure model-router matrix with example tables: global 20/20 passed. The local matrix with example tables has not been run; the last local run (older list examples) passed 24/32, with expected guardrail rejections in case 15 and environment-related process crashes that passed when replayed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Custom finalization can lose CSV series identities, and the hierarchy authoring example passes an unsupported argument.

2 open findings
What changed in this PR

Adds approved custom forecasting rules to FinnTS’s standard and Agent workflows, alongside built-in models.

Changes:

  • Introduces custom-model authoring, enrollment, raw C1 recipes and runtime integration.
  • Adds regression coverage for selection, hierarchy, workers, updates and restart integrity.
  • Expands documentation and clarifies targeted validation guidance.
File Description
vignettes/​models-used-in-finnts.Rmd Explains C1 and custom drivers.
vignettes/​hierarchical-forecasting.Rmd Documents custom hierarchy workflows.
vignettes/​ai-agent.Rmd Documents custom enrollment and updates.
tests/​testthat/​test-custom-model-standard.R Tests training and version identity.
tests/​testthat/​test-custom-model-standard-workers.R Checks parallel training parity.
tests/​testthat/​test-custom-model-standard-selection.R Tests averages and component integrity.
tests/​testthat/​test-custom-model-standard-global.R Tests global output and flooring.
tests/​testthat/​test-custom-model-standard-errors.R Tests runtime failure boundaries.
tests/​testthat/​test-custom-model-standard-enrollment.R Tests explicit enrollment rules.
tests/​testthat/​test-custom-model-standard-authorized.R Tests automatic approval envelopes.
tests/​testthat/​test-custom-model-hierarchy-runtime.R Exercises standard hierarchy forecasts.
tests/​testthat/​test-custom-model-hierarchy-grouped.R Exercises grouped hierarchy forecasts.
tests/​testthat/​test-custom-model-example-table.R Tests example-table conversion.
tests/​testthat/​test-custom-model-contract.R Tests definitions and content hashes.
tests/​testthat/​test-custom-model-c1-drivers.R Tests independent C1 drivers.
tests/​testthat/​test-artifact-io-parallel.R Updates worker helper dependencies.
tests/​testthat/​test-agent-update-forecast.R Checks lightweight worker context.
tests/​testthat/​test-agent-custom-updates.R Tests replay and identifier preservation.
tests/​testthat/​test-agent-custom-update-workers.R Checks real update workers.
tests/​testthat/​test-agent-custom-update-restart.R Tests restart without refitting.
tests/​testthat/​test-agent-custom-update-integrity.R Tests immutable update provenance.
tests/​testthat/​test-agent-custom-update-global.R Tests shared global replay.
tests/​testthat/​test-agent-custom-update-execution.R Tests recoverable error classification.
tests/​testthat/​test-agent-custom-update-defaults.R Tests new-series default forecasts.
tests/​testthat/​test-agent-custom-update-cohort.R Tests changed-cohort recovery.
tests/​testthat/​test-agent-custom-storage.R Tests exact-path backend reads.
tests/​testthat/​test-agent-custom-iteration.R Tests iteration and restart behavior.
tests/​testthat/​test-agent-custom-iteration-workers.R Checks independent Agent workers.
tests/​testthat/​test-agent-custom-iteration-global.R Tests global iteration identity.
tests/​testthat/​test-agent-custom-integration.R Tests reasoning and runtime integration.
tests/​testthat/​test-agent-custom-fallback.R Tests bounded custom recovery.
tests/​testthat/​test-agent-custom-enrollment.R Tests enrollment persistence and references.
tests/​testthat/​test-agent-custom-driver-update.R Tests driver preservation during updates.
tests/​testthat/​test-agent-custom-driver-iteration.R Tests driver-independent Agent settings.
tests/​testthat/​helper-custom-model-standard.R Supplies standard forecasting fixtures.
tests/​testthat/​helper-custom-model-hierarchy.R Supplies hierarchy fixtures and assertions.
tests/​testthat/​helper-custom-model-authoring.R Supplies authoring and console fixtures.
tests/​testthat/​helper-custom-drivers.R Supplies proportional-driver fixtures.
tests/​testthat/​helper-agent-custom-models.R Supplies offline Agent fixtures.
scott_cherry_custom_acr_logic_playground_prompt.md Adds a business-rule generation prompt.
R/​utility.R Registers the custom engine.
R/​read_write_data.R Adds C1 artifact handling.
R/​hierarchy.R Validates custom reconciliation coverage.
R/​forecast_time_series.R Integrates custom enrollment and C1.
R/​forecast_selection.R Supports raw C1 history.
R/​final_models.R Audits custom artifacts before selection.
R/​ensemble_models.R Aligns mixed-model ensemble targets.
R/​custom_model_registry.R Adds version-bound model storage.
R/​agent_summarize_models.R Adds custom metadata summaries.
R/​agent_info.R Persists custom Agent enrollment.
NEWS.md Records custom-model features and fixes.
NAMESPACE Registers new exports and printing.
man/​update_forecast.Rd Documents custom replay requirements.
man/​train_models.Rd Documents custom training behavior.
man/​set_agent_info.Rd Documents custom Agent setup.
man/​print.finnts_custom_model.Rd Documents custom-model printing.
man/​prep_models.Rd Documents enrollment contracts.
man/​prep_data.Rd Documents C1 preparation.
man/​iterate_forecast.Rd Documents custom iteration behavior.
man/​get_summarized_models.Rd Documents custom summary metadata.
man/​forecast_time_series.Rd Documents integrated custom forecasts.
man/​final_models.Rd Documents custom selection and reconciliation.
man/​ensemble_models.Rd Documents custom ensemble inputs.
man/​custom_model_predict_impl.Rd Documents prediction contracts.
man/​custom_model_fit_impl.Rd Documents fitting contracts.
man/​custom_model_feedback.Rd Documents authoring feedback.
man/​custom_model_examples_template.Rd Documents worked-example tables.
man/​custom_model_control.Rd Documents authoring controls.
man/​create_custom_model.Rd Documents creation and execution boundaries.
DESCRIPTION Advances the development version.
CLAUDE.md References targeted validation scope.
AGENTS.md Defines validation and implementation scope.
.vscode/​settings.json Sets the Python environment manager.
.github/​agent-guides/​validation-matrix.md Updates validation scope and regression guidance.
.claude/​skills/​finnts-validation/​SKILL.md Updates canonical validation guidance.
.claude/​rules/​r-package.md Clarifies deferred full-validation checks.
.agents/​skills/​finnts-validation/​SKILL.md Synchronizes generated validation guidance.
_pkgdown.yml Adds the Custom Models reference section.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread R/final_models.R
Comment thread vignettes/hierarchical-forecasting.Rmd Outdated
Comment thread R/custom_model_runs.R Outdated
Comment thread R/custom_model_authoring.R
Comment thread R/prep_models.R
Comment thread R/agent_summarize_models.R Outdated
Comment thread R/agent_update_forecast.R
Comment thread R/agent_iterate_forecast.R
@mitokic
Mike Tokic (mitokic) merged commit 768e993 into main Oct 20, 2026
10 of 13 checks passed
@mitokic
Mike Tokic (mitokic) deleted the mitokic/09202026/custom-model-logic branch October 20, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants