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(aio): conversation-only toggle and collapsible long messages (#94556)

Marco Gancitano9b84f2099818
diff --git a/products/ai_observability/frontend/AIObservabilitySessionScene.tsx b/products/ai_observability/frontend/AIObservabilitySessionScene.tsx
index 65ce4f44429c..05e7919ab4b6 100644
--- a/products/ai_observability/frontend/AIObservabilitySessionScene.tsx
+++ b/products/ai_observability/frontend/AIObservabilitySessionScene.tsx
@@ -3,7 +3,7 @@ import { combineUrl, router } from 'kea-router'
import { type Ref, Suspense, useEffect, useRef } from 'react'
import { IconWarning, IconWrench } from '@posthog/icons'
-import { LemonButton, LemonDrawer, LemonTag, Spinner, SpinnerOverlay, Tooltip } from '@posthog/lemon-ui'
+import { LemonButton, LemonDrawer, LemonSwitch, LemonTag, Spinner, SpinnerOverlay, Tooltip } from '@posthog/lemon-ui'
import { AccessControlAction } from 'lib/components/AccessControlAction'
import { TZLabel } from 'lib/components/TZLabel'
@@ -110,7 +110,8 @@ function SessionSceneWrapper({ showBreadcrumb = false }: { showBreadcrumb?: bool
loadingFullTraces,
expandedGenerationIds,
} = useValues(aiObservabilitySessionDataLogic)
- const { sessionId, dateRange } = useValues(aiObservabilitySessionLogic)
+ const { sessionId, dateRange, conversationOnly } = useValues(aiObservabilitySessionLogic)
+ const { setConversationOnly } = useActions(aiObservabilitySessionLogic)
const { summarizeAllTraces, loadNextData, closeStepsDrawer, toggleGenerationExpanded, focusGenerationExpanded } =
useActions(aiObservabilitySessionDataLogic)
const { dataProcessingAccepted } = useValues(maxGlobalLogic)
@@ -241,11 +242,21 @@ function SessionSceneWrapper({ showBreadcrumb = false }: { showBreadcrumb?: bool
<LLMASessionEvaluationsDisplay sessionId={sessionId} />
</Suspense>
</div>
- <SummarizeAllButton
- loading={summariesLoading}
- dataProcessingAccepted={dataProcessingAccepted}
- onSummarize={summarizeAllTraces}
- />
+ <div className="flex items-center gap-3">
+ <LemonSwitch
+ size="small"
+ checked={conversationOnly}
+ onChange={setConversationOnly}
+ label="Conversation only"
+ tooltip="Hide tool calls and internal messages to see the chat as the user saw it"
+ data-attr="llm-session-conversation-only"
+ />
+ <SummarizeAllButton
+ loading={summariesLoading}
+ dataProcessingAccepted={dataProcessingAccepted}
+ onSummarize={summarizeAllTraces}
+ />
+ </div>
</header>
<div className="flex flex-col flex-1">
@@ -359,10 +370,10 @@ function SummarizeAllButton({
type="primary"
size="small"
loading={loading}
- disabledReason="AI data processing must be approved to summarize traces"
+ disabledReason="AI data processing must be approved to summarize the session"
data-attr="llm-session-summarize-all"
>
- Summarize all traces
+ Summarize session
</LemonButton>
</AccessControlAction>
</AIConsentPopoverWrapper>
@@ -380,7 +391,7 @@ function SummarizeAllButton({
loading={loading}
data-attr="llm-session-summarize-all"
>
- Summarize all traces
+ Summarize session
</LemonButton>
</AccessControlAction>
)
@@ -398,11 +409,12 @@ function SessionTurnView({
showSentiment: boolean
traceSearchParams: Record<string, unknown>
rootRef?: Ref<HTMLDivElement>
-}): JSX.Element {
+}): JSX.Element | null {
const { traceSummaries, loadingFullTraces, fullTraces, expandedGenerationIds } = useValues(
aiObservabilitySessionDataLogic
)
const { openStepsDrawer, toggleGenerationExpanded, loadFullTrace } = useActions(aiObservabilitySessionDataLogic)
+ const { conversationOnly } = useValues(aiObservabilitySessionLogic)
const trace = turn.trace
const summary: TraceSummary | undefined = traceSummaries[trace.id]
@@ -418,7 +430,7 @@ function SessionTurnView({
).length
// Errors already surfaced by a red tool pill are excluded; the rest (e.g.
// generation failures) render as their own pills in the same style.
- const otherErrors = turn.errors.filter((e) => !turn.tools.includes(e.label))
+ const otherErrors = conversationOnly ? turn.errors : turn.errors.filter((e) => !turn.tools.includes(e.label))
const hasTranscript = turn.isLoaded && !!turn.userVisibleTurn
// Span-only turns have no transcript, so the span tree IS the conversation.
@@ -426,6 +438,11 @@ function SessionTurnView({
// Only a settled turn shows its summary, tools, errors, steps, and sidebar.
const isComplete = phase === 'complete'
+ // Span-only turns are invisible to the end user; keep only the ones that failed.
+ if (conversationOnly && isSpanOnly && turn.errors.length === 0) {
+ return null
+ }
+
return (
<div className="flex flex-col" ref={rootRef}>
<div className="flex items-center gap-3 py-3 text-xs text-muted">
@@ -442,10 +459,11 @@ function SessionTurnView({
phase={phase}
isLoading={isLoading}
sentiment={isComplete && showSentiment ? trace.sentiment : undefined}
+ hideInternal={conversationOnly}
onLoad={() => loadFullTrace(trace.id)}
/>
- {isComplete && turn.tools.length > 0 && (
+ {isComplete && !conversationOnly && turn.tools.length > 0 && (
<div className="flex items-center gap-1.5 flex-wrap text-xs text-muted">
{turn.tools.map((name) => {
// Tool spans and error labels both come from `$ai_span_name`,
@@ -492,7 +510,7 @@ function SessionTurnView({
</div>
)}
- {isComplete && hasTranscript && (
+ {isComplete && hasTranscript && !conversationOnly && (
<div>
<LemonButton
size="xsmall"
@@ -505,7 +523,7 @@ function SessionTurnView({
</div>
)}
- {isComplete && isSpanOnly && (
+ {isComplete && isSpanOnly && !conversationOnly && (
<StepsPanel
fullTrace={fullTrace}
expandedEventIds={expandedGenerationIds}
@@ -546,12 +564,14 @@ function TurnBody({
phase = 'complete',
isLoading,
sentiment,
+ hideInternal,
onLoad,
}: {
turn: SessionTurn
phase?: TurnPhase
isLoading: boolean
sentiment?: LLMTrace['sentiment']
+ hideInternal: boolean
onLoad: () => void
}): JSX.Element | null {
if (isLoading) {
@@ -583,7 +603,7 @@ function TurnBody({
if (phase === 'aiThinking') {
return (
<div className="flex flex-col gap-1.5">
- <TranscriptBubbleStream inputs={turn.newInputs} outputs={[]} />
+ <TranscriptBubbleStream inputs={turn.newInputs} outputs={[]} hideInternal={hideInternal} />
<TypingIndicator />
</div>
)
@@ -591,9 +611,9 @@ function TurnBody({
// `turn.newInputs` / `outputs` come pre-deduped from `extractSessionTurns`.
return (
<div className="flex flex-col gap-1.5">
- <TranscriptBubbleStream inputs={turn.newInputs} outputs={[]} />
+ <TranscriptBubbleStream inputs={turn.newInputs} outputs={[]} hideInternal={hideInternal} />
{turn.newInputs.length > 0 && <SessionTraceSentimentBar sentiment={sentiment} />}
- <TranscriptBubbleStream inputs={[]} outputs={turn.outputs} />
+ <TranscriptBubbleStream inputs={[]} outputs={turn.outputs} hideInternal={hideInternal} />
</div>
)
}
diff --git a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx
index 31c248e74305..e42da960b333 100644
--- a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx
+++ b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx
@@ -2,6 +2,7 @@ import posthog from 'posthog-js'
import { useEffect, useMemo, useRef, useState } from 'react'
import { IconChevronRight } from '@posthog/icons'
+import { LemonButton } from '@posthog/lemon-ui'
import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
@@ -27,6 +28,9 @@ import {
// one click away via "Show steps".
const HIDDEN_ROLES = new Set<string>(['system', AVAILABLE_TOOLS_ROLE])
+// Unknown roles like `developer` pass through the normalizer unchanged.
+const CONVERSATION_ROLES = new Set<string>(['user', 'assistant'])
+
function isUnrenderableContentItem(item: unknown): boolean {
return extractTextContent(item) === undefined && !isToolStepItem(item)
}
@@ -315,15 +319,27 @@ export function buildStreamItems(messages: CompatMessage[]): StreamItem[] {
export function TranscriptBubbleStream({
inputs,
outputs,
+ hideInternal = false,
}: {
inputs: CompatMessage[]
outputs: CompatMessage[]
+ hideInternal?: boolean
}): JSX.Element | null {
- const items = useMemo(() => buildStreamItems([...inputs, ...outputs]), [inputs, outputs])
+ // Keys come from the unfiltered index so toggling `hideInternal` does not hand one
+ // bubble's expanded state to its neighbor.
+ const items = useMemo(
+ () =>
+ buildStreamItems([...inputs, ...outputs])
+ .map((item, key) => ({ item, key }))
+ .filter(
+ ({ item }) => !hideInternal || (item.kind === 'bubble' && CONVERSATION_ROLES.has(item.message.role))
+ ),
+ [inputs, outputs, hideInternal]
+ )
const capturedRef = useRef<Set<string>>(new Set())
useEffect(() => {
- for (const item of items) {
+ for (const { item } of items) {
if (item.kind === 'bubble' && item.nonText) {
captureUnrenderableMessageOnce(item.message, capturedRef.current)
}
@@ -336,31 +352,62 @@ export function TranscriptBubbleStream({
return (
<div className="flex flex-col gap-1.5">
- {items.map((item, i) =>
+ {items.map(({ item, key }) =>
item.kind === 'bubble' ? (
<MessageTemplate
- key={i}
+ key={key}
type={item.message.role === 'user' ? 'human' : 'ai'}
wrapperClassName="max-w-[75%]"
// Same user-message fill the Trace page uses, so the two sides don't blend together
boxClassName={item.message.role === 'user' ? 'bg-fill-tertiary' : undefined}
>
- {item.text && (
- // Trace content is untrusted, so external images must not auto-load.
- <LemonMarkdown className="whitespace-pre-wrap break-words" disableImages>
- {item.text}
- </LemonMarkdown>
- )}
+ {item.text && <CollapsibleBubbleText text={item.text} />}
{item.nonText && <div className="italic text-muted text-xs mt-1">(has attachments)</div>}
</MessageTemplate>
) : (
- <InternalGroupPill key={i} messages={item.messages} labels={item.labels} role={item.role} />
+ <InternalGroupPill key={key} messages={item.messages} labels={item.labels} role={item.role} />
)
)}
</div>
)
}
+// Character count approximates rendered height without measuring the DOM.
+const LONG_MESSAGE_CHARS = 1500
+const LONG_MESSAGE_LINES = 20
+
+function isLongMessage(text: string): boolean {
+ return text.length > LONG_MESSAGE_CHARS || text.split('\n').length > LONG_MESSAGE_LINES
+}
+
+function CollapsibleBubbleText({ text }: { text: string }): JSX.Element {
+ const [expanded, setExpanded] = useState(false)
+ // Trace content is untrusted, so external images must not auto-load.
+ const markdown = (
+ <LemonMarkdown className="whitespace-pre-wrap break-words" disableImages>
+ {text}
+ </LemonMarkdown>
+ )
+ if (!isLongMessage(text)) {
+ return markdown
+ }
+ const collapsed = !expanded
+ return (
+ <div className="flex flex-col gap-1">
+ <div className={collapsed ? 'max-h-60 overflow-hidden' : undefined}>{markdown}</div>
+ <LemonButton
+ size="xsmall"
+ type="tertiary"
+ className="self-start"
+ onClick={() => setExpanded((v) => !v)}
+ data-attr="llm-session-toggle-long-message"
+ >
+ {collapsed ? 'Show more' : 'Show less'}
+ </LemonButton>
+ </div>
+ )
+}
+
function InternalGroupPill({
messages,
labels,
diff --git a/products/ai_observability/frontend/aiObservabilitySessionLogic.ts b/products/ai_observability/frontend/aiObservabilitySessionLogic.ts
index 6aacd9b60aa3..025f67290256 100644
--- a/products/ai_observability/frontend/aiObservabilitySessionLogic.ts
+++ b/products/ai_observability/frontend/aiObservabilitySessionLogic.ts
@@ -9,6 +9,7 @@ import { AnyResponseType, DataTableNode, NodeKind, SessionQuery } from '~/querie
import { Breadcrumb, InsightLogicProps } from '~/types'
import { aiObservabilitySharedLogic } from './aiObservabilitySharedLogic'
+import { buildAiObservabilityStorageConfig } from './preferenceStorage'
export interface AIObservabilitySessionDataNodeLogicParams {
sessionId: string
@@ -44,6 +45,7 @@ export interface aiObservabilitySessionLogicValues {
dateTo: string | null
} // aiObservabilitySharedLogic
breadcrumbs: Breadcrumb[]
+ conversationOnly: boolean
dateRange: {
dateFrom: string | null
dateTo: string | null
@@ -54,6 +56,9 @@ export interface aiObservabilitySessionLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface aiObservabilitySessionLogicActions {
+ setConversationOnly: (conversationOnly: boolean) => {
+ conversationOnly: boolean
+ }
setDateRange: (
dateFrom: string | null,
dateTo?: string | null
@@ -104,10 +109,16 @@ export const aiObservabilitySessionLogic = kea<aiObservabilitySessionLogicType>(
actions({
setSessionId: (sessionId: string) => ({ sessionId }),
setDateRange: (dateFrom: string | null, dateTo?: string | null) => ({ dateFrom, dateTo }),
+ setConversationOnly: (conversationOnly: boolean) => ({ conversationOnly }),
}),
- reducers({
+ reducers(() => ({
sessionId: ['' as string, { setSessionId: (_, { sessionId }) => sessionId }],
+ conversationOnly: [
+ false as boolean,
+ buildAiObservabilityStorageConfig('session.conversationOnly'),
+ { setConversationOnly: (_, { conversationOnly }) => conversationOnly },
+ ],
dateRange: [
null as { dateFrom: string | null; dateTo: string | null } | null,
{
@@ -117,7 +128,7 @@ export const aiObservabilitySessionLogic = kea<aiObservabilitySessionLogicType>(
}),
},
],
- }),
+ })),
selectors({
query: [