: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(signals): attach scout configuration id to posthog ai (#125687)
Georgiy Tarasovd55e0d0f0dd7
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutAskAiComposer.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutAskAiComposer.tsxindex d366a7cbefc7..ad1618a8e5cb 100644--- a/products/signals/frontend/inbox/components/config/scouts/ScoutAskAiComposer.tsx+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutAskAiComposer.tsx@@ -8,7 +8,15 @@ import { captureScoutAction } from '../../../inboxAnalytics'import { SCOUT_AI_STARTER_QUESTIONS, scoutAiLogic } from '../../../logics/scoutAiLogic'/** A one-line question box under the scout header. The answer runs in the PostHog AI side panel. */-export function ScoutAskAiComposer({ skillName, scoutName }: { skillName: string; scoutName: string }): JSX.Element {+export function ScoutAskAiComposer({+ scoutId,+ skillName,+ scoutName,+}: {+ scoutId: string+ skillName: string+ scoutName: string+}): JSX.Element {const { isAsking, aiConsentDisabledReason } = useValues(scoutAiLogic)const { askScout } = useActions(scoutAiLogic)const [draft, setDraft] = useState('')@@ -29,7 +37,7 @@ export function ScoutAskAiComposer({ skillName, scoutName }: { skillName: stringskillName,extra: { source: starterId ? 'starter' : 'typed', starter_id: starterId },})- askScout({ skillName, scoutName }, draft)+ askScout({ scoutId, skillName, scoutName }, draft)setDraft('')setStarterId(null)}diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutDetailView.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutDetailView.tsxindex 4e6587268b30..b05fe82d7d5e 100644--- a/products/signals/frontend/inbox/components/config/scouts/ScoutDetailView.tsx+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutDetailView.tsx@@ -74,7 +74,7 @@ export function ScoutDetailView({ skillName }: { skillName: string }): JSX.Eleme// Registered by the page as well as the AI panel, so the scout is already attached when the// panel composer mounts and sends the question at once. Any PostHog AI chat opened here gets it.- useAttachedContext(scoutName ? scoutAiContextItems({ skillName, scoutName }) : null)+ useAttachedContext(config && scoutName ? scoutAiContextItems({ scoutId: config.id, skillName, scoutName }) : null)// Once per scout opened, as soon as its config resolves — the run rollup fills in a beat later// off the polled window, so the counts are whatever had loaded by then.@@ -201,7 +201,7 @@ export function ScoutDetailView({ skillName }: { skillName: string }): JSX.Elemereturn (<div className="@container flex min-h-0 flex-1 flex-col overflow-auto"><ScoutDetailHeader config={config} rollup={rollup} noteCount={toldCount} learnedCount={learnedCount} />- <ScoutAskAiComposer skillName={skillName} scoutName={scoutDisplayName(config)} />+ <ScoutAskAiComposer scoutId={config.id} skillName={skillName} scoutName={scoutDisplayName(config)} /><div className="flex min-w-0 flex-col gap-4 px-4 py-4"><ScoutAttentionBanner config={config} />diff --git a/products/signals/frontend/inbox/logics/scoutAiLogic.test.ts b/products/signals/frontend/inbox/logics/scoutAiLogic.test.tsindex 3542fe300d4e..1edc1eeeeb51 100644--- a/products/signals/frontend/inbox/logics/scoutAiLogic.test.ts+++ b/products/signals/frontend/inbox/logics/scoutAiLogic.test.ts@@ -9,19 +9,22 @@ import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { SidePanelTab } from '~/types'+import { attachedContextLogic } from 'products/posthog_ai/frontend/api/logics'import { taskTrackerSceneLogic } from 'products/posthog_ai/frontend/scenes/TaskTracker/taskTrackerSceneLogic'-import { SCOUT_AI_PANEL, scoutAiLogic } from './scoutAiLogic'+import { SCOUT_AI_PANEL, scoutAiContextItems, scoutAiLogic } from './scoutAiLogic'describe('scoutAiLogic', () => {let logic: ReturnType<typeof scoutAiLogic.build>let trackerLogic: ReturnType<typeof taskTrackerSceneLogic.build>let seedBridgeLogic: ReturnType<typeof phaiSidePanelComposerSeedLogic.build>let createdDescriptions: string[]+ let startedMessages: string[]let approved: booleanbeforeEach(() => {createdDescriptions = []+ startedMessages = []approved = trueuseMocks({get: {@@ -39,7 +42,11 @@ describe('scoutAiLogic', () => {createdDescriptions.push(body.description)return [200, { id: 'new-task', ...body }]},- '/api/projects/:team/tasks/:id/run/': () => [200, { id: 'new-task', latest_run: { id: 'run-1' } }],+ '/api/projects/:team/tasks/:id/run/': async ({ request }) => {+ const body = (await request.json()) as Record<string, any>+ startedMessages.push(body.pending_user_message)+ return [200, { id: 'new-task', latest_run: { id: 'run-1' } }]+ },},})})@@ -70,13 +77,19 @@ describe('scoutAiLogic', () => {it('sends the question once and opens the scout panel', async () => {mountWithOpenPanel(true)- logic.actions.askScout({ skillName: 'checkout-watcher', scoutName: 'Checkout watcher' }, ' Are you working? ')+ const context = { scoutId: 'scout-config-1', skillName: 'checkout-watcher', scoutName: 'Checkout watcher' }+ attachedContextLogic.actions.registerContext('scout-page', scoutAiContextItems(context))+ logic.actions.askScout(context, ' Are you working? ')await expectLogic(trackerLogic).toFinishAllListeners()expect(createdDescriptions).toHaveLength(1)expect(createdDescriptions[0]).toContain('Are you working?')+ expect(startedMessages).toHaveLength(1)+ expect(startedMessages[0]).toContain('inbox_scout scout-config-1')+ expect(startedMessages[0]).not.toContain('checkout-watcher')+ expect(startedMessages[0]).not.toContain('Checkout watcher')expect(sidePanelStateLogic.values.selectedTabOptions).toBe(SCOUT_AI_PANEL)- expect(logic.values.scoutChatContext).toEqual({ skillName: 'checkout-watcher', scoutName: 'Checkout watcher' })+ expect(logic.values.scoutChatContext).toEqual(context)// The panel option must not land in the composer as a second prompt.expect(trackerLogic.values.newTaskData.description).toBe('')})@@ -84,7 +97,10 @@ describe('scoutAiLogic', () => {it('sends nothing without AI data processing consent', async () => {mountWithOpenPanel(false)- logic.actions.askScout({ skillName: 'checkout-watcher', scoutName: 'Checkout watcher' }, 'Are you working?')+ logic.actions.askScout(+ { scoutId: 'scout-config-1', skillName: 'checkout-watcher', scoutName: 'Checkout watcher' },+ 'Are you working?'+ )await expectLogic(trackerLogic).toFinishAllListeners()expect(createdDescriptions).toHaveLength(0)diff --git a/products/signals/frontend/inbox/logics/scoutAiLogic.ts b/products/signals/frontend/inbox/logics/scoutAiLogic.tsindex defefd8a971f..2be543453102 100644--- a/products/signals/frontend/inbox/logics/scoutAiLogic.ts+++ b/products/signals/frontend/inbox/logics/scoutAiLogic.ts@@ -21,6 +21,7 @@ export const SCOUT_AI_PANEL = 'inbox-scout'export const SCOUT_NOTE_CREATE_TOOL = 'scout-notes-create'export interface ScoutChatContext {+ scoutId: stringskillName: stringscoutName: string}@@ -33,9 +34,10 @@ export const SCOUT_AI_STARTER_QUESTIONS: { id: string; question: string }[] = []// Our own static string, which is what makes it safe as a trusted `instructions` item. The scout's-// name and skill_name ride in the untrusted `signal_scout` item instead.+// configuration ID rides in the untrusted `inbox_scout` item instead.const SCOUT_AI_INSTRUCTIONS = [- 'The user is looking at one PostHog Signals scout: the `signal_scout` context item, keyed by its `skill_name`. Answer about that scout without asking which one.',+ 'The user is looking at one Self-driving scout: the `inbox_scout` context item, keyed by its configuration ID. Answer about that scout without asking which one.',+ 'Use `scout-config-list` to find the configuration with that ID and read its `skill_name`. Use that skill name to retrieve its skill body, scratchpad entries, notes, and runs.','Load the `exploring-scouts` skill before your first tool call. Load `authoring-scouts` too when the user wants to change the scout.',"Before you answer, read the scout's skill body, its scratchpad entries, its notes, and its recent runs with the scout MCP tools.",'Answer in the first person, as the scout (for example, "I ran 4 times this week").',@@ -44,9 +46,9 @@ const SCOUT_AI_INSTRUCTIONS = ["Do not change the scout's skill or settings unless the user asks for that change.",].join(' ')-export function scoutAiContextItems({ skillName, scoutName }: ScoutChatContext): AttachedContextItem[] {+export function scoutAiContextItems({ scoutId }: ScoutChatContext): AttachedContextItem[] {return [- { type: 'signal_scout', key: skillName, label: `Scout: ${scoutName}`, dismissible: false },+ { type: 'inbox_scout', key: scoutId, label: 'Self-driving scout', dismissible: false },{ type: 'instructions', value: SCOUT_AI_INSTRUCTIONS, hidden: true },]}