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.

chore(phai): split agent-run surface into a tiered api/ facade (#66173)

Georgiy Tarasov89c721307e87
diff --git a/frontend/src/scenes/inbox/components/detail/AgentRunDetail.tsx b/frontend/src/scenes/inbox/components/detail/AgentRunDetail.tsx
index 125dc1c33471..fe1003723619 100644
--- a/frontend/src/scenes/inbox/components/detail/AgentRunDetail.tsx
+++ b/frontend/src/scenes/inbox/components/detail/AgentRunDetail.tsx
@@ -20,7 +20,8 @@ import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
import { SANDBOX_BIND_TASK_PARAM } from 'scenes/max/maxLogic'
import { urls } from 'scenes/urls'
-import { isTerminalRunStatus, RunViewer } from 'products/posthog_ai/frontend'
+import { isTerminalRunStatus } from 'products/posthog_ai/frontend/api/logics'
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
import { Task, TaskRunStatus } from 'products/posthog_ai/frontend/types/taskTypes'
import { inboxReportDetailLogic } from '../../logics/inboxReportDetailLogic'
diff --git a/frontend/src/scenes/inbox/components/detail/ArtefactTaskRun.tsx b/frontend/src/scenes/inbox/components/detail/ArtefactTaskRun.tsx
index 40edeca0b717..498db38c341a 100644
--- a/frontend/src/scenes/inbox/components/detail/ArtefactTaskRun.tsx
+++ b/frontend/src/scenes/inbox/components/detail/ArtefactTaskRun.tsx
@@ -6,7 +6,8 @@ import { LemonTag } from '@posthog/lemon-ui'
import api from 'lib/api'
import { identifierToHuman } from 'lib/utils/strings'
-import { isTerminalRunStatus, RunViewer } from 'products/posthog_ai/frontend'
+import { isTerminalRunStatus } from 'products/posthog_ai/frontend/api/logics'
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
import { Task, TaskRunStatus } from 'products/posthog_ai/frontend/types/taskTypes'
import { isCustomAgentTaskRun, taskRunTypeLabel, TaskRunArtefactContent } from './artefactTypes'
diff --git a/frontend/src/scenes/inbox/components/detail/ReportTasksSection.tsx b/frontend/src/scenes/inbox/components/detail/ReportTasksSection.tsx
index d206413825fb..b2fff5e2b061 100644
--- a/frontend/src/scenes/inbox/components/detail/ReportTasksSection.tsx
+++ b/frontend/src/scenes/inbox/components/detail/ReportTasksSection.tsx
@@ -3,7 +3,8 @@ import { useActions, useValues } from 'kea'
import { IconChevronDown, IconChevronRight, IconTerminal } from '@posthog/icons'
import { Spinner } from '@posthog/lemon-ui'
-import { isTerminalRunStatus, RunViewer } from 'products/posthog_ai/frontend'
+import { isTerminalRunStatus } from 'products/posthog_ai/frontend/api/logics'
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
import { TaskRunStatus } from 'products/posthog_ai/frontend/types/taskTypes'
import { inboxReportDetailLogic, ReportTaskEntry } from '../../logics/inboxReportDetailLogic'
diff --git a/frontend/src/scenes/max/AGENTS.md b/frontend/src/scenes/max/AGENTS.md
index 39c370f6ef06..0b7e02e1ddfb 100644
--- a/frontend/src/scenes/max/AGENTS.md
+++ b/frontend/src/scenes/max/AGENTS.md
@@ -48,10 +48,12 @@ parsing wire frames in a Max component.
The conversation-agnostic sandbox run surface (stream logic, thread/tool/permission/composer components,
policy, wire types) **no longer lives under `scenes/max`** — it's the composable PostHog AI agent-run
-library at `products/posthog_ai/frontend`, consumed here via its barrel
-(`import { ... } from 'products/posthog_ai/frontend'`). See that directory's `AGENTS.md` for its layout,
-public component API (`RunViewer`, `Thread`, `Composer`, `runStreamLogic`, the tool registry), and the
-hard rule that it must never import `scenes/max`.
+library at `products/posthog_ai/frontend`, consumed here through its tiered `api/<module>` facade
+(`import { ... } from 'products/posthog_ai/frontend/api/run'` / `api/primitives` / `api/logics` /
+`api/types` / `api/tools` — there is no root barrel; pick the narrowest tier). See that directory's
+`README.md` for the tier decision table + recipes and its `AGENTS.md` for layout, the public API
+(`RunViewer`, `Thread`, `Composer`, `runStreamLogic`, the tool registry), and the hard rule that it must
+never import `scenes/max`.
What stays in `scenes/max`: conversation orchestration (`maxLogic`, `maxThreadLogic`, `maxGlobalLogic`), the
Max Context subsystem, slash commands, `useMaxTool`/`MaxTool`, feedback/ratings, the frozen LangGraph path,
diff --git a/frontend/src/scenes/max/FeedbackPrompt.tsx b/frontend/src/scenes/max/FeedbackPrompt.tsx
index 0439153dc181..5eb50fa1a543 100644
--- a/frontend/src/scenes/max/FeedbackPrompt.tsx
+++ b/frontend/src/scenes/max/FeedbackPrompt.tsx
@@ -8,7 +8,7 @@ import { LemonButton, LemonInput, LemonModal } from '@posthog/lemon-ui'
import { SupportForm } from 'lib/components/Support/SupportForm'
import { supportLogic } from 'lib/components/Support/supportLogic'
-import { MessageTemplate } from 'products/posthog_ai/frontend'
+import { MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'
import { feedbackPromptLogic } from './feedbackPromptLogic'
import { captureFeedback } from './utils'
diff --git a/frontend/src/scenes/max/Thread.tsx b/frontend/src/scenes/max/Thread.tsx
index 256c056f5840..651375267b83 100644
--- a/frontend/src/scenes/max/Thread.tsx
+++ b/frontend/src/scenes/max/Thread.tsx
@@ -68,17 +68,16 @@ import { DataVisualizationNode, InsightVizNode } from '~/queries/schema/schema-g
import { isDataVisualizationNode, isHogQLQuery } from '~/queries/utils'
import { PendingApproval, Region } from '~/types'
+import { getThinkingMessageFromResponse, runStreamLogic } from 'products/posthog_ai/frontend/api/logics'
import {
AssistantFailureMessage,
- getThinkingMessageFromResponse,
+ ContextUsageBar,
MarkdownMessage,
MessageTemplate,
ReasoningAnswer,
- ContextUsageBar,
ResourcesBar,
- runStreamLogic,
ThreadView,
-} from 'products/posthog_ai/frontend'
+} from 'products/posthog_ai/frontend/api/primitives'
import { LogEntry } from 'products/posthog_ai/frontend/lib/parse-logs'
import { LangGraphActivity, ShimmeringContent } from './components/Activity'
diff --git a/frontend/src/scenes/max/components/Activity/LangGraphActivity.tsx b/frontend/src/scenes/max/components/Activity/LangGraphActivity.tsx
index 419814a98fd0..7d8c124d2d5c 100644
--- a/frontend/src/scenes/max/components/Activity/LangGraphActivity.tsx
+++ b/frontend/src/scenes/max/components/Activity/LangGraphActivity.tsx
@@ -4,7 +4,7 @@ import { CodeSnippet, Language } from 'lib/components/CodeSnippet/CodeSnippet'
import { TaskExecutionStatus as ExecutionStatus } from '~/queries/schema/schema-assistant-messages'
-import { Activity, ActivityToggleSection, MarkdownMessage } from 'products/posthog_ai/frontend'
+import { Activity, ActivityToggleSection, MarkdownMessage } from 'products/posthog_ai/frontend/api/primitives'
import type { EnhancedToolCall } from '../../max-constants'
import { SummarizeSessionsWidget, UIPayloadAnswer, isRenderableUIPayloadTool } from '../../messages/UIPayloadAnswer'
diff --git a/frontend/src/scenes/max/components/Activity/index.ts b/frontend/src/scenes/max/components/Activity/index.ts
index b292e39f5cdd..e21e93db3c3f 100644
--- a/frontend/src/scenes/max/components/Activity/index.ts
+++ b/frontend/src/scenes/max/components/Activity/index.ts
@@ -7,6 +7,6 @@ export {
ActivityToggleSection,
RunActivity,
ShimmeringContent,
-} from 'products/posthog_ai/frontend'
-export type { ActivityStatus } from 'products/posthog_ai/frontend'
+} from 'products/posthog_ai/frontend/api/primitives'
+export type { ActivityStatus } from 'products/posthog_ai/frontend/api/primitives'
export { LangGraphActivity } from './LangGraphActivity'
diff --git a/frontend/src/scenes/max/components/InputFormArea.tsx b/frontend/src/scenes/max/components/InputFormArea.tsx
index db71efba0249..75ba6ad21141 100644
--- a/frontend/src/scenes/max/components/InputFormArea.tsx
+++ b/frontend/src/scenes/max/components/InputFormArea.tsx
@@ -17,10 +17,10 @@ import {
MultiFieldQuestion,
type Option,
OptionSelector,
- QuestionField,
PermissionInput,
+ QuestionField,
QuestionInput,
-} from 'products/posthog_ai/frontend'
+} from 'products/posthog_ai/frontend/api/primitives'
import { maxThreadLogic } from '../maxThreadLogic'
diff --git a/frontend/src/scenes/max/components/MaxWebAnalyticsNudge.tsx b/frontend/src/scenes/max/components/MaxWebAnalyticsNudge.tsx
index efc6f82679c2..6889cda27348 100644
--- a/frontend/src/scenes/max/components/MaxWebAnalyticsNudge.tsx
+++ b/frontend/src/scenes/max/components/MaxWebAnalyticsNudge.tsx
@@ -4,7 +4,7 @@ import { LemonButton } from '@posthog/lemon-ui'
import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'
-import { MessageTemplate } from 'products/posthog_ai/frontend'
+import { MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'
import { maxWebAnalyticsNudgeLogic } from '../logics/maxWebAnalyticsNudgeLogic'
import { maxLogic, ThreadMessage } from '../maxLogic'
diff --git a/frontend/src/scenes/max/maxThreadLogic.test.ts b/frontend/src/scenes/max/maxThreadLogic.test.ts
index d091258a0dd1..ef84f08c862c 100644
--- a/frontend/src/scenes/max/maxThreadLogic.test.ts
+++ b/frontend/src/scenes/max/maxThreadLogic.test.ts
@@ -30,7 +30,7 @@ import {
import { initKeaTests } from '~/test/init'
import { Conversation, ConversationDetail, ConversationStatus, ConversationType } from '~/types'
-import { runStreamLogic } from 'products/posthog_ai/frontend'
+import { runStreamLogic } from 'products/posthog_ai/frontend/api/logics'
import { EnhancedToolCall, TOOL_DEFINITIONS } from './max-constants'
import { maxContextLogic } from './maxContextLogic'
diff --git a/frontend/src/scenes/max/maxThreadLogic.tsx b/frontend/src/scenes/max/maxThreadLogic.tsx
index b653f480e9a3..2478c30cc7b3 100644
--- a/frontend/src/scenes/max/maxThreadLogic.tsx
+++ b/frontend/src/scenes/max/maxThreadLogic.tsx
@@ -69,7 +69,7 @@ import {
isTerminalRunStatus,
INITIAL_PERMISSION_MODE,
runStreamLogic,
-} from 'products/posthog_ai/frontend'
+} from 'products/posthog_ai/frontend/api/logics'
import { LogEntry, parseLogEvent } from 'products/posthog_ai/frontend/lib/parse-logs'
import { handsFreeLogic } from './handsFreeLogic'
diff --git a/frontend/src/scenes/max/maxTypes.ts b/frontend/src/scenes/max/maxTypes.ts
index cd6c3d929d4f..e2214d3a97c1 100644
--- a/frontend/src/scenes/max/maxTypes.ts
+++ b/frontend/src/scenes/max/maxTypes.ts
@@ -245,7 +245,7 @@ export function isAgentMode(mode: unknown): mode is AgentMode {
// `ToolCallMessage` now lives with the relocated sandbox renderer. Re-exported here so
// the frozen LangGraph path and any in-flight branches keep resolving it from `maxTypes`.
-export type { ToolCallMessage } from 'products/posthog_ai/frontend'
+export type { ToolCallMessage } from 'products/posthog_ai/frontend/api/types'
/**
* Flat context attachment sent to the sandbox agent runtime (`agent_runtime === 'sandbox'`).
diff --git a/frontend/src/scenes/max/messages/MultiQuestionForm.tsx b/frontend/src/scenes/max/messages/MultiQuestionForm.tsx
index 94456294ecb1..5f5de4a84b3b 100644
--- a/frontend/src/scenes/max/messages/MultiQuestionForm.tsx
+++ b/frontend/src/scenes/max/messages/MultiQuestionForm.tsx
@@ -2,7 +2,7 @@ import { IconCheck, IconX } from '@posthog/icons'
import { MultiQuestionForm as MultiQuestionFormType } from '~/queries/schema/schema-assistant-messages'
-import { MessageTemplate } from 'products/posthog_ai/frontend'
+import { MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'
interface MultiQuestionFormRecapProps {
form: MultiQuestionFormType
diff --git a/frontend/src/scenes/max/messages/NotebookArtifactAnswer.tsx b/frontend/src/scenes/max/messages/NotebookArtifactAnswer.tsx
index d07d52a4894e..11e2df1ff8a2 100644
--- a/frontend/src/scenes/max/messages/NotebookArtifactAnswer.tsx
+++ b/frontend/src/scenes/max/messages/NotebookArtifactAnswer.tsx
@@ -35,7 +35,7 @@ import { NotebookArtifactContent } from '~/queries/schema/schema-assistant-messa
import { DataVisualizationNode, InsightVizNode, NodeKind } from '~/queries/schema/schema-general'
import { isFunnelsQuery, isHogQLQuery, isInsightVizNode } from '~/queries/utils'
-import { MarkdownMessage, MessageTemplate } from 'products/posthog_ai/frontend'
+import { MarkdownMessage, MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'
import { MessageStatus } from '../maxLogic'
import { castAssistantQuery, visualizationTypeToQuery } from '../utils'
diff --git a/frontend/src/scenes/max/messages/UIPayloadAnswer.tsx b/frontend/src/scenes/max/messages/UIPayloadAnswer.tsx
index a3cc9065aa61..5978aecd93d3 100644
--- a/frontend/src/scenes/max/messages/UIPayloadAnswer.tsx
+++ b/frontend/src/scenes/max/messages/UIPayloadAnswer.tsx
@@ -31,7 +31,7 @@ import {
issueQueryOptionsLogic,
} from 'products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic'
import { ERROR_TRACKING_SCENE_LOGIC_KEY } from 'products/error_tracking/frontend/scenes/ErrorTrackingScene/errorTrackingSceneLogic'
-import { MessageTemplate } from 'products/posthog_ai/frontend'
+import { MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'
import { isDangerousOperationResponse, normalizeDangerousOperationResponse } from '../approvalOperationUtils'
import { DangerousOperationApprovalCard } from '../DangerousOperationApprovalCard'
diff --git a/frontend/src/scenes/max/messages/VisualizationWidget.tsx b/frontend/src/scenes/max/messages/VisualizationWidget.tsx
index 958610f3bafd..f2da16399726 100644
--- a/frontend/src/scenes/max/messages/VisualizationWidget.tsx
+++ b/frontend/src/scenes/max/messages/VisualizationWidget.tsx
@@ -24,7 +24,7 @@ import { QueryContext } from '~/queries/types'
import { isFunnelsQuery, isHogQLQuery, isInsightVizNode } from '~/queries/utils'
import { InsightShortId } from '~/types'
-import { MessageTemplate } from 'products/posthog_ai/frontend'
+import { MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'
import { visualizationTypeToQuery } from '../utils'
diff --git a/frontend/src/scenes/max/messages/adapters/CreateInsightWidget.tsx b/frontend/src/scenes/max/messages/adapters/CreateInsightWidget.tsx
index 1898ffc1803b..3174d6bb53c1 100644
--- a/frontend/src/scenes/max/messages/adapters/CreateInsightWidget.tsx
+++ b/frontend/src/scenes/max/messages/adapters/CreateInsightWidget.tsx
@@ -1,4 +1,4 @@
-import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend'
+import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend/api/tools'
import { VisualizationWidget, getArtifactOpenTarget } from '../VisualizationWidget'
import { extractVisualizationArtifact } from './extractors'
diff --git a/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.test.tsx b/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.test.tsx
index a74b4351a778..cddbffa28be5 100644
--- a/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.test.tsx
+++ b/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.test.tsx
@@ -2,7 +2,7 @@
// registry. The bare registry no longer knows product keys, so the resolution assertions below need it.
import './registerMaxToolRenderers'
-import { lookupToolRenderer, toolRegistry } from 'products/posthog_ai/frontend'
+import { lookupToolRenderer, toolRegistry } from 'products/posthog_ai/frontend/api/tools'
import type { ToolCallMessage } from '../../maxTypes'
import { extractNotebook } from './CreateNotebookWidget'
diff --git a/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.tsx b/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.tsx
index e8031f4b0c68..5c4e5fa27100 100644
--- a/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.tsx
+++ b/frontend/src/scenes/max/messages/adapters/CreateNotebookWidget.tsx
@@ -4,7 +4,7 @@ import { LemonButton } from '@posthog/lemon-ui'
import { IconOpenInNew } from 'lib/lemon-ui/icons'
import { urls } from 'scenes/urls'
-import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend'
+import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend/api/tools'
/** The notebook fields the widget renders, pulled from the REST payload. */
export interface NotebookExtraction {
diff --git a/frontend/src/scenes/max/messages/adapters/ErrorTrackingWidget.tsx b/frontend/src/scenes/max/messages/adapters/ErrorTrackingWidget.tsx
index d70abb5837cf..a43ab5f69645 100644
--- a/frontend/src/scenes/max/messages/adapters/ErrorTrackingWidget.tsx
+++ b/frontend/src/scenes/max/messages/adapters/ErrorTrackingWidget.tsx
@@ -1,4 +1,4 @@
-import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend'
+import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend/api/tools'
import { ErrorTrackingFiltersWidget } from '../UIPayloadAnswer'
import { extractErrorTrackingResponse } from './extractors'
diff --git a/frontend/src/scenes/max/messages/adapters/QueryWidget.tsx b/frontend/src/scenes/max/messages/adapters/QueryWidget.tsx
index 27c82061337c..15f04c024c25 100644
--- a/frontend/src/scenes/max/messages/adapters/QueryWidget.tsx
+++ b/frontend/src/scenes/max/messages/adapters/QueryWidget.tsx
@@ -1,4 +1,4 @@
-import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend'
+import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend/api/tools'
import { VisualizationWidget } from '../VisualizationWidget'
import { extractQueryResult } from './extractors'
diff --git a/frontend/src/scenes/max/messages/adapters/SearchSessionRecordingsWidget.tsx b/frontend/src/scenes/max/messages/adapters/SearchSessionRecordingsWidget.tsx
index 92861e521e98..affc97c209c5 100644
--- a/frontend/src/scenes/max/messages/adapters/SearchSessionRecordingsWidget.tsx
+++ b/frontend/src/scenes/max/messages/adapters/SearchSessionRecordingsWidget.tsx
@@ -1,4 +1,4 @@
-import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend'
+import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend/api/tools'
import { RecordingsWidget } from '../UIPayloadAnswer'
import { extractRecordingFilters } from './extractors'
diff --git a/frontend/src/scenes/max/messages/adapters/UpsertDashboardWidget.tsx b/frontend/src/scenes/max/messages/adapters/UpsertDashboardWidget.tsx
index 350ea886a376..6253368f15a8 100644
--- a/frontend/src/scenes/max/messages/adapters/UpsertDashboardWidget.tsx
+++ b/frontend/src/scenes/max/messages/adapters/UpsertDashboardWidget.tsx
@@ -4,7 +4,7 @@ import { LemonButton } from '@posthog/lemon-ui'
import { IconOpenInNew } from 'lib/lemon-ui/icons'
import { urls } from 'scenes/urls'
-import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend'
+import { GenericMcpToolRenderer, DataToolRow, type ToolRendererProps } from 'products/posthog_ai/frontend/api/tools'
import { extractDashboard } from './extractors'
diff --git a/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.test.ts b/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.test.ts
index 5c9b96c3a34f..1c397e470782 100644
--- a/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.test.ts
+++ b/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.test.ts
@@ -3,7 +3,7 @@
// Renderer itself is an opaque chunk).
import './registerMaxToolRenderers'
-import { toolRegistry } from 'products/posthog_ai/frontend'
+import { toolRegistry } from 'products/posthog_ai/frontend/api/tools'
describe('registerMaxToolRenderers', () => {
it.each([
diff --git a/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.tsx b/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.tsx
index 2ef4d681c23e..dc022f64f2f2 100644
--- a/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.tsx
+++ b/frontend/src/scenes/max/messages/adapters/registerMaxToolRenderers.tsx
@@ -16,7 +16,11 @@ import {
IconWarning,
} from '@posthog/icons'
-import { toolRegistry, type ToolRendererProps } from 'products/posthog_ai/frontend'
+import {
+ registerToolRenderers,
+ type ToolRegistryEntry,
+ type ToolRendererProps,
+} from 'products/posthog_ai/frontend/api/tools'
// Product-specific tool-call renderers for the PostHog AI agent run surface. These render PostHog
// product entities (insights, dashboards, recordings, error-tracking issues, notebooks, query results)
@@ -40,16 +44,16 @@ const NotebookRenderer = lazy(() => import('./CreateNotebookWidget').then((m) =>
const QueryRenderer = lazy(() => import('./QueryWidget').then((m) => ({ default: m.QueryWidget })))
// The single-exec inner tool names exist in two conventions — hyphenated (the MCP yaml definitions) and
-// snake_case (legacy Max tools) — so we register both aliases where both are real tool names.
+// snake_case (legacy Max tools) — so we register both aliases where both are real tool names. Each call
+// fans the aliases into one entry per key and feeds them through the surface's `registerToolRenderers`
+// seam (Tier 4) — Max is the first consumer of that generic per-product mechanism.
function register(
keys: string[],
displayName: string,
icon: JSX.Element,
Renderer: ComponentType<ToolRendererProps>
): void {
- for (const key of keys) {
- toolRegistry.register({ key, displayName, icon, Renderer })
- }
+ registerToolRenderers(keys.map((key): ToolRegistryEntry => ({ key, displayName, icon, Renderer })))
}
// --- Data tools: insight (create / update / read) ---
@@ -113,6 +117,13 @@ const QUERY_WRAPPER_TOOLS: { key: string; displayName: string; icon: JSX.Element
{ key: 'query-lifecycle-actors', displayName: 'Lifecycle persons', icon: <IconPerson /> },
{ key: 'query-paths-actors', displayName: 'Paths persons', icon: <IconPerson /> },
]
-for (const { key, displayName, icon } of QUERY_WRAPPER_TOOLS) {
- toolRegistry.register({ key, displayName, icon, Renderer: QueryRenderer })
-}
+registerToolRenderers(
+ QUERY_WRAPPER_TOOLS.map(
+ ({ key, displayName, icon }): ToolRegistryEntry => ({
+ key,
+ displayName,
+ icon,
+ Renderer: QueryRenderer,
+ })
+ )
+)
diff --git a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx
index 769ce1ebd6c7..f768351310a3 100644
--- a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx
+++ b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx
@@ -5,7 +5,7 @@ import { IconChevronRight } from '@posthog/icons'
import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
-import { MessageTemplate } from 'products/posthog_ai/frontend'
+import { MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'
import { CompatMessage } from '../types'
import {
diff --git a/products/posthog_ai/frontend/AGENTS.md b/products/posthog_ai/frontend/AGENTS.md
index 8c9b823cb103..5b4393cca1ee 100644
--- a/products/posthog_ai/frontend/AGENTS.md
+++ b/products/posthog_ai/frontend/AGENTS.md
@@ -10,25 +10,51 @@ embeddable anywhere an agent run needs to be shown or interacted with. The stand
> conventionally directly under `frontend/` with the prefix dropped. The word "sandbox" that remains is the
> agent _runtime_ (`agent_runtime === 'sandbox'`), a real domain term — not the old codename.
-## 1. The public API is the barrel (`index.ts`)
-
-Every external consumer imports from `products/posthog_ai/frontend` (the barrel) — **never** from deep
-paths. The barrel is the contract; internal files can move freely behind it. The headline exports:
-
-- **`RunViewer`** — Radix-style compound for an embeddable run. `RunViewer.Root` binds the stream logic and
- bootstraps the run; slots `RunViewer.Thread / .Prompt / .Composer / .Resources / .ContextUsage` compose a
- custom layout. Calling `RunViewer` directly (`<RunViewer .../>`) renders the prepackaged default layout —
- use that for the common embed.
-- **`Thread`** — Radix-style compound for the run thread. `Thread.Root` is the virtualized presenter; the
- atoms `Thread.Message / .Markdown / .Reasoning / .Failure / .Activity / .ToolCall` are the same
- presentational building blocks, exposed for bespoke threads.
-- **`Composer`** — logic-free compound input (`Composer.Root/Frame/Field/Placeholder/Textarea/Footer/Submit/
-Banner`). The caller owns `value`/`onChange`/`onSubmit`; every part is a styled slot.
-- **`runStreamLogic`** — the SSE stream + thread projection (see §3). **`runInteractionLogic`** — the
- Max-agnostic follow-up/queue interaction facade.
-- Tool rendering: **`toolRegistry`**, `lookupToolRenderer`, `GenericMcpToolRenderer`,
- `ToolActivity`, `DataToolRow`, `EditDiffRenderer`, and the diff/exec helpers.
-- Permission/question/resource surfaces, message presenters, and the folded-thread types.
+## 1. The public API is the `api/<module>` facade
+
+Every external consumer imports from a domain-scoped **`api/<module>`** entry — **never** from deep paths
+(`components/...`, `logics/...`). The `api/` modules are the contract; internal files move freely behind
+them. There are four tiers, split along dependency/side-effect boundaries (not cosmetics — that's what
+preserves code-splitting). Consumers pick the **lowest tier** that does the job. The full decision table,
+import rule, and copy-paste recipes live in the consumer-facing [`README.md`](./README.md); the summary:
+
+| Tier | Module | What's in it |
+| ------------------------------ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| **1 — Prepackaged surfaces** | `api/run` | `RunViewer` (call directly → default layout), `RunComposer` |
+| **2 — Compound primitives** | `api/primitives` | `RunViewer.Root` + slots, `Thread` + atoms, `ThreadView`, `Composer.*`, activity primitives + `RunActivity`, message presenters, permission/question/resource surfaces |
+| **3 — Headless logic + types** | `api/logics` + `api/types` | `runStreamLogic`, `runInteractionLogic`, status + thinking helpers; folded-thread + tool types |
+| **4 — Extension seam** | `api/tools` | `toolRegistry`, `registerToolRenderers`, `lookupToolRenderer`, `GenericMcpToolRenderer`, `DataToolRow`, `ToolActivity`, `FilePath`, diff helpers |
+
+**Why the split, not one flat barrel:** the tool registry registers built-ins at module load — a top-level
+side effect that is _not_ tree-shaken. A single barrel statically re-exports it alongside the
+markdown/virtualization-heavy thread and the headless logics, so a consumer wanting only
+`isTerminalRunStatus` for a status badge would drag the registry + presenters into its chunk. Isolating the
+side-effectful registry in `api/tools` and keeping the headless lane (`api/logics` + `api/types`) free of
+React/registry imports is what keeps each consumer's bundle to its subtree.
+
+There is deliberately **no root `index.ts` barrel**: a single aggregate that re-exports every tier would
+re-fatten any consumer's chunk and undo the split. It also wouldn't match the repo norm — no other
+`products/*/frontend` ships a barrel; consumers import the specific path they need. Every public symbol is
+reached through an `api/<module>` entry; add new exports to the relevant tier module, not to a new barrel.
+
+The headline exports per module:
+
+- **`api/run`** — **`RunViewer`** (Radix-style compound; call directly for the default-layout embed, or use
+ `.Root` + slots `.Thread/.Prompt/.Composer/.Resources/.ContextUsage` for a custom layout) and
+ **`RunComposer`**.
+- **`api/primitives`** — **`Thread`** (Radix-style compound: `Thread.Root` is the virtualized presenter, the
+ atoms `Thread.Message/.Markdown/.Reasoning/.Failure/.Activity/.ToolCall` are the building blocks for
+ bespoke threads), **`Composer`** (logic-free compound input — the caller owns
+ `value`/`onChange`/`onSubmit`), activity primitives, message presenters, and the
+ permission/question/resource surfaces.
+- **`api/logics`** — **`runStreamLogic`** (SSE stream + thread projection, see §3),
+ **`runInteractionLogic`** (Max-agnostic follow-up/queue facade), status helpers
+ (`isTerminalRunStatus`, `INITIAL_PERMISSION_MODE`), and thinking-message helpers. Imports only
+ `logics/*` + `utils/*` — never a component or the registry, so it's the clean headless lane.
+- **`api/types`** — folded-thread + tool domain types (pure types).
+- **`api/tools`** — **`toolRegistry`**, **`registerToolRenderers`** (the generic per-product seam, see §2),
+ `lookupToolRenderer`, `GenericMcpToolRenderer`, `DataToolRow`, `ToolActivity`, `FilePath`, and the
+ diff/exec helpers. Isolated here because importing it pulls the side-effectful registry chunk.
## 2. Coupling boundary — couples to tasks runs, never to Max
@@ -42,12 +68,16 @@ It must stay **free of the Max scene and conversation orchestration**. Do not im
- `runStreamLogic` keys on a generic `streamKey` (conversation id for Max, run/task id for a task
viewer). Keep it generic — no Max-specific branching.
-- **Product-specific tool renderers live in Max, not here.** Renderers that display PostHog product entities
- (insights, dashboards, recordings, error-tracking issues, notebooks, query results) live in
- `scenes/max/messages/adapters` and register themselves into `toolRegistry` via
- `registerMaxToolRenderers` (imported once by the Max scene). The shared registry only knows the built-ins,
- the exec verbs, the question card, the generic MCP card, and the generic `EditDiffRenderer`. Surfaces that
- never load Max (tasks, signals inbox) fall through to the generic card for those product keys — by design.
+- **Product-specific tool renderers live in the consuming product, not here — via the generic seam.**
+ `api/tools` exposes `toolRegistry` and the convenience wrapper **`registerToolRenderers(entries)`**: the
+ generic per-product mechanism for a product to plug in cards that display its own entities. A product
+ registers from its own scene's entrypoint; the shared registry stays free of product imports. **Max is
+ the first consumer of this pattern, not a special case** — its renderers (insights, dashboards,
+ recordings, error-tracking issues, notebooks, query results) live in `scenes/max/messages/adapters` and
+ call `registerToolRenderers` via `registerMaxToolRenderers` (imported once by the Max scene). The shared
+ registry only knows the built-ins, the exec verbs, the question card, the generic MCP card, and the
+ generic `EditDiffRenderer`. Surfaces without an adapter for a key (tasks, signals inbox) fall through to
+ the generic card — by design.
- If Max needs something the surface doesn't express generically, **lift it to a generic prop/selector here
and have Max adapt** — never special-case Max in this directory. Enforced by a grep gate:
`grep -rE "scenes/max|maxThreadLogic|MaxUIContext" products/posthog_ai/frontend` must be empty.
@@ -89,7 +119,12 @@ loosely typed — guard at the parse boundary with runtime checks; never assume
## 5. Layout
```text
-index.ts # public API barrel (the contract)
+api/ # public API facade — the contract (import api/<module>, never deep paths)
+ run.ts # Tier 1: RunViewer, RunComposer
+ primitives.ts # Tier 2: Composer, Thread + atoms, ThreadView, presenters, perm/question/resource
+ logics.ts # Tier 3: runStreamLogic, runInteractionLogic, status + thinking helpers (headless)
+ types.ts # Tier 3: folded-thread + tool domain types (pure types)
+ tools.ts # Tier 4: toolRegistry + registerToolRenderers seam (side-effectful — isolated)
components/ # RunViewer, Thread, Composer, permission/question/resource surfaces, activity, tool/
composer/ # the Composer compound
tool/ # tool registry + renderers (built-ins, generic MCP, EditDiffRenderer, diff/exec utils)
@@ -103,3 +138,18 @@ scenes/ # standalone scenes registered via ../manifest.tsx
TaskTracker/ # the runner scene (component, stories, scene logics, scene-specific components/)
generated/ # auto-generated API types (mcp_tools / docs_search) — do not edit by hand
```
+
+## 6. Replacement-readiness
+
+This surface is the intended replacement for Max's **legacy LangGraph thread**. The design keeps the
+eventual switch clean, so build with it in mind:
+
+- **The new-vs-legacy switch is a consumer concern, not this surface's.** Max already routes
+ `conversation.agent_runtime === 'sandbox'` through `runStreamLogic` (keyed by `conversationId`) and renders
+ `threadItems` via this surface, while its LangGraph `EventSource` path renders Max's own thread. **This
+ surface must never branch on Max/LangGraph/conversation** — enforced by the §2 grep gate.
+- **For full replacement, what the LangGraph path owns that the surface doesn't express generically** —
+ agent modes, billing context, scene attachments/context — **stays in Max as a consumer** and feeds the
+ surface through generic props / the tool registry / `streamKey`. If the surface needs it, lift it to a
+ generic seam here; never special-case Max. The setting flips the default implementation **in Max**; this
+ surface's contract (the four tiers in §1) is unchanged whichever side of the switch is active.
diff --git a/products/posthog_ai/frontend/README.md b/products/posthog_ai/frontend/README.md
new file mode 100644
index 000000000000..3066e3545fdb
--- /dev/null
+++ b/products/posthog_ai/frontend/README.md
@@ -0,0 +1,126 @@
+# PostHog AI agent-run surface — consumer guide
+
+This directory is the **conversation-agnostic agent-run UI**: a library that renders and drives a streamed
+agent run — the thread, tool cards, approvals, the composer. If you're embedding a run, showing a status
+badge, or registering a product's tool cards, you consume it from here.
+
+> Building _on_ the surface (adding a thread-item type, a permission rule, stream telemetry)? That's the
+> contributor guide — [`AGENTS.md`](./AGENTS.md) — not this file.
+
+## 1. How to import — the one rule
+
+Import from a domain-scoped **`api/<module>`** entry. Never reach into deep internal paths
+(`../components/...`, `../logics/...`); the `api/` modules are the contract and internal files move behind
+them. The `products/*` path alias is configured in tsconfig, so the import is absolute:
+
+```ts
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
+import { isTerminalRunStatus } from 'products/posthog_ai/frontend/api/logics'
+```
+
+**Prefer the narrowest module that does the job.** The split exists to preserve code-splitting: the
+side-effectful tool registry (`api/tools`) and the markdown/virtualization-heavy thread (`api/primitives`)
+must not leak into a bundle that only needs a status helper from `api/logics`. A status badge that imports
+a fat path drags presenters and the registry into its chunk; importing `api/logics` alone does not.
+
+There is deliberately **no root `index.ts` barrel** — a barrel that re-exports every tier would
+re-introduce the exact bundling problem the split solves. Always import an `api/<module>`.
+
+## 2. Which surface do I use?
+
+Pick the **lowest tier** that does the job.
+
+| Tier | Module | What's in it | Use when |
+| ------------------------------ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
+| **1 — Prepackaged surfaces** | `api/run` | `RunViewer` (call directly → default layout), `RunComposer` | "Just show/drive a run." Inbox read-only embed, tasks embed. |
+| **2 — Compound primitives** | `api/primitives` | `RunViewer.Root` + slots, `Thread` + atoms (`.Message/.Markdown/.Reasoning/.Failure/.Activity/.ToolCall`), `ThreadView`, `Composer.*`, activity primitives + `RunActivity`, message presenters, permission/question/resource surfaces | Custom layout, or a bespoke/compact thread. |
+| **3 — Headless logic + types** | `api/logics` + `api/types` | `runStreamLogic`, `runInteractionLogic`, status helpers (`isTerminalRunStatus`, `INITIAL_PERMISSION_MODE`), thinking-message helpers; folded-thread + tool types | Status badge or automation — no React, no registry. |
+| **4 — Extension seam** | `api/tools` | `toolRegistry`, `registerToolRenderers`, `lookupToolRenderer`, `GenericMcpToolRenderer`, `DataToolRow`, `ToolActivity`, `FilePath`, diff helpers | Your product renders tool cards (insights, dashboards…). Register them from your own scene. |
+
+`api/run` (Tier 1) is built on `api/primitives` (Tier 2); `api/primitives` consumes the headless
+`api/logics`/`api/types` (Tier 3). Going down a tier trades convenience for control and a smaller chunk.
+
+## 3. Recipes
+
+Each recipe shows the granular import to copy.
+
+### Read-only embed (inbox-style)
+
+```tsx
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
+;<RunViewer taskId={task.id} runId={run.id} interaction="read-only" />
+```
+
+### Live embed with composer + queue (tasks-style; caller owns draft/queue)
+
+```tsx
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
+import { runInteractionLogic, type RunInteractionLogicProps } from 'products/posthog_ai/frontend/api/logics'
+
+// Bind runInteractionLogic for the follow-up/queue facade, then render the viewer with a composer slot.
+const { queuedMessages } = useValues(runInteractionLogic(props))
+<RunViewer taskId={task.id} runId={run.id} />
+```
+
+### Custom layout via `RunViewer.Root` + slots
+
+```tsx
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
+;<RunViewer.Root taskId={task.id} runId={run.id}>
+ <RunViewer.Resources />
+ <RunViewer.Thread />
+ <RunViewer.ContextUsage />
+ <RunViewer.Composer />
+</RunViewer.Root>
+```
+
+### Bespoke / compact thread via `Thread.*` atoms
+
+```tsx
+import { Thread } from 'products/posthog_ai/frontend/api/primitives'
+
+// Compose only the atoms you want — e.g. a compact inline preview that drops the activity/tool chrome.
+;<Thread.Root items={items}>{(item) => <Thread.Message item={item} />}</Thread.Root>
+```
+
+### Register product tool renderers (Tier 4)
+
+```tsx
+import { registerToolRenderers, type ToolRegistryEntry } from 'products/posthog_ai/frontend/api/tools'
+
+// Call once from your scene's entrypoint. Tools without an adapter fall through to the generic MCP card.
+registerToolRenderers([
+ { key: 'my-product-tool', displayName: 'My tool', icon: <IconWrench />, Renderer: MyToolRenderer },
+])
+```
+
+This is the generic per-product mechanism. Max is its first consumer
+(`scenes/max/messages/adapters/registerMaxToolRenderers`), not a special case.
+
+### Headless status badge / automation
+
+```ts
+import { runStreamLogic, isTerminalRunStatus } from 'products/posthog_ai/frontend/api/logics'
+
+const { currentRunStatus } = useValues(runStreamLogic({ streamKey }))
+const done = isTerminalRunStatus(currentRunStatus)
+```
+
+No React presenters, no tool registry — this import lane stays out of those chunks.
+
+## 4. Coupling boundary
+
+This surface **couples to the tasks run API by design** (`products/tasks/frontend/generated/api`) and
+**never to Max or the conversations API** — Max is a consumer, not a dependency. The full rule (and the
+grep gate that enforces it) is in [`AGENTS.md`](./AGENTS.md#2-coupling-boundary--couples-to-tasks-runs-never-to-max).
+
+## 5. Replacement-ready by design
+
+This surface is the intended replacement for Max's legacy LangGraph thread. The new-vs-legacy switch is a
+**consumer concern** (Max routes `agent_runtime === 'sandbox'` conversations through `runStreamLogic` and
+renders this surface; its LangGraph path renders its own thread). The surface never branches on
+Max/LangGraph/conversation. Anything the LangGraph path owns that the surface doesn't express generically
+(agent modes, billing context, scene attachments) stays in Max and feeds the surface through generic props
+/ the tool registry / `streamKey` — lifted to a generic seam here, never special-cased. The four-tier
+contract above is unchanged whichever side of the switch is active. See
+[`AGENTS.md`](./AGENTS.md#6-replacement-readiness) for the contributor-side detail.
diff --git a/products/posthog_ai/frontend/api/logics.ts b/products/posthog_ai/frontend/api/logics.ts
new file mode 100644
index 000000000000..ef907a419bf1
--- /dev/null
+++ b/products/posthog_ai/frontend/api/logics.ts
@@ -0,0 +1,20 @@
+// Tier 3 — headless stream + interaction logic and thinking-message helpers. Imports only from
+// ../logics/* and ../utils/* (no component or registry imports), so it never pulls the side-effectful
+// tool registry or the markdown/virtualization chunks. Pair with ./types for a fully headless lane —
+// status badges, automation, or a consumer that drives a run without rendering the prepackaged UI.
+//
+// Part of the `products/posthog_ai/frontend/api/<module>` public surface — import from here, not from
+// deep `../logics/*` paths. See ../README.md for the tier model and ../AGENTS.md for the coupling rule.
+
+// --- Stream logic + status helpers ---
+// `runStreamLogic` keys on a generic `streamKey` (conversation id for Max, run/task id for a task
+// viewer); read `currentRunStatus` / `isTerminalRunStatus` off it for a status badge with no UI.
+export { runStreamLogic, isTerminalRunStatus, INITIAL_PERMISSION_MODE } from '../logics/runStreamLogic'
+export type { RunStreamLogicProps, RunSseStatus, RunStatus } from '../logics/runStreamLogic'
+
+// --- Interaction facade (follow-up / queue) ---
+export { runInteractionLogic } from '../logics/runInteractionLogic'
+export type { RunInteractionLogicProps, QueuedMessage } from '../logics/runInteractionLogic'
+
+// --- Thinking-message helpers ---
+export { getThinkingMessageFromResponse, getRandomThinkingMessage, THINKING_MESSAGES } from '../utils/thinkingMessages'
diff --git a/products/posthog_ai/frontend/api/primitives.ts b/products/posthog_ai/frontend/api/primitives.ts
new file mode 100644
index 000000000000..a60ec58fba5c
--- /dev/null
+++ b/products/posthog_ai/frontend/api/primitives.ts
@@ -0,0 +1,53 @@
+// Tier 2 — compound primitives & presenters: the broad presentational bucket for custom layouts and
+// bespoke threads. The Composer compound, the Thread compound + atoms, the prepackaged `ThreadView`,
+// message presenters, activity primitives, and the permission/question/resource surfaces. Use when the
+// prepackaged `RunViewer` (Tier 1, ./run) doesn't fit and you need to compose the pieces yourself —
+// e.g. a compact inline thread via `Thread.*` atoms, or a custom layout via `RunViewer.Root` + slots.
+//
+// (This is intentionally the wide presentational module; it can be subdivided later — e.g. thread.ts /
+// composer.ts — if a consumer needs finer code-splitting.)
+//
+// Part of the `products/posthog_ai/frontend/api/<module>` public surface — import from here, not from
+// deep `../components/*` paths. See ../README.md for the tier model and ../AGENTS.md for the coupling rule.
+
+// --- Composer (Radix-style compound) ---
+export { Composer } from '../components/composer/Composer'
+export type {
+ ComposerRootProps,
+ ComposerFrameProps,
+ ComposerTextareaProps,
+ ComposerSubmitProps,
+} from '../components/composer/Composer'
+
+// --- Thread + message presenters ---
+// `Thread` is the Radix-style compound (Root + Message/Markdown/Reasoning/Failure/Activity/ToolCall
+// atoms); `ThreadView` is the prepackaged virtualized presenter (also `Thread.Root`).
+export { Thread } from '../components/Thread'
+export { ThreadView } from '../components/ThreadView'
+export { MessageTemplate } from '../messages/MessageTemplate'
+export { MarkdownMessage } from '../messages/MarkdownMessage'
+export { ReasoningAnswer } from '../messages/ReasoningAnswer'
+export type { ReasoningAnswerProps } from '../messages/ReasoningAnswer'
+export { AssistantFailureMessage } from '../messages/AssistantFailureMessage'
+
+// --- Activity primitives ---
+export {
+ Activity,
+ ActivityDetails,
+ ActivityHeader,
+ ActivityStatusIcon,
+ ActivitySubsteps,
+ ActivityToggleSection,
+ ShimmeringContent,
+} from '../components/ActivityPrimitives'
+export type { ActivityStatus } from '../components/ActivityPrimitives'
+export { RunActivity } from '../components/RunActivity'
+
+// --- Permission / question / resource surfaces ---
+export { PermissionInput } from '../components/PermissionInput'
+export { QuestionInput } from '../components/QuestionInput'
+export { ResourcesBar } from '../components/ResourcesBar'
+export { ContextUsageBar } from '../components/ContextUsageBar'
+export { QuestionField, MultiFieldQuestion, isFieldValid } from '../components/QuestionField'
+export { OptionSelector } from '../components/OptionSelector'
+export type { Option } from '../components/OptionSelector'
diff --git a/products/posthog_ai/frontend/api/run.ts b/products/posthog_ai/frontend/api/run.ts
new file mode 100644
index 000000000000..33539e9a9531
--- /dev/null
+++ b/products/posthog_ai/frontend/api/run.ts
@@ -0,0 +1,4 @@
+export { RunViewer } from '../components/RunViewer'
+export type { RunViewerRootProps, RunViewerProps } from '../components/RunViewer'
+export { RunComposer } from '../components/RunComposer'
+export type { RunComposerProps } from '../components/RunComposer'
diff --git a/products/posthog_ai/frontend/api/tools.ts b/products/posthog_ai/frontend/api/tools.ts
new file mode 100644
index 000000000000..09fb941792a7
--- /dev/null
+++ b/products/posthog_ai/frontend/api/tools.ts
@@ -0,0 +1,9 @@
+export { toolRegistry, lookupToolRenderer, registerToolRenderers } from '../components/tool/toolRegistry'
+export type { ToolRendererProps, ToolRegistryEntry, ToolRegistry } from '../components/tool/toolRegistry'
+export { GenericMcpToolRenderer } from '../components/tool/GenericMcpToolRenderer'
+export { DataToolRow } from '../components/tool/DataToolRow'
+export { ToolActivity } from '../components/tool/ToolActivity'
+export type { ToolActivityProps } from '../components/tool/ToolActivity'
+export { FilePath } from '../components/tool/FilePath'
+export { findAllDiffContent, getDiffStats, languageFromPath } from '../components/tool/toolDiffContent'
+export type { ToolCallDiffContent } from '../components/tool/toolDiffContent'
diff --git a/products/posthog_ai/frontend/api/types.ts b/products/posthog_ai/frontend/api/types.ts
new file mode 100644
index 000000000000..ab8ef8955fc8
--- /dev/null
+++ b/products/posthog_ai/frontend/api/types.ts
@@ -0,0 +1,9 @@
+export type {
+ ThreadItem,
+ ToolInvocation,
+ PermissionRequestRecord,
+ ContextUsage,
+ RunArtifacts,
+ ProgressStep,
+} from '../types/streamTypes'
+export type { ToolCallMessage } from '../types/toolTypes'
diff --git a/products/posthog_ai/frontend/components/tool/toolRegistry.test.tsx b/products/posthog_ai/frontend/components/tool/toolRegistry.test.tsx
index a5797a17eedd..bc00458934a0 100644
--- a/products/posthog_ai/frontend/components/tool/toolRegistry.test.tsx
+++ b/products/posthog_ai/frontend/components/tool/toolRegistry.test.tsx
@@ -5,7 +5,7 @@ import { render, screen } from '@testing-library/react'
import type { ToolCallMessage } from 'products/posthog_ai/frontend/types/toolTypes'
import { ToolCallCard } from './ToolCallCard'
-import { lookupToolRenderer, toolRegistry } from './toolRegistry'
+import { lookupToolRenderer, registerToolRenderers, toolRegistry, type ToolRegistryEntry } from './toolRegistry'
function makeMessage(overrides: Partial<ToolCallMessage> = {}): ToolCallMessage {
return {
@@ -26,6 +26,17 @@ describe('toolRegistry', () => {
// `registerMaxToolRenderers` and covered by that module's own test. Here we assert only what the
// shared, Max-free registry registers: built-ins, exec verbs, the question card, and the fallback.
+ it('bulk-registers every entry it is handed', () => {
+ const Renderer = (() => null) as unknown as ToolRegistryEntry['Renderer']
+ const icon = null as unknown as JSX.Element
+ registerToolRenderers([
+ { key: '__test_alpha__', displayName: 'Alpha', icon, Renderer },
+ { key: '__test_beta__', displayName: 'Beta', icon, Renderer },
+ ])
+ expect(toolRegistry.lookup('__test_alpha__')?.displayName).toEqual('Alpha')
+ expect(toolRegistry.lookup('__test_beta__')?.displayName).toEqual('Beta')
+ })
+
it('leaves product-specific and unknown tool names unregistered, resolving to the key as displayName', () => {
expect(toolRegistry.lookup('mcp__user-installed__something')).toBeNull()
// The synthesized fallback uses the resolved key as its displayName.
diff --git a/products/posthog_ai/frontend/components/tool/toolRegistry.tsx b/products/posthog_ai/frontend/components/tool/toolRegistry.tsx
index d70ae0eddeed..b10757d56e3d 100644
--- a/products/posthog_ai/frontend/components/tool/toolRegistry.tsx
+++ b/products/posthog_ai/frontend/components/tool/toolRegistry.tsx
@@ -85,6 +85,17 @@ const QuestionRenderer = lazy(() => import('../QuestionRenderer').then((m) => ({
*/
export const toolRegistry: ToolRegistry = new MapBackedRegistry()
+/**
+ * Bulk-register tool renderers into the shared registry. The generic per-product seam: a product
+ * registers its tool cards from its own scene's entrypoint (as Max does via `registerMaxToolRenderers`).
+ * `toolRegistry.register` stays available for single-entry use.
+ */
+export function registerToolRenderers(entries: ToolRegistryEntry[]): void {
+ for (const entry of entries) {
+ toolRegistry.register(entry)
+ }
+}
+
// Product-specific data-tool renderers (insight, dashboard, session recordings, error tracking,
// notebooks, query wrappers) are NOT registered here — they live in scenes/max and register themselves
// into this registry via `registerMaxToolRenderers` so this surface stays free of any scenes/max import.
diff --git a/products/posthog_ai/frontend/index.ts b/products/posthog_ai/frontend/index.ts
deleted file mode 100644
index b0f72373b00d..000000000000
--- a/products/posthog_ai/frontend/index.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-// Public component API of the PostHog AI agent-run surface — the conversation-agnostic agent UI.
-// Every external consumer (tasks, the signals inbox, and the Max scene in scenes/max) imports from
-// THIS barrel, never from deep subtree paths, so the internal layout can move without touching them.
-//
-// Coupling boundary: this surface couples to the tasks run API (`products/tasks/frontend/generated/api`)
-// by design — task + taskrun + streaming together ARE the surface. It must never import the conversations
-// API or Max conversation orchestration (`scenes/max/*`, `maxThreadLogic`, `maxContextLogic`, `MaxUIContext`):
-// Max is a consumer of this surface, not a dependency of it.
-
-// --- Embeddable run surface ---
-// `RunViewer` is the Radix-style compound (Root + Thread/Prompt/Composer/Resources/ContextUsage slots);
-// called directly (`<RunViewer .../>`) it renders the prepackaged default layout for the common embed.
-export { RunViewer } from './components/RunViewer'
-export type { RunViewerRootProps, RunViewerProps } from './components/RunViewer'
-export { RunComposer } from './components/RunComposer'
-export type { RunComposerProps } from './components/RunComposer'
-
-// --- Composer (Radix-style compound) ---
-export { Composer } from './components/composer/Composer'
-export type {
- ComposerRootProps,
- ComposerFrameProps,
- ComposerTextareaProps,
- ComposerSubmitProps,
-} from './components/composer/Composer'
-
-// --- Thread + message presenters ---
-// `Thread` is the Radix-style compound (Root + Message/Markdown/Reasoning/Failure/Activity/ToolCall atoms);
-// `ThreadView` is the prepackaged virtualized presenter (also `Thread.Root`).
-export { Thread } from './components/Thread'
-export { ThreadView } from './components/ThreadView'
-export { MessageTemplate } from './messages/MessageTemplate'
-export { MarkdownMessage } from './messages/MarkdownMessage'
-export { ReasoningAnswer } from './messages/ReasoningAnswer'
-export type { ReasoningAnswerProps } from './messages/ReasoningAnswer'
-export { AssistantFailureMessage } from './messages/AssistantFailureMessage'
-
-// --- Activity primitives ---
-export {
- Activity,
- ActivityDetails,
- ActivityHeader,
- ActivityStatusIcon,
- ActivitySubsteps,
- ActivityToggleSection,
- ShimmeringContent,
-} from './components/ActivityPrimitives'
-export type { ActivityStatus } from './components/ActivityPrimitives'
-export { RunActivity } from './components/RunActivity'
-
-// --- Tool rendering + registry ---
-export { toolRegistry, lookupToolRenderer } from './components/tool/toolRegistry'
-export type { ToolRendererProps, ToolRegistryEntry, ToolRegistry } from './components/tool/toolRegistry'
-export { GenericMcpToolRenderer } from './components/tool/GenericMcpToolRenderer'
-export { DataToolRow } from './components/tool/DataToolRow'
-export { ToolActivity } from './components/tool/ToolActivity'
-export type { ToolActivityProps } from './components/tool/ToolActivity'
-export { FilePath } from './components/tool/FilePath'
-export { findAllDiffContent, getDiffStats, languageFromPath } from './components/tool/toolDiffContent'
-export type { ToolCallDiffContent } from './components/tool/toolDiffContent'
-
-// --- Questions / multi-field forms ---
-export { QuestionField, MultiFieldQuestion, isFieldValid } from './components/QuestionField'
-export { OptionSelector } from './components/OptionSelector'
-export type { Option } from './components/OptionSelector'
-
-// --- Stream logic + interaction facade ---
-export { runStreamLogic, isTerminalRunStatus, INITIAL_PERMISSION_MODE } from './logics/runStreamLogic'
-export type { RunStreamLogicProps, RunSseStatus, RunStatus } from './logics/runStreamLogic'
-export { runInteractionLogic } from './logics/runInteractionLogic'
-export type { RunInteractionLogicProps, QueuedMessage } from './logics/runInteractionLogic'
-
-// --- Permission / question / resource surfaces ---
-export { PermissionInput } from './components/PermissionInput'
-export { QuestionInput } from './components/QuestionInput'
-export { ResourcesBar } from './components/ResourcesBar'
-export { ContextUsageBar } from './components/ContextUsageBar'
-
-// --- Thinking-message helpers ---
-export { getThinkingMessageFromResponse, getRandomThinkingMessage, THINKING_MESSAGES } from './utils/thinkingMessages'
-
-// --- Types ---
-export type {
- ThreadItem,
- ToolInvocation,
- PermissionRequestRecord,
- ContextUsage,
- RunArtifacts,
- ProgressStep,
-} from './types/streamTypes'
-export type { ToolCallMessage } from './types/toolTypes'
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunChat.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunChat.tsx
index 48e0ad9e9718..47fcf5ea37a2 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunChat.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunChat.tsx
@@ -1,6 +1,7 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { RunViewer, type RunInteractionLogicProps, runInteractionLogic } from 'products/posthog_ai/frontend'
+import { runInteractionLogic, type RunInteractionLogicProps } from 'products/posthog_ai/frontend/api/logics'
+import { RunViewer } from 'products/posthog_ai/frontend/api/run'
import { taskDetailSceneLogic } from '../taskDetailSceneLogic'