: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: support agent settings (#69933)
Alex Vd33fc5e0ce1e
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsxindex 681ab6ef8bcf..00413b468cf2 100644--- a/frontend/src/scenes/settings/SettingsMap.tsx+++ b/frontend/src/scenes/settings/SettingsMap.tsx@@ -1137,16 +1137,6 @@ export const SETTINGS_MAP: SettingSection[] = ['browser',],},- {- id: 'conversations-ai',- title: 'AI',- description:- 'Automatically generate AI-powered reply suggestions grounded in your business knowledge sources.',- component: <AISection />,- flag: 'PRODUCT_SUPPORT_AI_SUGGESTION',- allowForTeam: (t) => !!t?.conversations_enabled,- keywords: ['ai', 'suggestion', 'auto', 'reply', 'support', 'conversation'],- },{id: 'conversations-imports',title: 'Imports',@@ -1156,6 +1146,23 @@ export const SETTINGS_MAP: SettingSection[] = [allowForTeam: (t) => !!t?.conversations_enabled,keywords: ['import', 'zendesk', 'migrate', 'ticket', 'support', 'conversation'],},+ {+ id: 'conversations-ai',+ title: (+ <>+ AI agent+ <LemonTag type="highlight" size="small" className="ml-1">+ Beta+ </LemonTag>+ </>+ ),+ description:+ 'Automatically generate AI-powered reply suggestions grounded in your business knowledge sources.',+ component: <AISection />,+ flag: 'PRODUCT_SUPPORT_AI_SUGGESTION',+ allowForTeam: (t) => !!t?.conversations_enabled,+ keywords: ['ai', 'agent', 'suggestion', 'auto', 'reply', 'support', 'conversation', 'beta'],+ },],},{diff --git a/products/conversations/frontend/scenes/settings/AISection.tsx b/products/conversations/frontend/scenes/settings/AISection.tsxindex e85c96f05740..792de9841bea 100644--- a/products/conversations/frontend/scenes/settings/AISection.tsx+++ b/products/conversations/frontend/scenes/settings/AISection.tsx@@ -1,17 +1,20 @@import { useActions, useValues } from 'kea'+import { router } from 'kea-router'import { LemonBanner, LemonCard, LemonCheckbox, LemonSelect, LemonSwitch, Link } from '@posthog/lemon-ui'+import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { settingsLogic } from 'scenes/settings/settingsLogic'import { urls } from 'scenes/urls'import { SceneSection } from '~/layout/scenes/components/SceneSection'-import { FEATURE_FLAGS } from '~/lib/constants'-import { aiTriageTicketTypeLabel } from '../../types'+import { aiTriageTicketTypeLabel, TicketChannel } from '../../types'import { supportSettingsLogic } from './supportSettingsLogic'+import { CONVERSATIONS_LOGIC_KEY } from './SupportSettingsScene'-const CHANNEL_LABELS: Record<string, string> = {+const CHANNEL_LABELS: Record<TicketChannel, string> = {widget: 'API / Widget',slack: 'Slack',email: 'Email',@@ -19,6 +22,14 @@ const CHANNEL_LABELS: Record<string, string> = {github: 'GitHub',}+const CHANNEL_SETTINGS_TABS: Record<TicketChannel, string> = {+ widget: 'widget',+ slack: 'slack',+ email: 'email',+ teams: 'teams',+ github: 'github',+}+const TICKET_TYPES = ['how_to', 'diagnostic', 'account_billing'] as const// Only how_to replies may be sent to the customer. diagnostic/account_billing draw on project@@ -37,6 +48,7 @@ export function AISection(): JSX.Element {aiDiagnosticsEnabled,aiDiagnosticsLoading,aiEnabledChannels,+ aiAllChannels,aiResolutionChannels,aiReplyModes,} = useValues(supportSettingsLogic)@@ -45,125 +57,189 @@ export function AISection(): JSX.Element {const { featureFlags } = useValues(featureFlagLogic)const businessKnowledgeEnabled = !!featureFlags[FEATURE_FLAGS.PRODUCT_BUSINESS_KNOWLEDGE]+ const isChannelActive = (channel: TicketChannel): boolean => aiEnabledChannels.includes(channel)++ const openChannelSettings = (channel: TicketChannel): void => {+ // Switch the embedded settings pane via its own logic — settingsLogic does not+ // sync selectedSetting from /support/settings hash changes.+ settingsLogic({+ logicKey: CONVERSATIONS_LOGIC_KEY,+ sectionId: 'environment-conversations',+ }).actions.selectSetting('conversations-general')+ router.actions.push(urls.supportSettings(), router.values.searchParams, {+ ...router.values.hashParams,+ selectedSetting: 'conversations-general',+ channel: CHANNEL_SETTINGS_TABS[channel],+ })+ }+return (- <SceneSection- title="AI suggestions"- className="my-8"- description="When enabled, PostHog will automatically generate a suggested reply as a private note whenever a new ticket arrives. Suggestions are grounded in your business knowledge sources."- >- <LemonCard hoverEffect={false} className="flex flex-col gap-y-3 max-w-[800px] px-4 py-3">- <LemonSwitch- checked={aiSuggestionsEnabled}- onChange={(checked) => setAiSuggestionsEnabled(checked)}- loading={aiSuggestionsLoading}- label="Allow AI suggestions"- />- <p className="text-xs text-muted-alt mb-0">- Requires AI data processing consent at the organization level and at least one ready business- knowledge source.- </p>- </LemonCard>- {aiSuggestionsEnabled && businessKnowledgeEnabled && (- <LemonBanner type="info" className="max-w-[800px]">- Add your documents, links, and general context to{' '}- <Link to={urls.businessKnowledge()} target="_blank">- Business knowledge- </Link>{' '}- so the AI can ground its replies in your company's information.- </LemonBanner>- )}- {aiSuggestionsEnabled && (+ <>+ <SceneSection+ title="AI agent"+ className="my-8"+ description="When enabled, the AI agent automatically generates reply suggestions as private notes when new tickets arrive. Replies are grounded in your business knowledge sources."+ ><LemonCard hoverEffect={false} className="flex flex-col gap-y-3 max-w-[800px] px-4 py-3">- <LemonSwitch- checked={aiDiagnosticsEnabled}- onChange={(checked) => setAiDiagnosticsEnabled(checked)}- loading={aiDiagnosticsLoading}- disabledReason={!aiSuggestionsEnabled ? 'Enable AI suggestions first' : undefined}- label="Allow the agent to investigate ticket data"- />- <p className="text-xs text-muted-alt mb-0">- When enabled, tickets that report something broken let the agent query your project's data —- events, error tracking, session recordings, and logs — to investigate the issue instead of- relying on documentation alone. The agent has read-only access scoped to your project. Leave- this off to keep suggestions grounded only in documentation and your business knowledge.- </p>- </LemonCard>- )}- {aiSuggestionsEnabled && aiEnabledChannels.length > 0 && (- <LemonCard hoverEffect={false} className="flex flex-col gap-y-3 max-w-[800px] px-4 py-3">- <h4 className="font-semibold text-sm mb-0">Allowed channels</h4>- <p className="text-xs text-muted-alt mb-0">- Choose which channels the AI resolution pipeline runs on. Unchecked channels will not receive AI- suggestions.- </p>- <div className="flex flex-col gap-y-2">- {aiEnabledChannels.map((channel) => (- <LemonCheckbox- key={channel}- checked={aiResolutionChannels.includes(channel)}- onChange={(checked) => {- const next = checked- ? [...aiResolutionChannels, channel]- : aiResolutionChannels.filter((c) => c !== channel)- setAiResolutionChannels(next)- }}- label={CHANNEL_LABELS[channel] ?? channel}- />- ))}+ <div className="flex items-center gap-4 justify-between">+ <div>+ <label className="font-medium">Enable AI agent</label>+ <p className="text-xs text-muted-alt mb-0">+ Requires AI data processing consent at the organization level and at least one ready+ business knowledge source.+ </p>+ </div>+ <LemonSwitch+ checked={aiSuggestionsEnabled}+ onChange={(checked) => setAiSuggestionsEnabled(checked)}+ loading={aiSuggestionsLoading}+ /></div></LemonCard>+ {aiSuggestionsEnabled && businessKnowledgeEnabled && (+ <LemonBanner type="info" className="max-w-[800px] mt-3">+ Add your documents, links, and general context to{' '}+ <Link to={urls.businessKnowledge()} target="_blank">+ Business knowledge+ </Link>{' '}+ so the AI can ground its replies in your company's information.+ </LemonBanner>+ )}+ </SceneSection>++ {aiSuggestionsEnabled && (+ <SceneSection+ title="Investigate ticket data"+ titleSize="sm"+ className="my-8"+ description="When enabled, tickets that report something broken let the agent query your project's data — events, error tracking, session recordings, and logs — to investigate the issue instead of relying on documentation alone. The agent has read-only access scoped to your project."+ >+ <LemonCard hoverEffect={false} className="flex flex-col gap-y-3 max-w-[800px] px-4 py-3">+ <div className="flex items-center gap-4 justify-between">+ <div>+ <label className="font-medium">Allow the agent to investigate ticket data</label>+ <p className="text-xs text-muted-alt mb-0">+ Leave this off to keep the agent grounded only in documentation and your business+ knowledge.+ </p>+ </div>+ <LemonSwitch+ checked={aiDiagnosticsEnabled}+ onChange={(checked) => setAiDiagnosticsEnabled(checked)}+ loading={aiDiagnosticsLoading}+ />+ </div>+ </LemonCard>+ </SceneSection>+ )}++ {aiSuggestionsEnabled && (+ <SceneSection+ title="Allowed channels"+ titleSize="sm"+ className="my-8"+ description="Choose which channels the AI agent runs on. Inactive channels must be enabled under Channels first."+ >+ <LemonCard hoverEffect={false} className="flex flex-col gap-y-2 max-w-[800px] px-4 py-3">+ {aiAllChannels.map((channel) => {+ const active = isChannelActive(channel)+ return (+ <LemonCheckbox+ key={channel}+ checked={active && aiResolutionChannels.includes(channel)}+ disabledReason={+ active ? undefined : 'Enable this channel in Channels settings first'+ }+ onChange={(checked) => {+ const next = checked+ ? [...aiResolutionChannels, channel]+ : aiResolutionChannels.filter((c) => c !== channel)+ setAiResolutionChannels(next)+ }}+ label={+ <span className="inline-flex flex-wrap items-center gap-x-1">+ {CHANNEL_LABELS[channel]}+ {!active && (+ <>+ <span className="text-muted-alt">·</span>+ <Link+ onClick={(e) => {+ e.preventDefault()+ openChannelSettings(channel)+ }}+ to={urls.supportSettings()}+ >+ Enable in Channels first+ </Link>+ </>+ )}+ </span>+ }+ />+ )+ })}+ </LemonCard>+ </SceneSection>)}{aiSuggestionsEnabled && aiResolutionChannels.length > 0 && (- <LemonCard hoverEffect={false} className="flex flex-col gap-y-3 max-w-[800px] px-4 py-3">- <h4 className="font-semibold text-sm mb-0">Reply behavior</h4>- <p className="text-xs text-muted-alt mb-0">- For each channel and ticket type, choose whether the AI posts a private note (visible only to- your team) or sends a safety-reviewed reply directly to the customer.- </p>- <p className="text-xs text-muted-alt mb-0">- <strong>Diagnostic and Account/Billing</strong> replies may include data from your project, so- they're always kept as private notes and can't be sent directly to the customer.- </p>- <div className="overflow-x-auto">- <table className="w-full text-xs">- <thead>- <tr>- <th className="text-left py-1 pr-3 font-medium text-muted-alt">Channel</th>- {TICKET_TYPES.map((tt) => (- <th key={tt} className="text-left py-1 px-2 font-medium text-muted-alt">- {aiTriageTicketTypeLabel[tt]}- </th>- ))}- </tr>- </thead>- <tbody>- {aiResolutionChannels.map((channel) => (- <tr key={channel} className="border-t border-border">- <td className="py-2 pr-3 font-medium">{CHANNEL_LABELS[channel] ?? channel}</td>- {TICKET_TYPES.map((tt) =>- PUBLISHABLE_TICKET_TYPES.has(tt) ? (- <td key={tt} className="py-2 px-2">- <LemonSelect- size="xsmall"- options={REPLY_MODE_OPTIONS}- value={aiReplyModes[channel]?.[tt] ?? 'private_note'}- onChange={(value) => setAiReplyMode(channel, tt, value)}- />- </td>- ) : (- <td key={tt} className="py-2 px-2 text-muted-alt">- Private note- </td>- )- )}+ <SceneSection+ title="Reply behavior"+ titleSize="sm"+ className="my-8"+ description={+ <>+ For each channel and ticket type, choose whether the AI agent posts a private note (visible+ only to your team) or sends a safety-reviewed reply directly to the customer.{' '}+ <strong>Diagnostic</strong> and <strong>Account/Billing</strong> replies may include data+ from your project, so they're always kept as private notes and can't be sent directly to the+ customer.+ </>+ }+ >+ <LemonCard hoverEffect={false} className="max-w-[800px] px-4 py-3">+ <div className="overflow-x-auto">+ <table className="w-full text-xs">+ <thead>+ <tr>+ <th className="text-left py-1 pr-3 font-medium text-muted-alt">Channel</th>+ {TICKET_TYPES.map((tt) => (+ <th key={tt} className="text-left py-1 px-2 font-medium text-muted-alt">+ {aiTriageTicketTypeLabel[tt]}+ </th>+ ))}</tr>- ))}- </tbody>- </table>- </div>- </LemonCard>+ </thead>+ <tbody>+ {aiResolutionChannels.map((channel) => (+ <tr key={channel} className="border-t border-border">+ <td className="py-2 pr-3 font-medium">+ {CHANNEL_LABELS[channel] ?? channel}+ </td>+ {TICKET_TYPES.map((tt) =>+ PUBLISHABLE_TICKET_TYPES.has(tt) ? (+ <td key={tt} className="py-2 px-2">+ <LemonSelect+ size="xsmall"+ options={REPLY_MODE_OPTIONS}+ value={aiReplyModes[channel]?.[tt] ?? 'private_note'}+ onChange={(value) => setAiReplyMode(channel, tt, value)}+ />+ </td>+ ) : (+ <td key={tt} className="py-2 px-2 text-muted-alt">+ Private note+ </td>+ )+ )}+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ </LemonCard>+ </SceneSection>)}- </SceneSection>+ </>)}diff --git a/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts b/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.tsindex 6157271623c0..e272b4037d72 100644--- a/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts+++ b/products/conversations/frontend/scenes/settings/supportSettingsLogic.test.ts@@ -1,11 +1,14 @@import { expectLogic } from 'kea-test-utils'+import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { useMocks } from '~/mocks/jest'import { teamLogic } from '~/scenes/teamLogic'import { initKeaTests } from '~/test/init'import { TeamType } from '~/types'-import { supportSettingsLogic } from './supportSettingsLogic'+import { aiAllChannelsForFeatureFlags, supportSettingsLogic } from './supportSettingsLogic'describe('supportSettingsLogic', () => {let logic: ReturnType<typeof supportSettingsLogic.build>@@ -29,6 +32,43 @@ describe('supportSettingsLogic', () => {logic?.unmount()})+ describe('aiAllChannelsForFeatureFlags', () => {+ it.each([+ ['no flags enabled', {}, ['widget', 'email', 'slack']],+ [+ 'teams and github enabled',+ {+ [FEATURE_FLAGS.PRODUCT_SUPPORT_TEAMS_ENABLED]: true,+ [FEATURE_FLAGS.PRODUCT_SUPPORT_GITHUB_CHANNEL]: true,+ },+ ['widget', 'email', 'slack', 'teams', 'github'],+ ],+ ])('%s', (_label, flags, expected) => {+ expect(aiAllChannelsForFeatureFlags(flags)).toEqual(expected)+ })+ })++ describe('aiResolutionChannels selector', () => {+ it('drops flag-gated channels that are no longer available', async () => {+ initKeaTests(true, {+ conversations_settings: {+ slack_enabled: true,+ teams_enabled: true,+ ai_resolution_channels: ['widget', 'slack', 'teams'],+ },+ } as unknown as TeamType)+ featureFlagLogic.mount()++ logic = supportSettingsLogic()+ logic.mount()++ await expectLogic(logic).toMatchValues({+ aiAllChannels: ['widget', 'email', 'slack'],+ aiResolutionChannels: ['widget', 'slack'],+ })+ })+ })+describe('aiSuggestionsEnabled selector', () => {it.each([['conversations_settings is undefined', undefined, false],diff --git a/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts b/products/conversations/frontend/scenes/settings/supportSettingsLogic.tsindex 187569ce19a8..d456dd11c009 100644--- a/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts+++ b/products/conversations/frontend/scenes/settings/supportSettingsLogic.ts@@ -2,13 +2,29 @@ import { actions, afterMount, connect, kea, listeners, path, reducers, selectorsimport { loaders } from 'kea-loaders'import api from 'lib/api'+import { FEATURE_FLAGS } from 'lib/constants'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { teamLogic } from 'scenes/teamLogic'import { SlackChannelType, UserBasicType } from '~/types'+import { TicketChannel } from '../../types'import type { supportSettingsLogicType } from './supportSettingsLogicType'+const BASE_AI_CHANNELS: TicketChannel[] = ['widget', 'email', 'slack']++export function aiAllChannelsForFeatureFlags(featureFlags: Record<string, boolean | string>): TicketChannel[] {+ const channels: TicketChannel[] = [...BASE_AI_CHANNELS]+ if (featureFlags[FEATURE_FLAGS.PRODUCT_SUPPORT_TEAMS_ENABLED]) {+ channels.push('teams')+ }+ if (featureFlags[FEATURE_FLAGS.PRODUCT_SUPPORT_GITHUB_CHANNEL]) {+ channels.push('github')+ }+ return channels+}+export interface EmailConfigStatus {id: stringfrom_email: string@@ -22,7 +38,7 @@ export interface EmailConfigStatus {export const supportSettingsLogic = kea<supportSettingsLogicType>([path(['products', 'conversations', 'frontend', 'scenes', 'settings', 'supportSettingsLogic']),connect(() => ({- values: [teamLogic, ['currentTeam', 'currentTeamLoading']],+ values: [teamLogic, ['currentTeam', 'currentTeamLoading'], featureFlagLogic, ['featureFlags']],actions: [teamLogic,['updateCurrentTeam', 'updateCurrentTeamSuccess', 'updateCurrentTeamFailure', 'loadCurrentTeam'],@@ -111,7 +127,7 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([setAiSuggestionsLoading: (loading: boolean) => ({ loading }),setAiDiagnosticsEnabled: (enabled: boolean) => ({ enabled }),setAiDiagnosticsLoading: (loading: boolean) => ({ loading }),- setAiResolutionChannels: (channels: string[]) => ({ channels }),+ setAiResolutionChannels: (channels: TicketChannel[]) => ({ channels }),setAiReplyMode: (channel: string, ticketType: string, mode: 'private_note' | 'bot_reply') => ({channel,ticketType,@@ -520,12 +536,12 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([],aiEnabledChannels: [(s) => [s.currentTeam, s.emailConfigs],- (currentTeam, emailConfigs): string[] => {+ (currentTeam, emailConfigs): TicketChannel[] => {const cs = currentTeam?.conversations_settingsif (!cs) {return []}- const channels: string[] = []+ const channels: TicketChannel[] = []channels.push('widget')if (cs.slack_enabled) {channels.push('slack')@@ -542,14 +558,21 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([return channels},],+ aiAllChannels: [+ (s) => [s.featureFlags],+ (featureFlags): TicketChannel[] => aiAllChannelsForFeatureFlags(featureFlags),+ ],aiResolutionChannels: [- (s) => [s.currentTeam, s.aiEnabledChannels],- (currentTeam, aiEnabledChannels): string[] => {+ (s) => [s.currentTeam, s.aiEnabledChannels, s.aiAllChannels],+ (currentTeam, aiEnabledChannels, aiAllChannels): TicketChannel[] => {+ const allowed = aiEnabledChannels.filter((channel) => aiAllChannels.includes(channel))const stored = currentTeam?.conversations_settings?.ai_resolution_channelsif (Array.isArray(stored)) {- return stored.filter((ch: string) => aiEnabledChannels.includes(ch))+ return stored.filter((channel: string): channel is TicketChannel =>+ allowed.includes(channel as TicketChannel)+ )}- return aiEnabledChannels+ return allowed},],aiReplyModes: [@@ -957,10 +980,11 @@ export const supportSettingsLogic = kea<supportSettingsLogicType>([})},setAiResolutionChannels: ({ channels }) => {+ const allowed = new Set(values.aiAllChannels)actions.updateCurrentTeam({conversations_settings: {...values.currentTeam?.conversations_settings,- ai_resolution_channels: channels,+ ai_resolution_channels: channels.filter((channel) => allowed.has(channel)),},})},