: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(autoresearch): enable the autoresearch-score-create mcp tool (#110070)
posthog[bot]ed91cd992d2d
diff --git a/products/autoresearch/mcp/AGENTS.md b/products/autoresearch/mcp/AGENTS.mdindex fe5487bc07bb..50187e2ad782 100644--- a/products/autoresearch/mcp/AGENTS.md+++ b/products/autoresearch/mcp/AGENTS.md@@ -7,7 +7,7 @@ During a run, the sandbox agent has no other write path. It records iterations,## What lives here- `tools.yaml`- The whole surface: 20 enabled tools, `category: Autoresearch`, `feature: autoresearch`, `url_prefix: /autoresearch`. The family must stay at or below 25 tools: above that the exec tool's compact domain index splits it into sub-domains, and the serialized exec schema crosses the claude.ai registry cap (see `services/mcp/tests/unit/instructions-formatter-snapshot.test.ts`). Duplicative tools (`suggestions-retrieve`, `templates-list`, `validate-online-create`, `artifacts-delete-create`) are disabled rather than removed. `resolve-template-create` names every template key, so it replaces `templates-list` as the template entry point.+ The whole surface: 21 enabled tools, `category: Autoresearch`, `feature: autoresearch`, `url_prefix: /autoresearch`. The family must stay at or below 25 tools: above that the exec tool's compact domain index splits it into sub-domains, and the serialized exec schema crosses the claude.ai registry cap (see `services/mcp/tests/unit/instructions-formatter-snapshot.test.ts`). Duplicative tools (`suggestions-retrieve`, `templates-list`, `validate-online-create`, `artifacts-delete-create`) are disabled rather than removed. `resolve-template-create` names every template key, so it replaces `templates-list` as the template entry point.Each entry names an `operation` (an operation id from the OpenAPI spec), an `enabled` flag, required `scopes` (`autoresearch:read` / `autoresearch:write`, plus every extra scope the endpoint's `required_scopes` names, such as `query:read`: MCP hides a tool whose scopes the key lacks), `annotations` (`readOnly`, `destructive`, `idempotent`), and a `title` + `description`.Tool entries are scaffolded from the OpenAPI schema — `pnpm --filter=@posthog/mcp run scaffold-yaml -- --sync-all` keeps the tool list and operation ids in sync. Everything editorial (description, title, `enrich_url`, `exclude_params`) is yours to write.@@ -20,9 +20,11 @@ Tool entries are scaffolded from the OpenAPI schema — `pnpm --filter=@posthog/**Bring-your-own agents** — an agent that trains outside PostHog (for example on a laptop) calls `autoresearch-training-runs-create` to open a run, then the agent-facing tools above except `-materialize-features`, which writes into a PostHog sandbox; it pulls data with `execute-sql` instead. A sandbox request to open a run is refused.-**User-facing** — creating and inspecting pipelines: `autoresearch-resolve-template-create`, `-validate-create`, `-create`, `-train-create`, `-list`, `-retrieve`, `-training-runs-list`, `-suggestions-create`, `-suggestions-list` (to read the agent's response).+**User-facing** — creating and inspecting pipelines: `autoresearch-resolve-template-create`, `-validate-create`, `-create`, `-train-create`, `-score-create`, `-list`, `-retrieve`, `-training-runs-list`, `-suggestions-create`, `-suggestions-list` (to read the agent's response).-Pipeline lifecycle (`archive`, `pause`, `resume`), manual `score`, and the inference-run list stay disabled: the UI covers the lifecycle, the daily workflows score, and nothing agent-driven needs the rest yet. Enabling one is a one-line change here.+`autoresearch-score-create` scores today's prediction date on demand, so an MCP caller does not have to wait for the daily run after a champion is promoted. The training sandbox never sees it, because `TRAINING_MCP_SCOPES` has no `person:write`.++Pipeline lifecycle (`archive`, `pause`, `resume`) and the inference-run list stay disabled: the UI covers the lifecycle, and nothing agent-driven needs the rest yet. Enabling one is a one-line change here.The split matters when you change a description. An agent-facing description is a **contract**: `autoresearch-training-runs-iterations-create` has to tell the agent what a valid `feature_sql` looks like, because the server will reject anything that is not a read-only `SELECT` keyed on `person_id` and the agent has no other way to learn that.diff --git a/products/autoresearch/mcp/tools.yaml b/products/autoresearch/mcp/tools.yamlindex cb20190330c9..4f3b01f1a601 100644--- a/products/autoresearch/mcp/tools.yaml+++ b/products/autoresearch/mcp/tools.yaml@@ -261,7 +261,7 @@ tools:enabled: falseautoresearch-score-create:operation: autoresearch_score_create- enabled: false+ enabled: truescopes:- autoresearch:write- query:read@@ -272,12 +272,16 @@ tools:idempotent: falsetitle: Run inference (score users)description: >- Score the inference population using the champion model and emit 'autoresearch_prediction' events for each- user. Returns the inference run object with rows_scored and status. Requires a champion model and a pipeline- that is not paused — run autoresearch-train-create first if the pipeline has no champion. A pipeline with an- action target also needs the action:read scope. Each scored user gets a '$autoresearch_p_y' property on- their prediction event and a person property update. After scoring, query predictions with execute-sql:- SELECT distinct_id, properties.$autoresearch_p_y FROM events WHERE event = 'autoresearch_prediction' AND+ Score today's prediction date now with the pipeline's champion model, instead of waiting for the daily 02:00+ UTC scoring run. Use it after autoresearch-train-create completes and promotes a champion. The call is+ synchronous and returns the inference run with status and rows_scored. It emits one+ 'autoresearch_prediction' event per scored user, with the score in '$autoresearch_p_y', and sets the+ pipeline's output_person_property on each scored person. A manual score counts as that day's scoring, so the+ daily run skips the pipeline until its next cadence date. Call it once per prediction date: a repeat call+ scores the population again and can duplicate predictions. Returns 400 if the pipeline has no champion (run+ autoresearch-train-create first), is paused, or its target cannot be resolved. A pipeline with an action+ target also needs the action:read scope. After scoring, query predictions with execute-sql: SELECT+ distinct_id, properties.$autoresearch_p_y FROM events WHERE event = 'autoresearch_prediction' ANDproperties.$autoresearch_pipeline_id = '<pipeline_id>' ORDER BY properties.$autoresearch_p_y DESC LIMIT 50.feature_flag: autoresearchautoresearch-suggestions-create:@@ -410,9 +414,10 @@ tools:a training run is already in progress, the pipeline is paused, or its creator or target is no longer valid(recreate the pipeline). Returns 403 from inside a sandbox, such as a PostHog AI cloud task: do not retry,and ask the user to start training from the pipeline's page in PostHog. Needs PostHog Desktop access,- because the run is a cloud sandbox. After a run promotes a champion, the daily scoring job scores the- inference population and emits autoresearch_prediction events. You can optionally override the- iteration_budget for this run. A pipeline with an action target also needs the action:read scope.+ because the run is a cloud sandbox. After a run promotes a champion, the daily 02:00 UTC scoring job scores+ the inference population and emits autoresearch_prediction events. To score now instead, call+ autoresearch-score-create once. You can optionally override the iteration_budget for this run. A pipeline+ with an action target also needs the action:read scope.feature_flag: autoresearchautoresearch-training-runs-artifacts-delete-create:operation: autoresearch_training_runs_artifacts_delete_creatediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 943e18a1d617..1a3381be0dc3 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -1194,6 +1194,21 @@},"feature_flag": "autoresearch"},+ "autoresearch-score-create": {+ "description": "Score today's prediction date now with the pipeline's champion model, instead of waiting for the daily 02:00 UTC scoring run. Use it after autoresearch-train-create completes and promotes a champion. The call is synchronous and returns the inference run with status and rows_scored. It emits one 'autoresearch_prediction' event per scored user, with the score in '$autoresearch_p_y', and sets the pipeline's output_person_property on each scored person. A manual score counts as that day's scoring, so the daily run skips the pipeline until its next cadence date. Call it once per prediction date: a repeat call scores the population again and can duplicate predictions. Returns 400 if the pipeline has no champion (run autoresearch-train-create first), is paused, or its target cannot be resolved. A pipeline with an action target also needs the action:read scope. After scoring, query predictions with execute-sql: SELECT distinct_id, properties.$autoresearch_p_y FROM events WHERE event = 'autoresearch_prediction' AND properties.$autoresearch_pipeline_id = '<pipeline_id>' ORDER BY properties.$autoresearch_p_y DESC LIMIT 50.",+ "category": "Autoresearch",+ "feature": "autoresearch",+ "summary": "Run inference (score users)",+ "title": "Run inference (score users)",+ "required_scopes": ["autoresearch:write", "query:read", "person:write"],+ "annotations": {+ "destructiveHint": true,+ "idempotentHint": false,+ "openWorldHint": true,+ "readOnlyHint": false+ },+ "feature_flag": "autoresearch"+ },"autoresearch-suggestions-create": {"description": "Inject a free-text hypothesis or direction into a running pipeline for the sandbox agent to consider. The agent reads queued suggestions at the start of each training batch and decides whether to translate the suggestion into a concrete iteration ('acted_on'), apply it as a search constraint ('picked_up'), or reject it with rationale ('dismissed'). Use priority='try_next' to instruct the agent to act on this before autonomous iterations; 'consider' (default) is advisory. Check 'agent_response' after the next training run to see how the suggestion was interpreted. Examples: 'try a gradient boosting model', 'remove recency features — I suspect leakage', 'the target event has a 7-day spike on Mondays, account for day-of-week'. Suggestions survive pipeline pauses and are included in the next training batch when the pipeline resumes.","category": "Autoresearch",@@ -1240,7 +1255,7 @@"feature_flag": "autoresearch"},"autoresearch-train-create": {- "description": "Start an asynchronous training run for a pipeline. Launches the autoresearch agent in a sandbox and returns the training run immediately with status 'running'. Poll autoresearch-training-runs-list until the run reaches 'completed' or 'failed'. A pipeline's first run has no champion until it completes and server-side promotion runs; on a retrain the existing champion keeps scoring until a new one is promoted. Returns 400 if a training run is already in progress, the pipeline is paused, or its creator or target is no longer valid (recreate the pipeline). Returns 403 from inside a sandbox, such as a PostHog AI cloud task: do not retry, and ask the user to start training from the pipeline's page in PostHog. Needs PostHog Desktop access, because the run is a cloud sandbox. After a run promotes a champion, the daily scoring job scores the inference population and emits autoresearch_prediction events. You can optionally override the iteration_budget for this run. A pipeline with an action target also needs the action:read scope.",+ "description": "Start an asynchronous training run for a pipeline. Launches the autoresearch agent in a sandbox and returns the training run immediately with status 'running'. Poll autoresearch-training-runs-list until the run reaches 'completed' or 'failed'. A pipeline's first run has no champion until it completes and server-side promotion runs; on a retrain the existing champion keeps scoring until a new one is promoted. Returns 400 if a training run is already in progress, the pipeline is paused, or its creator or target is no longer valid (recreate the pipeline). Returns 403 from inside a sandbox, such as a PostHog AI cloud task: do not retry, and ask the user to start training from the pipeline's page in PostHog. Needs PostHog Desktop access, because the run is a cloud sandbox. After a run promotes a champion, the daily 02:00 UTC scoring job scores the inference population and emits autoresearch_prediction events. To score now instead, call autoresearch-score-create once. You can optionally override the iteration_budget for this run. A pipeline with an action target also needs the action:read scope.","category": "Autoresearch","feature": "autoresearch","summary": "Start training",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex e717754d579e..0ba0202030d5 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -1209,6 +1209,21 @@},"feature_flag": "autoresearch"},+ "autoresearch-score-create": {+ "description": "Score today's prediction date now with the pipeline's champion model, instead of waiting for the daily 02:00 UTC scoring run. Use it after autoresearch-train-create completes and promotes a champion. The call is synchronous and returns the inference run with status and rows_scored. It emits one 'autoresearch_prediction' event per scored user, with the score in '$autoresearch_p_y', and sets the pipeline's output_person_property on each scored person. A manual score counts as that day's scoring, so the daily run skips the pipeline until its next cadence date. Call it once per prediction date: a repeat call scores the population again and can duplicate predictions. Returns 400 if the pipeline has no champion (run autoresearch-train-create first), is paused, or its target cannot be resolved. A pipeline with an action target also needs the action:read scope. After scoring, query predictions with execute-sql: SELECT distinct_id, properties.$autoresearch_p_y FROM events WHERE event = 'autoresearch_prediction' AND properties.$autoresearch_pipeline_id = '<pipeline_id>' ORDER BY properties.$autoresearch_p_y DESC LIMIT 50.",+ "category": "Autoresearch",+ "feature": "autoresearch",+ "summary": "Run inference (score users)",+ "title": "Run inference (score users)",+ "required_scopes": ["autoresearch:write", "query:read", "person:write"],+ "annotations": {+ "destructiveHint": true,+ "idempotentHint": false,+ "openWorldHint": true,+ "readOnlyHint": false+ },+ "feature_flag": "autoresearch"+ },"autoresearch-suggestions-create": {"description": "Inject a free-text hypothesis or direction into a running pipeline for the sandbox agent to consider. The agent reads queued suggestions at the start of each training batch and decides whether to translate the suggestion into a concrete iteration ('acted_on'), apply it as a search constraint ('picked_up'), or reject it with rationale ('dismissed'). Use priority='try_next' to instruct the agent to act on this before autonomous iterations; 'consider' (default) is advisory. Check 'agent_response' after the next training run to see how the suggestion was interpreted. Examples: 'try a gradient boosting model', 'remove recency features — I suspect leakage', 'the target event has a 7-day spike on Mondays, account for day-of-week'. Suggestions survive pipeline pauses and are included in the next training batch when the pipeline resumes.","category": "Autoresearch",@@ -1255,7 +1270,7 @@"feature_flag": "autoresearch"},"autoresearch-train-create": {- "description": "Start an asynchronous training run for a pipeline. Launches the autoresearch agent in a sandbox and returns the training run immediately with status 'running'. Poll autoresearch-training-runs-list until the run reaches 'completed' or 'failed'. A pipeline's first run has no champion until it completes and server-side promotion runs; on a retrain the existing champion keeps scoring until a new one is promoted. Returns 400 if a training run is already in progress, the pipeline is paused, or its creator or target is no longer valid (recreate the pipeline). Returns 403 from inside a sandbox, such as a PostHog AI cloud task: do not retry, and ask the user to start training from the pipeline's page in PostHog. Needs PostHog Desktop access, because the run is a cloud sandbox. After a run promotes a champion, the daily scoring job scores the inference population and emits autoresearch_prediction events. You can optionally override the iteration_budget for this run. A pipeline with an action target also needs the action:read scope.",+ "description": "Start an asynchronous training run for a pipeline. Launches the autoresearch agent in a sandbox and returns the training run immediately with status 'running'. Poll autoresearch-training-runs-list until the run reaches 'completed' or 'failed'. A pipeline's first run has no champion until it completes and server-side promotion runs; on a retrain the existing champion keeps scoring until a new one is promoted. Returns 400 if a training run is already in progress, the pipeline is paused, or its creator or target is no longer valid (recreate the pipeline). Returns 403 from inside a sandbox, such as a PostHog AI cloud task: do not retry, and ask the user to start training from the pipeline's page in PostHog. Needs PostHog Desktop access, because the run is a cloud sandbox. After a run promotes a champion, the daily 02:00 UTC scoring job scores the inference population and emits autoresearch_prediction events. To score now instead, call autoresearch-score-create once. You can optionally override the iteration_budget for this run. A pipeline with an action target also needs the action:read scope.","category": "Autoresearch","feature": "autoresearch","summary": "Start training",diff --git a/services/mcp/src/generated/autoresearch/api.ts b/services/mcp/src/generated/autoresearch/api.tsindex b8d692a498de..b8ecf2b1c8f4 100644--- a/services/mcp/src/generated/autoresearch/api.ts+++ b/services/mcp/src/generated/autoresearch/api.ts@@ -3,7 +3,7 @@* MCP service uses these Zod schemas for generated tool handlers.* To regenerate: hogli build:openapi*- * PostHog API - MCP 20 enabled ops+ * PostHog API - MCP 21 enabled ops* OpenAPI spec version: 1.0.0*/import * as zod from 'zod'@@ -604,6 +604,19 @@ export const AutoresearchRetrieveParams = () => zod.object({),})+/**+ * Score the inference population using the champion model and emit autoresearch_prediction events for each scored user, and sets the pipeline's output_person_property on each scored person. In production this is triggered by the daily Temporal inference workflow.+ * @summary Run inference (score users)+ */+export const AutoresearchScoreCreateParams = () => zod.object({+ id: zod.string().describe('A UUID string identifying this autoresearch pipeline.'),+ project_id: zod+ .string()+ .describe(+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to \/api\/projects\/."+ ),+})+/*** Start an asynchronous training run for this pipeline. Creates a Task/TaskRun sandbox where the autoresearch agent iterates on features and models, and returns the run immediately with status 'running'. Poll the training run until it reaches a terminal status (completed or failed). A pipeline's first run has no champion until it completes and promotion runs; on a retrain the existing champion stays live and keeps scoring until a new one is promoted.* @summary Start a training rundiff --git a/services/mcp/src/tools/generated/autoresearch.ts b/services/mcp/src/tools/generated/autoresearch.tsindex c9f189a9494c..6a0d4628b2c6 100644--- a/services/mcp/src/tools/generated/autoresearch.ts+++ b/services/mcp/src/tools/generated/autoresearch.ts@@ -262,6 +262,27 @@ const autoresearchRetrieve = (): ToolBase<},})+const AutoresearchScoreCreateSchema = () => {+ const AutoresearchScoreCreateParams = orvalSchemas.AutoresearchScoreCreateParams()+ return AutoresearchScoreCreateParams.omit({ project_id: true })+}++const autoresearchScoreCreate = (): ToolBase<+ ReturnType<typeof AutoresearchScoreCreateSchema>,+ Schemas.AutoresearchRun+> => ({+ name: 'autoresearch-score-create',+ schema: AutoresearchScoreCreateSchema(),+ handler: async (context: Context, params: z.infer<ReturnType<typeof AutoresearchScoreCreateSchema>>) => {+ const projectId = await context.stateManager.getProjectId()+ const result = await context.api.request<Schemas.AutoresearchRun>({+ method: 'POST',+ path: `/api/projects/${encodeURIComponent(String(projectId))}/autoresearch/${encodeURIComponent(String(params.id))}/score/`,+ })+ return result+ },+})+const AutoresearchSuggestionsCreateSchema = () => {const AutoresearchSuggestionsCreateBody = orvalSchemas.AutoresearchSuggestionsCreateBody()const AutoresearchSuggestionsCreateParams = orvalSchemas.AutoresearchSuggestionsCreateParams()@@ -767,6 +788,7 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {'autoresearch-models-retrieve': autoresearchModelsRetrieve,'autoresearch-resolve-template-create': autoresearchResolveTemplateCreate,'autoresearch-retrieve': autoresearchRetrieve,+ 'autoresearch-score-create': autoresearchScoreCreate,'autoresearch-suggestions-create': autoresearchSuggestionsCreate,'autoresearch-suggestions-list': autoresearchSuggestionsList,'autoresearch-suggestions-respond': autoresearchSuggestionsRespond,