:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Autoresearch
Agent-driven predictive modeling.
A user names a target event, a population, and a horizon ("who will download a file in the next 30 days?").
An agent then searches for the best model for that question, and once it finds one, the product scores the population on a cadence and writes the result back into PostHog as autoresearch_prediction events.
The framing is Karpathy's autoresearch prompt pattern: an agent edits one thing, runs a fixed eval, keeps the change if a single metric improved, reverts otherwise, and loops until a stop rule fires.
Here the "one thing" is a feature set plus a model spec, the fixed eval is holdout AUC on a labeled training population, and the loop runs inside a Tasks sandbox.
This directory holds the data model, the access gate, and the backend packages that have landed so far; each package has its own AGENTS.md.
The frontend lands in later pieces of the split tracked in #88464.
Data model in one pass
AutoresearchPipeline the standing question (target, population, horizon, cadence)
├─ AutoresearchTrainingRun one attempt to find a better model
│ └─ AutoresearchIteration one experiment inside that attempt (kept / discarded)
├─ AutoresearchModel a trained model, role = champion | challenger | archived
├─ AutoresearchRun one execution of inference, validation, or person property cleanup
└─ AutoresearchSuggestion a human- or agent-authored hypothesis for the next run to explore
AutoresearchModel.artifact_prefix points at the model's artifact bundle in object storage.
When it is empty the model carries only model_recipe, which the in-process scoring path reads.
Every model carries its own team foreign key and sits on TeamScopedRootMixin, so reads outside a team scope raise rather than crossing tenants.
Read through Model.objects.for_team(team_id) or inside a team_scope(team_id) block.
The five pipeline-owned models inherit PipelineScopedModel, whose save() derives team from the parent pipeline unconditionally (an explicit mismatched value is overwritten) and rejects related rows that belong to another pipeline, so a create only has to pass pipeline.
Every AUC and confidence column (success_auc, holdout_score, realized_score, best_holdout_score, train_score, agent_confidence) is NULL until measured and otherwise held to [0, 1] by a CHECK constraint.
A writer that produces a raw score has to normalize it before it saves.
The counters carry CHECK constraints too: iteration_budget is at least 1, iteration_count, rows_scored and iteration_budget_remaining are at least 0, and trained_on_start is no later than trained_on_end.
Feature flag and access
Gated by the autoresearch feature flag (backend/access.py).
Rollout is configured on the flag, and code only asks whether it is on.
The real-agent training path additionally needs Tasks access, because it runs in a Tasks sandbox.
Training schedule
Training never ends, but exploration comes first.
The daily sweep starts research runs on scoring days until a run fails to promote a better model or 5 research runs have run, then one run every research_interval_days after the latest run (backend/training/schedule.py).
Each run takes iterations_per_run iterations, and records why it started in kickoff_reason.
Per-project limits in backend/limits.py bound every sandbox run, however it starts (sweep, UI, API or MCP).
A project starts at most max_training_runs_per_day sandbox runs (default 3) in any rolling 24 hours, across all its pipelines, and no run gets more than max_iterations_per_run iterations (default 10).
Runs that open_training_run() opens for an external agent do not count against the daily limit, because the caller's own agent does the work.
A project has at most max_live_pipelines live pipelines (default 3).
Live means bootstrapping, running or converged; draft, paused and archived do not count.
A draft with an open training run counts too, because its promotion makes it live with no check.
The facade refuses a pipeline going live at the limit with LivePipelineCapReached (a 400): starting a draft's first run, opening an external run on a draft, and resuming a paused pipeline.
Pipelines already over the limit keep running and training.
All three limits resolve from the autoresearch flag payload: the project's team_configs["<team_id>"] entry, then default_team_config, then the code constants.
Edit the payload to change a limit without a deploy.
The pipeline viewset's limits action reports each limit with the project's current usage, for the Setup tab.
Each run also records the runtime adapter, model and reasoning effort it was dispatched with (see backend/training/AGENTS.md).
iteration_budget and iteration_budget_remaining are deprecated: nothing scheduled reads them.
Invariants that cross package boundaries
These are the ones that have actually broken things.
- Everything is keyed on
person_id, one row per person. Agent-authoredfeature_sqlmust be a read-onlySELECTkeyed onperson_id, and the label and population queries key on it too. The feature SQL exposes that key under the column namedistinct_id(a.person_id AS distinct_id), which is what the training join and the materialized parquet read; the name is historical, the value is always the person id. A mismatch here does not raise, it silently produces all-zero labels and a degenerate model. A uniform score distribution is an identifier mismatch until proven otherwise, not a bad model. - The agent proposes, the backend disposes. Iterations are recorded by the agent, but champion selection happens server-side. Never let agent output pick the champion directly.
- Autoresearch trains on identified users only. On demo-style datasets that are largely anonymous, raw event counts wildly overstate how much training data exists.