Skip to content

: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.

feat(autoresearch): expose pipelines as a HogQL system table (3/22) (#88741)

Andrew Maguire808ed36282ba
diff --git a/posthog/clickhouse/query_tagging.py b/posthog/clickhouse/query_tagging.py
index a05401b1188c..8b07518a7040 100644
--- a/posthog/clickhouse/query_tagging.py
+++ b/posthog/clickhouse/query_tagging.py
@@ -48,6 +48,7 @@ def is_api_key_access_method(access_method: AccessMethod | str | None) -> bool:
class Product(StrEnum):
API = "api"
+ AUTORESEARCH = "autoresearch"
BATCH_EXPORT = "batch_export"
COHORTS = "cohorts"
CONVERSATIONS = "conversations"
diff --git a/posthog/hogql/database/schema/system.py b/posthog/hogql/database/schema/system.py
index 5a455c0829de..3e8fc0db48e4 100644
--- a/posthog/hogql/database/schema/system.py
+++ b/posthog/hogql/database/schema/system.py
@@ -1021,6 +1021,46 @@ groups: PostgresTable = PostgresTable(
},
)
+autoresearch_pipelines: PostgresTable = PostgresTable(
+ name="autoresearch_pipelines",
+ postgres_table_name="autoresearch_autoresearchpipeline",
+ access_scope="autoresearch",
+ description="Autoresearch pipelines; one row per standing prediction question (a target event, a population, and a horizon).",
+ fields={
+ "id": UUIDDatabaseField(name="id", description="Pipeline UUID."),
+ "team_id": IntegerDatabaseField(name="team_id", description="Team the pipeline belongs to."),
+ "name": StringDatabaseField(name="name", description="Human-readable name."),
+ "description": StringDatabaseField(name="description", description="Free-text description; blank when unset."),
+ "target_event": StringDatabaseField(
+ name="target_event", description="Event the pipeline predicts, for example '$pageview'."
+ ),
+ "horizon_days": IntegerDatabaseField(
+ name="horizon_days", description="Number of days ahead the prediction looks for the target event."
+ ),
+ "status": StringDatabaseField(
+ name="status",
+ description="One of draft, bootstrapping, running, converged, paused, archived.",
+ ),
+ "iteration_budget": IntegerDatabaseField(
+ name="iteration_budget", description="Maximum training iterations the agent loop may spend."
+ ),
+ "iteration_budget_remaining": IntegerDatabaseField(
+ name="iteration_budget_remaining",
+ nullable=True,
+ description="Training iterations still available to spend (NULL when unset).",
+ ),
+ "output_person_property": StringDatabaseField(
+ name="output_person_property",
+ description="Person property the champion model's score is written to; blank when unset.",
+ ),
+ "last_scored_at": DateTimeDatabaseField(
+ name="last_scored_at", nullable=True, description="When inference last ran (NULL before the first run)."
+ ),
+ "created_at": DateTimeDatabaseField(name="created_at", description="When the pipeline was created."),
+ "updated_at": DateTimeDatabaseField(name="updated_at", description="When the pipeline was last modified."),
+ },
+)
+
group_type_mappings: PostgresTable = PostgresTable(
name="group_type_mappings",
postgres_table_name="posthog_grouptypemapping",
@@ -2995,6 +3035,7 @@ class SystemTables(TableNode):
"task_runs": TableNode(name="task_runs", table=task_runs),
"tags": TableNode(name="tags", table=tags),
"tasks": TableNode(name="tasks", table=tasks),
+ "autoresearch_pipelines": TableNode(name="autoresearch_pipelines", table=autoresearch_pipelines),
"teams": TableNode(name="teams", table=teams),
"trace_review_scores": TableNode(name="trace_review_scores", table=trace_review_scores),
"trace_reviews": TableNode(name="trace_reviews", table=trace_reviews),
diff --git a/posthog/hogql/database/schema/test/test_system_tables.py b/posthog/hogql/database/schema/test/test_system_tables.py
index 95a3f46cdb0c..61491c444dfb 100644
--- a/posthog/hogql/database/schema/test/test_system_tables.py
+++ b/posthog/hogql/database/schema/test/test_system_tables.py
@@ -1,5 +1,6 @@
import json
import uuid
+from types import SimpleNamespace
from posthog.test.base import BaseTest, NonAtomicBaseTest
@@ -32,6 +33,7 @@ from products.ai_observability.backend.models.score_definitions import ScoreDefi
from products.ai_observability.backend.models.trace_reviews import TraceReview, TraceReviewScore
from products.alerts.backend.models.alert import AlertConfiguration
from products.annotations.backend.models.annotation import Annotation
+from products.autoresearch.backend.facade import testing as autoresearch_testing
from products.business_knowledge.backend.models import KnowledgeChunk, KnowledgeDocument, KnowledgeSource
from products.business_knowledge.backend.models.constants import SourceStatus, SourceType
from products.canvas.backend.models import Canvas
@@ -292,6 +294,11 @@ def _create_annotation(team: Team, label: str) -> Annotation:
return Annotation.objects.create(team=team, content=f"annotation_{label}")
+def _create_autoresearch_pipeline(team: Team, label: str) -> SimpleNamespace:
+ # autoresearch is sealed: the row is planted through its facade, so only the id comes back.
+ return SimpleNamespace(pk=autoresearch_testing.create_pipeline(team_id=team.pk, name=f"pipeline_{label}"))
+
+
def _create_cohort_calculation_history(team: Team, label: str) -> CohortCalculationHistory:
cohort = Cohort.objects.create(team=team, name=f"cohort_for_calc_{label}")
return CohortCalculationHistory.objects.create(team=team, cohort=cohort, filters={})
@@ -866,6 +873,7 @@ SYSTEM_TABLE_FACTORIES = [
("actions", _create_action),
("alerts", _create_alert),
("annotations", _create_annotation),
+ ("autoresearch_pipelines", _create_autoresearch_pipeline),
("batch_export_backfills", _create_batch_export_backfill),
("batch_export_on_demands", _create_batch_export_on_demand),
("batch_export_runs", _create_batch_export_run),
diff --git a/posthog/hogql/database/test/__snapshots__/test_database.ambr b/posthog/hogql/database/test/__snapshots__/test_database.ambr
index e58732fdf9c6..516f0267b1a1 100644
--- a/posthog/hogql/database/test/__snapshots__/test_database.ambr
+++ b/posthog/hogql/database/test/__snapshots__/test_database.ambr
@@ -11473,6 +11473,135 @@
"row_count": null,
"type": "system"
},
+ "system.autoresearch_pipelines": {
+ "certification": null,
+ "fields": {
+ "id": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "id",
+ "id": null,
+ "name": "id",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "name": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "name",
+ "id": null,
+ "name": "name",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "description": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "description",
+ "id": null,
+ "name": "description",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "target_event": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "target_event",
+ "id": null,
+ "name": "target_event",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "horizon_days": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "horizon_days",
+ "id": null,
+ "name": "horizon_days",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "status": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "status",
+ "id": null,
+ "name": "status",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "iteration_budget": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "iteration_budget",
+ "id": null,
+ "name": "iteration_budget",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "iteration_budget_remaining": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "iteration_budget_remaining",
+ "id": null,
+ "name": "iteration_budget_remaining",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "output_person_property": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "output_person_property",
+ "id": null,
+ "name": "output_person_property",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "last_scored_at": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "last_scored_at",
+ "id": null,
+ "name": "last_scored_at",
+ "schema_valid": true,
+ "table": null,
+ "type": "datetime"
+ },
+ "created_at": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "created_at",
+ "id": null,
+ "name": "created_at",
+ "schema_valid": true,
+ "table": null,
+ "type": "datetime"
+ },
+ "updated_at": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "updated_at",
+ "id": null,
+ "name": "updated_at",
+ "schema_valid": true,
+ "table": null,
+ "type": "datetime"
+ }
+ },
+ "id": "system.autoresearch_pipelines",
+ "name": "system.autoresearch_pipelines",
+ "row_count": null,
+ "type": "system"
+ },
"system.teams": {
"certification": null,
"fields": {
@@ -22923,6 +23052,135 @@
"row_count": null,
"type": "system"
},
+ "system.autoresearch_pipelines": {
+ "certification": null,
+ "fields": {
+ "id": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "id",
+ "id": null,
+ "name": "id",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "name": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "name",
+ "id": null,
+ "name": "name",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "description": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "description",
+ "id": null,
+ "name": "description",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "target_event": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "target_event",
+ "id": null,
+ "name": "target_event",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "horizon_days": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "horizon_days",
+ "id": null,
+ "name": "horizon_days",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "status": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "status",
+ "id": null,
+ "name": "status",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "iteration_budget": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "iteration_budget",
+ "id": null,
+ "name": "iteration_budget",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "iteration_budget_remaining": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "iteration_budget_remaining",
+ "id": null,
+ "name": "iteration_budget_remaining",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "output_person_property": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "output_person_property",
+ "id": null,
+ "name": "output_person_property",
+ "schema_valid": true,
+ "table": null,
+ "type": "string"
+ },
+ "last_scored_at": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "last_scored_at",
+ "id": null,
+ "name": "last_scored_at",
+ "schema_valid": true,
+ "table": null,
+ "type": "datetime"
+ },
+ "created_at": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "created_at",
+ "id": null,
+ "name": "created_at",
+ "schema_valid": true,
+ "table": null,
+ "type": "datetime"
+ },
+ "updated_at": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "updated_at",
+ "id": null,
+ "name": "updated_at",
+ "schema_valid": true,
+ "table": null,
+ "type": "datetime"
+ }
+ },
+ "id": "system.autoresearch_pipelines",
+ "name": "system.autoresearch_pipelines",
+ "row_count": null,
+ "type": "system"
+ },
"system.teams": {
"certification": null,
"fields": {
diff --git a/products/autoresearch/backend/facade/testing.py b/products/autoresearch/backend/facade/testing.py
new file mode 100644
index 000000000000..c1d839c8d3bd
--- /dev/null
+++ b/products/autoresearch/backend/facade/testing.py
@@ -0,0 +1,17 @@
+"""Test-support facade for autoresearch.
+
+Suites outside this product plant pipeline rows through here instead of importing the
+model. The model is team-scoped and fail-closed, so this opens the scope the insert needs.
+"""
+
+from uuid import UUID
+
+from posthog.models.scoping import team_scope
+
+from products.autoresearch.backend.models import AutoresearchPipeline
+
+
+def create_pipeline(*, team_id: int, name: str, target_event: str = "$pageview") -> UUID:
+ with team_scope(team_id):
+ pipeline = AutoresearchPipeline.objects.create(team_id=team_id, name=name, target_event=target_event)
+ return pipeline.pk
diff --git a/products/posthog_ai/scripts/schema_columns/__init__.py b/products/posthog_ai/scripts/schema_columns/__init__.py
index d0ca6210535d..e42305a4d898 100644
--- a/products/posthog_ai/scripts/schema_columns/__init__.py
+++ b/products/posthog_ai/scripts/schema_columns/__init__.py
@@ -13,7 +13,9 @@ from __future__ import annotations
from dataclasses import dataclass
from functools import lru_cache
-_HEADER = "Column | Type | Nullable | Description"
+# The separator row is part of the header: without it the block is not a markdown table and
+# renders as plain text wherever the reference is displayed.
+_HEADER = "Column | Type | Nullable | Description\n--- | --- | --- | ---"
# Not `@frozen` from `posthog.dataclasses`: importing it runs `posthog/__init__`, and every helper
diff --git a/products/posthog_ai/skills/querying-posthog-data/SKILL.md b/products/posthog_ai/skills/querying-posthog-data/SKILL.md
index 146fa4ab087a..6a9b9d2eab0b 100644
--- a/products/posthog_ai/skills/querying-posthog-data/SKILL.md
+++ b/products/posthog_ai/skills/querying-posthog-data/SKILL.md
@@ -55,6 +55,7 @@ Every column table below is generated from the live HogQL catalog, so it lists e
- [Actions](./references/models-actions.md)
- [Alerts](./references/models-alerts.md)
- [Annotations](./references/models-annotations.md)
+- [Autoresearch](./references/models-autoresearch.md)
- [APM / tracing (`posthog.trace_spans`)](./references/models-apm-spans.md)
- [Batch exports](./references/models-batch-exports.md)
- [Early Access Features](./references/models-early-access-features.md)
diff --git a/products/posthog_ai/skills/querying-posthog-data/references/models-autoresearch.md.j2 b/products/posthog_ai/skills/querying-posthog-data/references/models-autoresearch.md.j2
new file mode 100644
index 000000000000..db596c62690f
--- /dev/null
+++ b/products/posthog_ai/skills/querying-posthog-data/references/models-autoresearch.md.j2
@@ -0,0 +1,15 @@
+# Autoresearch
+
+## AutoresearchPipeline (`system.autoresearch_pipelines`)
+
+A standing prediction question: a target event, a population, and a horizon ("who will download a file in the next 30 days?").
+An agent searches for a model that answers it, and the product scores the population on a cadence.
+
+### Columns
+
+{{ schema_columns('system.autoresearch_pipelines') }}
+
+### Key Relationships
+
+- Pipelines belong to a **Team** (`team_id`)
+- A pipeline owns its training runs, iterations, trained models, operational runs, and suggestions. None of those are exposed as system tables, and there is no read path for them yet.
diff --git a/tach.toml b/tach.toml
index 4e59a0b91e10..bf83205f27e9 100644
--- a/tach.toml
+++ b/tach.toml
@@ -79,6 +79,7 @@ layer = "modules"
[[modules]]
path = "posthog"
depends_on = [
+ "products.autoresearch",
"products.cohorts",
"ee",
"products.access_control",