1"""Stage 1 of the taxonomy: turn each session's opening tool calls into a facet.23Reads the pipe-delimited corpus dumped from HogQL, asks gpt-4.1-mini to recover4the user's starting intention, and writes JSONL. Clustering happens downstream.56Model choice matches `products/mcp_analytics/backend/intent_generation.py`,7which already uses gpt-4.1-mini for the closest existing job (summarizing a8session's intents), so the two stay comparable.910PostHog employees only: the key comes from the repo's .env.local, which holds111Password references rather than literal secrets.1213CONSENT: the `opening` column is customer-authored intent text, and this script14sends it to a third-party model. PostHog's backend gates the same class of text15on `organization.is_ai_data_processing_approved` (see intent_generation.py and
42SYSTEM = """You are analyzing telemetry from PostHog's MCP server: sequences of tool calls an AI agent made on a user's behalf. Each session ended with the agent calling {tool}.
43
44Recover the USER'S STARTING POINT — what the person set out to accomplish when the session began. This is upstream of the tool call: reaching {tool} is usually where the work landed, not the goal itself.
45
46Rules:
47- `goal` is a short imperative phrase, 3-8 words, describing the starting task in general terms. Examples of the right altitude: "investigate an error spike", "build a weekly metrics report", "analyze a conversion funnel drop", "audit feature flag usage".
48- Generalize hard. Two sessions doing the same kind of work must produce the SAME goal string, character for character. Strip anything specific to one user.
49- NEVER include a customer, company, project, product, person, or app name in any field. These appear constantly in the input; drop them. Write "a mobile app", not the app's name.
50- `data_touched` is true if the session queried analytics data (SQL, insights, events, warehouse) before reaching the tool, false if it only read or wrote configuration.
51- `{facet}` is one of: {values}. Pick the closest; use the last value when the opening calls do not say."""