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.

fix(aio): render activity AI generation input correctly (#66469) (#68820)

Eva Wuuu84e0d350e791
diff --git a/frontend/src/scenes/activity/explore/EventDetails.tsx b/frontend/src/scenes/activity/explore/EventDetails.tsx
index 3a093c816769..dbc5cfa1fbf7 100644
--- a/frontend/src/scenes/activity/explore/EventDetails.tsx
+++ b/frontend/src/scenes/activity/explore/EventDetails.tsx
@@ -84,6 +84,7 @@ export function EventDetails({ event, tableProps }: EventDetailsProps): JSX.Elem
<ConversationDisplay
eventProperties={properties}
eventId={getEventId(event)}
+ eventName={event.event}
eventTimestamp={event.timestamp}
/>
</div>
diff --git a/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.stories.tsx b/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.stories.tsx
index 4449d2aae757..f551de26a848 100644
--- a/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.stories.tsx
+++ b/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.stories.tsx
@@ -5,8 +5,14 @@ import { ConversationDisplay as ConversationDisplayComponent, ConversationDispla
const meta: Meta<ConversationDisplayProps> = {
title: 'Scenes-App/AI observability/Conversation Display',
component: ConversationDisplayComponent,
- render: ({ eventProperties, eventId }) => {
- return <ConversationDisplayComponent eventProperties={eventProperties} eventId={eventId || 'story-event-1'} />
+ render: ({ eventProperties, eventId, eventName }) => {
+ return (
+ <ConversationDisplayComponent
+ eventProperties={eventProperties}
+ eventId={eventId || 'story-event-1'}
+ eventName={eventName || '$ai_generation'}
+ />
+ )
},
}
export default meta
diff --git a/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.test.tsx b/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.test.tsx
new file mode 100644
index 000000000000..08506d133f3a
--- /dev/null
+++ b/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.test.tsx
@@ -0,0 +1,122 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render } from '@testing-library/react'
+import { Provider } from 'kea'
+
+import { initKeaTests } from '~/test/init'
+
+import { useAIData } from '../hooks/useAIData'
+import { ConversationDisplay } from './ConversationDisplay'
+
+jest.mock('../hooks/useAIData', () => ({
+ useAIData: jest.fn(),
+}))
+
+jest.mock('./ConversationMessagesDisplay', () => ({
+ ConversationMessagesDisplay: jest.fn(() => null),
+}))
+
+jest.mock('./MetadataHeader', () => ({
+ MetadataHeader: jest.fn(() => null),
+}))
+
+const mockUseAIData = useAIData as jest.MockedFunction<typeof useAIData>
+
+describe('ConversationDisplay', () => {
+ beforeEach(() => {
+ initKeaTests()
+ mockUseAIData.mockImplementation((eventData) => ({
+ input: eventData?.input,
+ output: eventData?.output,
+ tools: eventData?.tools,
+ isLoading: false,
+ }))
+ })
+
+ afterEach(() => {
+ cleanup()
+ jest.resetAllMocks()
+ })
+
+ it.each([
+ [
+ '$ai_generation without $ai_input',
+ '$ai_generation',
+ {
+ $ai_input_state: { messages: [{ type: 'system', content: 'state input' }] },
+ $ai_output_choices: [{ message: { role: 'assistant', content: 'choice output' } }],
+ $ai_output: 'plain output',
+ $ai_tools: [{ function: { name: 'search' } }],
+ $ai_trace_id: 'trace-1',
+ },
+ {
+ input: undefined,
+ output: [{ message: { role: 'assistant', content: 'choice output' } }],
+ },
+ ],
+ [
+ '$ai_generation with $ai_input',
+ '$ai_generation',
+ {
+ $ai_input: [{ role: 'user', content: 'generation input' }],
+ $ai_output: 'plain output',
+ $ai_tools: [{ function: { name: 'search' } }],
+ $ai_trace_id: 'trace-1',
+ },
+ {
+ input: [{ role: 'user', content: 'generation input' }],
+ output: 'plain output',
+ },
+ ],
+ [
+ '$ai_embedding',
+ '$ai_embedding',
+ {
+ $ai_input: 'embedding input',
+ $ai_output_state: 'state output',
+ $ai_tools: [{ function: { name: 'search' } }],
+ $ai_trace_id: 'trace-1',
+ },
+ {
+ input: 'embedding input',
+ output: 'Embedding vector generated',
+ },
+ ],
+ [
+ '$ai_span',
+ '$ai_span',
+ {
+ $ai_input: [{ role: 'user', content: 'generation-like input' }],
+ $ai_input_state: { messages: [{ type: 'human', content: 'state input' }] },
+ $ai_output_choices: [{ message: { role: 'assistant', content: 'choice output' } }],
+ $ai_output_state: { messages: [{ type: 'ai', content: 'state output' }] },
+ $ai_tools: [{ function: { name: 'search' } }],
+ $ai_trace_id: 'trace-1',
+ },
+ {
+ input: { messages: [{ type: 'human', content: 'state input' }] },
+ output: { messages: [{ type: 'ai', content: 'state output' }] },
+ },
+ ],
+ ])('passes trace-view-compatible data for %s', (_label, eventName, eventProperties, expected) => {
+ render(
+ <Provider>
+ <ConversationDisplay
+ eventProperties={eventProperties}
+ eventId="event-1"
+ eventName={eventName}
+ eventTimestamp="2026-07-06T20:22:00Z"
+ />
+ </Provider>
+ )
+
+ expect(mockUseAIData).toHaveBeenCalledWith({
+ uuid: 'event-1',
+ input: expected.input,
+ output: expected.output,
+ tools: [{ function: { name: 'search' } }],
+ traceId: 'trace-1',
+ timestamp: '2026-07-06T20:22:00Z',
+ })
+ })
+})
diff --git a/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.tsx b/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.tsx
index e2a9bddf485a..96f97955d7d0 100644
--- a/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.tsx
+++ b/products/ai_observability/frontend/ConversationDisplay/ConversationDisplay.tsx
@@ -17,6 +17,7 @@ import { MetadataHeader } from './MetadataHeader'
export interface ConversationDisplayProps {
eventProperties: EventType['properties']
eventId: string
+ eventName?: string
/** Event timestamp, needed to fetch heavy props via TraceQuery when they've been stripped from `events`. */
eventTimestamp?: string
}
@@ -24,10 +25,19 @@ export interface ConversationDisplayProps {
export function ConversationDisplay({
eventProperties,
eventId,
+ eventName,
eventTimestamp,
}: ConversationDisplayProps): JSX.Element {
- const rawInput = eventProperties.$ai_input ?? eventProperties.$ai_input_state
- const rawOutput = eventProperties.$ai_output_choices ?? eventProperties.$ai_output_state
+ const rawInput =
+ eventName === '$ai_generation' || eventName === '$ai_embedding'
+ ? eventProperties.$ai_input
+ : eventProperties.$ai_input_state
+ const rawOutput =
+ eventName === '$ai_generation'
+ ? (eventProperties.$ai_output_choices ?? eventProperties.$ai_output)
+ : eventName === '$ai_embedding'
+ ? 'Embedding vector generated'
+ : eventProperties.$ai_output_state
const rawTools = eventProperties.$ai_tools
const { input, output, tools, isLoading } = useAIData({
uuid: eventId,