: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
chore(devex): move AI/LLM models to product apps (#61346)
Julian Bezf03892f47ffd
diff --git a/ee/api/conversation.py b/ee/api/conversation.pyindex 3e78a39fab60..322364ce9058 100644--- a/ee/api/conversation.py+++ b/ee/api/conversation.py@@ -50,6 +50,8 @@ from posthog.temporal.ai.research_agent import (ResearchAgentWorkflowInputs,)+from products.posthog_ai.backend.models.assistant import Conversation+from ee.billing.quota_limiting import QuotaLimitingCaches, QuotaResource, is_team_limitedfrom ee.hogai.api.serializers import ConversationMinimalSerializer, ConversationSerializerfrom ee.hogai.chat_agent import AssistantGraph@@ -60,7 +62,6 @@ from ee.hogai.stream.redis_stream import get_conversation_stream_keyfrom ee.hogai.utils.aio import async_to_syncfrom ee.hogai.utils.sse import AssistantSSESerializerfrom ee.hogai.utils.types import PartialAssistantState-from ee.models.assistant import Conversationlogger = structlog.get_logger(__name__)diff --git a/ee/api/core_memory.py b/ee/api/core_memory.pyindex 780ffd42cbf8..91b96f94b32e 100644--- a/ee/api/core_memory.py+++ b/ee/api/core_memory.py@@ -6,7 +6,7 @@ from rest_framework.viewsets import GenericViewSetfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.exceptions import Conflict-from ee.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemory+from products.posthog_ai.backend.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemoryclass MaxCoreMemorySerializer(serializers.ModelSerializer):diff --git a/ee/api/hands_free.py b/ee/api/hands_free.pyindex f24a041ff271..9fe48a416250 100644--- a/ee/api/hands_free.py+++ b/ee/api/hands_free.py@@ -35,7 +35,7 @@ from posthog.rate_limit import (MaxHandsFreeTokenSustainedRateThrottle,)-from ee.models.assistant import Conversation+from products.posthog_ai.backend.models.assistant import Conversationlogger = structlog.get_logger(__name__)diff --git a/ee/api/max_tools.py b/ee/api/max_tools.pyindex d6a31d9d37f6..c6885767a6eb 100644--- a/ee/api/max_tools.py+++ b/ee/api/max_tools.py@@ -17,8 +17,9 @@ from posthog.models.user import Userfrom posthog.rate_limit import AIBurstRateThrottle, AISustainedRateThrottlefrom posthog.renderers import SafeJSONRenderer+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.utils.types import AssistantState-from ee.models.assistant import Conversationclass InsightsToolCallSerializer(serializers.Serializer):diff --git a/ee/api/test/test_conversation.py b/ee/api/test/test_conversation.pyindex 94bc3f1d5d9a..fb82bebbb34e 100644--- a/ee/api/test/test_conversation.py+++ b/ee/api/test/test_conversation.py@@ -30,8 +30,9 @@ from posthog.models.user import Userfrom posthog.temporal.ai.chat_agent import ChatAgentWorkflow, ChatAgentWorkflowInputsfrom posthog.temporal.ai.research_agent import ResearchAgentWorkflow, ResearchAgentWorkflowInputs+from products.posthog_ai.backend.models.assistant import Conversation+from ee.api.conversation import ConversationViewSet-from ee.models.assistant import Conversationasync def _async_generator():diff --git a/ee/api/test/test_conversation_queue.py b/ee/api/test/test_conversation_queue.pyindex 365bc9f2c744..540e34874bbe 100644--- a/ee/api/test/test_conversation_queue.py+++ b/ee/api/test/test_conversation_queue.py@@ -7,8 +7,9 @@ from rest_framework import statusfrom posthog.models import Teamfrom posthog.models.user import User+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.queue import ConversationQueueStore, build_queue_message-from ee.models.assistant import Conversationclass TestConversationQueue(APIBaseTest):diff --git a/ee/api/test/test_core_memory.py b/ee/api/test/test_core_memory.pyindex ad25da16ceea..98155d22df54 100644--- a/ee/api/test/test_core_memory.py+++ b/ee/api/test/test_core_memory.py@@ -8,7 +8,7 @@ from rest_framework import statusfrom posthog.models.team.team import Team-from ee.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemory+from products.posthog_ai.backend.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemoryclass TestCoreMemoryAPI(APIBaseTest):diff --git a/ee/hogai/api/serializers.py b/ee/hogai/api/serializers.pyindex 53abea25192e..176ab17873a0 100644--- a/ee/hogai/api/serializers.py+++ b/ee/hogai/api/serializers.py@@ -8,6 +8,8 @@ from rest_framework import serializersfrom posthog.api.shared import UserBasicSerializerfrom posthog.exceptions_capture import capture_exception+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.research_agent.graph import ResearchAgentGraph@@ -15,7 +17,6 @@ from ee.hogai.tool import PENDING_APPROVAL_STATUSfrom ee.hogai.utils.helpers import should_output_assistant_messagefrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.composed import AssistantMaxGraphState-from ee.models.assistant import Conversation_conversation_fields = ["id",diff --git a/ee/hogai/api/test/test_serializers.py b/ee/hogai/api/test/test_serializers.pyindex 1adff365aa09..11852b8cf8ac 100644--- a/ee/hogai/api/test/test_serializers.py+++ b/ee/hogai/api/test/test_serializers.py@@ -12,11 +12,12 @@ from posthog.schema import (ContextMessage,)+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation+from ee.hogai.api.serializers import ConversationSerializerfrom ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import AgentArtifact, Conversationclass TestConversationSerializers(APIBaseTest):diff --git a/ee/hogai/artifacts/handlers/base.py b/ee/hogai/artifacts/handlers/base.pyindex 93843f8ca943..da58380aa8a7 100644--- a/ee/hogai/artifacts/handlers/base.py+++ b/ee/hogai/artifacts/handlers/base.py@@ -11,8 +11,9 @@ from posthog.schema import ArtifactContentTypefrom posthog.models import Team+from products.posthog_ai.backend.models.assistant import AgentArtifact+from ee.hogai.utils.types.base import AssistantMessageUnion-from ee.models.assistant import AgentArtifact# Type variables for handler generics - bound to BaseModel for model_validate()T_Stored = TypeVar("T_Stored", bound=BaseModel) # Stored content type (in DB)diff --git a/ee/hogai/artifacts/handlers/notebook.py b/ee/hogai/artifacts/handlers/notebook.pyindex c683981227c7..f39163d28f5f 100644--- a/ee/hogai/artifacts/handlers/notebook.py+++ b/ee/hogai/artifacts/handlers/notebook.py@@ -10,6 +10,7 @@ from posthog.schema import ArtifactContentType, ErrorBlock, NotebookArtifactContfrom posthog.models import Teamfrom products.notebooks.backend.models import Notebook+from products.posthog_ai.backend.models.assistant import AgentArtifactfrom ee.hogai.artifacts.handlers.base import (ArtifactHandler,@@ -26,7 +27,6 @@ from ee.hogai.artifacts.types import ()from ee.hogai.context.insight.query_executor import is_supported_queryfrom ee.hogai.utils.types.base import AssistantMessageUnion-from ee.models.assistant import AgentArtifact@register_handlerdiff --git a/ee/hogai/artifacts/handlers/visualization.py b/ee/hogai/artifacts/handlers/visualization.pyindex d6e9c2b91aad..8daed5d982cd 100644--- a/ee/hogai/artifacts/handlers/visualization.py+++ b/ee/hogai/artifacts/handlers/visualization.py@@ -9,6 +9,7 @@ from posthog.schema import ArtifactContentType, ArtifactSource, VisualizationArtfrom posthog.models import Team+from products.posthog_ai.backend.models.assistant import AgentArtifactfrom products.product_analytics.backend.models.insight import Insightfrom ee.hogai.artifacts.handlers.base import ArtifactHandler, EnrichmentContext, register_handler@@ -20,7 +21,6 @@ from ee.hogai.artifacts.types import ()from ee.hogai.context.insight.context import InsightContextfrom ee.hogai.utils.types.base import AssistantMessageUnion-from ee.models.assistant import AgentArtifact@register_handlerdiff --git a/ee/hogai/artifacts/manager.py b/ee/hogai/artifacts/manager.pyindex e230fd27de18..e4bfb9f7f763 100644--- a/ee/hogai/artifacts/manager.py+++ b/ee/hogai/artifacts/manager.py@@ -9,6 +9,8 @@ from posthog.schema import ArtifactContentType, ArtifactMessage, ArtifactSource,from posthog.models import Userfrom posthog.models.team import Team+from products.posthog_ai.backend.models.assistant import AgentArtifact+from ee.hogai.artifacts.handlers import (EnrichmentContext,NotebookArtifactManagerMixin,@@ -20,7 +22,6 @@ from ee.hogai.artifacts.handlers import (from ee.hogai.artifacts.types import ArtifactContent, ContentT, StoredContentfrom ee.hogai.core.mixins import AssistantContextMixinfrom ee.hogai.utils.types.base import ArtifactRefMessage, AssistantMessageUnion-from ee.models.assistant import AgentArtifactclass ArtifactManager(diff --git a/ee/hogai/artifacts/test/test_manager.py b/ee/hogai/artifacts/test/test_manager.pyindex d868c8200511..12876139e457 100644--- a/ee/hogai/artifacts/test/test_manager.py+++ b/ee/hogai/artifacts/test/test_manager.py@@ -26,12 +26,12 @@ from posthog.schema import (VisualizationMessage,)+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversationfrom products.product_analytics.backend.models.insight import Insightfrom ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.artifacts.types import StoredNotebookArtifactContentfrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import AgentArtifact, Conversationclass TestArtifactManagerCreateMessage(BaseTest):diff --git a/ee/hogai/chat_agent/funnels/test/test_nodes.py b/ee/hogai/chat_agent/funnels/test/test_nodes.pyindex 724becef7f5b..dd381e782e09 100644--- a/ee/hogai/chat_agent/funnels/test/test_nodes.py+++ b/ee/hogai/chat_agent/funnels/test/test_nodes.py@@ -11,10 +11,11 @@ from posthog.schema import (HumanMessage,)+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.funnels.nodes import FunnelGeneratorNode, FunnelsSchemaGeneratorOutputfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import Conversationclass TestFunnelsGeneratorNode(BaseTest):diff --git a/ee/hogai/chat_agent/insights/test/test_nodes.py b/ee/hogai/chat_agent/insights/test/test_nodes.pyindex 06df4cdfa4c5..09d6ec63add7 100644--- a/ee/hogai/chat_agent/insights/test/test_nodes.py+++ b/ee/hogai/chat_agent/insights/test/test_nodes.py@@ -20,13 +20,13 @@ from posthog.schema import (VisualizationArtifactContent,)+from products.posthog_ai.backend.models.assistant import Conversationfrom products.product_analytics.backend.models.insight import Insight, InsightViewedfrom ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.chat_agent.insights.nodes import InsightDict, InsightSearchNode, NoInsightsExceptionfrom ee.hogai.utils.types import AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import Conversationdef create_mock_query_executor():diff --git a/ee/hogai/chat_agent/memory/nodes.py b/ee/hogai/chat_agent/memory/nodes.pyindex d449e361aa4b..161c2fe01984 100644--- a/ee/hogai/chat_agent/memory/nodes.py+++ b/ee/hogai/chat_agent/memory/nodes.py@@ -36,6 +36,8 @@ from posthog.hogql_queries.query_runner import ExecutionModefrom posthog.sync import database_sync_to_asyncfrom posthog.utils import human_list+from products.posthog_ai.backend.models.assistant import CoreMemory+from ee.hogai.artifacts.utils import unwrap_visualization_artifact_contentfrom ee.hogai.core.agent_modes import SlashCommandNamefrom ee.hogai.core.mixins import AssistantContextMixin@@ -46,7 +48,6 @@ from ee.hogai.utils.markdown import remove_markdownfrom ee.hogai.utils.prompt import format_prompt_stringfrom ee.hogai.utils.types import AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import CoreMemoryfrom .parsers import check_memory_collection_completed, compressed_memory_parserfrom .prompts import (diff --git a/ee/hogai/chat_agent/memory/test/test_nodes.py b/ee/hogai/chat_agent/memory/test/test_nodes.pyindex 6288f66b04ea..3fc9f1f7b52c 100644--- a/ee/hogai/chat_agent/memory/test/test_nodes.py+++ b/ee/hogai/chat_agent/memory/test/test_nodes.py@@ -23,6 +23,8 @@ from langgraph.errors import NodeInterruptfrom posthog.schema import AssistantMessage, ContextMessage, EventTaxonomyItem, HumanMessage+from products.posthog_ai.backend.models.assistant import CoreMemory+from ee.hogai.chat_agent.memory import promptsfrom ee.hogai.chat_agent.memory.nodes import (MemoryCollectorNode,@@ -37,7 +39,6 @@ from ee.hogai.chat_agent.memory.nodes import ()from ee.hogai.core.agent_modes import SlashCommandNamefrom ee.hogai.utils.types import AssistantState, PartialAssistantState-from ee.models import CoreMemoryclass TestMemoryInitializerContextMixin(ClickhouseTestMixin, NonAtomicBaseTest):diff --git a/ee/hogai/chat_agent/query_executor/test/test_nodes.py b/ee/hogai/chat_agent/query_executor/test/test_nodes.pyindex 22334a0437c4..bdda6a4f641a 100644--- a/ee/hogai/chat_agent/query_executor/test/test_nodes.py+++ b/ee/hogai/chat_agent/query_executor/test/test_nodes.py@@ -28,6 +28,8 @@ from posthog.schema import (from posthog.api.services.query import process_query_dict+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation+from ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.chat_agent.query_executor.nodes import QueryExecutorNodefrom ee.hogai.context.insight.prompts import (@@ -39,7 +41,6 @@ from ee.hogai.context.insight.prompts import ()from ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage, PartialAssistantState-from ee.models import AgentArtifact, Conversationclass TestQueryExecutorNode(ClickhouseTestMixin, NonAtomicBaseTest):diff --git a/ee/hogai/chat_agent/query_planner/test/test_nodes.py b/ee/hogai/chat_agent/query_planner/test/test_nodes.pyindex f57c46dbcedd..2d6c4f537f9a 100644--- a/ee/hogai/chat_agent/query_planner/test/test_nodes.py+++ b/ee/hogai/chat_agent/query_planner/test/test_nodes.py@@ -22,11 +22,12 @@ from posthog.schema import (from posthog.test.test_utils import create_group_type_mapping_without_created_at+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation+from ee.hogai.chat_agent.query_planner.nodes import QueryPlannerNode, QueryPlannerToolsNodefrom ee.hogai.chat_agent.query_planner.toolkit import TaxonomyAgentToolkitfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models import AgentArtifact, Conversationclass DummyToolkit(TaxonomyAgentToolkit):diff --git a/ee/hogai/chat_agent/retention/test/test_nodes.py b/ee/hogai/chat_agent/retention/test/test_nodes.pyindex 147d5eb2dc45..931608df9876 100644--- a/ee/hogai/chat_agent/retention/test/test_nodes.py+++ b/ee/hogai/chat_agent/retention/test/test_nodes.py@@ -14,11 +14,11 @@ from posthog.schema import ()from products.actions.backend.models.action import Action+from products.posthog_ai.backend.models.assistant import Conversationfrom ee.hogai.chat_agent.retention.nodes import RetentionGeneratorNode, RetentionSchemaGeneratorOutputfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import Conversationclass TestRetentionGeneratorNode(BaseTest):diff --git a/ee/hogai/chat_agent/runner.py b/ee/hogai/chat_agent/runner.pyindex 6bfce4fb7c4e..2f6f57d0859c 100644--- a/ee/hogai/chat_agent/runner.py+++ b/ee/hogai/chat_agent/runner.py@@ -11,12 +11,13 @@ from posthog import event_usagefrom posthog.models import Team, Userfrom posthog.sync import database_sync_to_async+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.chat_agent.stream_processor import ChatAgentStreamProcessorfrom ee.hogai.chat_agent.taxonomy.types import TaxonomyNodeNamefrom ee.hogai.core.runner import BaseAgentRunnerfrom ee.hogai.utils.types import AssistantNodeName, AssistantOutput, AssistantState, PartialAssistantState-from ee.models import Conversation_tracer = trace.get_tracer(__name__)diff --git a/ee/hogai/chat_agent/schema_generator/test/test_nodes.py b/ee/hogai/chat_agent/schema_generator/test/test_nodes.pyindex 879d565bf316..60a17aa2c52b 100644--- a/ee/hogai/chat_agent/schema_generator/test/test_nodes.py+++ b/ee/hogai/chat_agent/schema_generator/test/test_nodes.py@@ -19,6 +19,8 @@ from posthog.schema import (VisualizationArtifactContent,)+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation+from ee.hogai.chat_agent.schema_generator.nodes import (RETRIES_ALLOWED,SchemaGenerationException,@@ -29,7 +31,6 @@ from ee.hogai.chat_agent.schema_generator.parsers import PydanticOutputParserExcfrom ee.hogai.chat_agent.schema_generator.utils import SchemaGeneratorOutputfrom ee.hogai.utils.types import AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage, IntermediateStep-from ee.models import AgentArtifact, ConversationDummySchema = SchemaGeneratorOutput[AssistantTrendsQuery]diff --git a/ee/hogai/chat_agent/slash_commands/commands/remember/command.py b/ee/hogai/chat_agent/slash_commands/commands/remember/command.pyindex d7fe0af7a307..71a4979323a7 100644--- a/ee/hogai/chat_agent/slash_commands/commands/remember/command.py+++ b/ee/hogai/chat_agent/slash_commands/commands/remember/command.py@@ -4,10 +4,11 @@ from langchain_core.runnables import RunnableConfigfrom posthog.schema import AssistantMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import CoreMemory+from ee.hogai.chat_agent.slash_commands.commands import SlashCommandfrom ee.hogai.core.agent_modes import SlashCommandNamefrom ee.hogai.utils.types import AssistantState, PartialAssistantState-from ee.models.assistant import CoreMemoryclass RememberCommand(SlashCommand):diff --git a/ee/hogai/chat_agent/slash_commands/commands/remember/test/test_remember.py b/ee/hogai/chat_agent/slash_commands/commands/remember/test/test_remember.pyindex 6bbbf0062a18..26665832ab19 100644--- a/ee/hogai/chat_agent/slash_commands/commands/remember/test/test_remember.py+++ b/ee/hogai/chat_agent/slash_commands/commands/remember/test/test_remember.py@@ -6,9 +6,10 @@ from langchain_core.runnables import RunnableConfigfrom posthog.schema import AssistantMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemory+from ee.hogai.chat_agent.slash_commands.commands.remember import RememberCommandfrom ee.hogai.utils.types import AssistantState-from ee.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemoryclass TestRememberCommand(BaseTest):diff --git a/ee/hogai/chat_agent/slash_commands/commands/usage/queries.py b/ee/hogai/chat_agent/slash_commands/commands/usage/queries.pyindex 144b148120bd..8efb5d5ce11d 100644--- a/ee/hogai/chat_agent/slash_commands/commands/usage/queries.py+++ b/ee/hogai/chat_agent/slash_commands/commands/usage/queries.py@@ -16,7 +16,7 @@ from posthog.tasks.usage_report import ()from posthog.utils import get_instance_region-from ee.models.assistant import Conversation+from products.posthog_ai.backend.models.assistant import Conversation# Default free tier limit in creditsDEFAULT_FREE_TIER_CREDITS = 2000diff --git a/ee/hogai/chat_agent/slash_commands/commands/usage/test/test_usage.py b/ee/hogai/chat_agent/slash_commands/commands/usage/test/test_usage.pyindex dc657471b207..de2f67cb8101 100644--- a/ee/hogai/chat_agent/slash_commands/commands/usage/test/test_usage.py+++ b/ee/hogai/chat_agent/slash_commands/commands/usage/test/test_usage.py@@ -7,6 +7,8 @@ from unittest.mock import patchfrom parameterized import parameterized+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.slash_commands.commands.usage.queries import (CLOUD_REGION_TO_TEAM_ID,CLOUD_REGION_TO_URL,@@ -19,7 +21,6 @@ from ee.hogai.chat_agent.slash_commands.commands.usage.queries import (get_ga_launch_date,get_past_month_start,)-from ee.models.assistant import Conversationclass TestUsage(BaseTest):diff --git a/ee/hogai/chat_agent/sql/test/test_nodes.py b/ee/hogai/chat_agent/sql/test/test_nodes.pyindex e5d641c04cc4..4cd8505dec52 100644--- a/ee/hogai/chat_agent/sql/test/test_nodes.py+++ b/ee/hogai/chat_agent/sql/test/test_nodes.py@@ -5,10 +5,11 @@ from langchain_core.runnables import RunnableConfig, RunnableLambdafrom posthog.schema import ArtifactContentType, ArtifactSource, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.sql.nodes import SQLGeneratorNodefrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import Conversationclass TestSQLGeneratorNode(NonAtomicBaseTest):diff --git a/ee/hogai/chat_agent/test/test_assistant_graph.py b/ee/hogai/chat_agent/test/test_assistant_graph.pyindex 4a7907e6ec20..5626c5272f6f 100644--- a/ee/hogai/chat_agent/test/test_assistant_graph.py+++ b/ee/hogai/chat_agent/test/test_assistant_graph.py@@ -2,11 +2,12 @@ from posthog.test.base import BaseTestfrom langgraph.checkpoint.memory import InMemorySaver+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.base import BaseAssistantGraphfrom ee.hogai.core.node import AssistantNodefrom ee.hogai.utils.types import AssistantNodeName, AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import AssistantGraphName-from ee.models import Conversationclass TestAssistantGraph(BaseTest):diff --git a/ee/hogai/chat_agent/test/test_chat_agent.py b/ee/hogai/chat_agent/test/test_chat_agent.pyindex 108879144bdc..0698dfa981fc 100644--- a/ee/hogai/chat_agent/test/test_chat_agent.py+++ b/ee/hogai/chat_agent/test/test_chat_agent.py@@ -51,6 +51,7 @@ from posthog.schema import ()from products.actions.backend.models.action import Action+from products.posthog_ai.backend.models.assistant import Conversation, CoreMemoryfrom ee.hogai.chat_agent.funnels.nodes import FunnelsSchemaGeneratorOutputfrom ee.hogai.chat_agent.graph import AssistantGraph@@ -66,7 +67,6 @@ from ee.hogai.test.base import BaseAssistantTestfrom ee.hogai.utils.tests import FakeAnthropicRunnableLambdaWithTokenCounter, FakeChatAnthropic, FakeChatOpenAIfrom ee.hogai.utils.types import AssistantNodeName, AssistantOutput, AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage, ReplaceMessages-from ee.models.assistant import Conversation, CoreMemorytitle_generator_mock = patch("ee.hogai.core.title_generator.nodes.TitleGeneratorNode._model",diff --git a/ee/hogai/chat_agent/test/test_runner.py b/ee/hogai/chat_agent/test/test_runner.pyindex ef2d1d72873a..9fcbc68510ba 100644--- a/ee/hogai/chat_agent/test/test_runner.py+++ b/ee/hogai/chat_agent/test/test_runner.py@@ -3,8 +3,9 @@ from unittest.mock import MagicMock, patchfrom posthog.schema import AgentMode, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.runner import ChatAgentRunner-from ee.models.assistant import Conversationclass TestChatAgentRunner(BaseTest):diff --git a/ee/hogai/chat_agent/test/test_stream_processor.py b/ee/hogai/chat_agent/test/test_stream_processor.pyindex c5e41fe73360..ddc112131632 100644--- a/ee/hogai/chat_agent/test/test_stream_processor.py+++ b/ee/hogai/chat_agent/test/test_stream_processor.py@@ -32,6 +32,8 @@ from posthog.schema import (VisualizationMessage,)+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation+from ee.hogai.chat_agent.stream_processor import ChatAgentStreamProcessorfrom ee.hogai.utils.state import GraphValueUpdateTuplefrom ee.hogai.utils.types.base import (@@ -48,7 +50,6 @@ from ee.hogai.utils.types.base import (NodeStartAction,UpdateAction,)-from ee.models.assistant import AgentArtifact, Conversationclass TestStreamProcessor(BaseTest):diff --git a/ee/hogai/chat_agent/trends/test/test_nodes.py b/ee/hogai/chat_agent/trends/test/test_nodes.pyindex fd8758e12647..7a492dc64c1f 100644--- a/ee/hogai/chat_agent/trends/test/test_nodes.py+++ b/ee/hogai/chat_agent/trends/test/test_nodes.py@@ -5,10 +5,11 @@ from langchain_core.runnables import RunnableConfig, RunnableLambdafrom posthog.schema import ArtifactContentType, ArtifactSource, AssistantTrendsQuery, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.trends.nodes import TrendsGeneratorNode, TrendsSchemaGeneratorOutputfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import Conversationclass TestTrendsGeneratorNode(BaseTest):diff --git a/ee/hogai/core/executor.py b/ee/hogai/core/executor.pyindex 5b173f4e6784..98a84cdea89d 100644--- a/ee/hogai/core/executor.py+++ b/ee/hogai/core/executor.py@@ -19,6 +19,8 @@ from posthog.schema import AssistantEventType, FailureMessagefrom posthog.temporal.ai.base import AgentBaseWorkflowfrom posthog.temporal.common.client import async_connect+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.queue import ConversationQueueStorefrom ee.hogai.stream.redis_stream import (CONVERSATION_STREAM_MAX_LENGTH,@@ -33,7 +35,6 @@ from ee.hogai.stream.redis_stream import (get_conversation_stream_key,)from ee.hogai.utils.types import AssistantOutput-from ee.models.assistant import Conversationlogger = structlog.get_logger(__name__)_tracer = trace.get_tracer(__name__)diff --git a/ee/hogai/core/mixins.py b/ee/hogai/core/mixins.pyindex 96276bdb67cd..282113161d83 100644--- a/ee/hogai/core/mixins.py+++ b/ee/hogai/core/mixins.py@@ -14,12 +14,12 @@ from posthog.models import Teamfrom posthog.models.user import Userfrom products.actions.backend.models.action import Action+from products.posthog_ai.backend.models.assistant import Conversation, CoreMemoryfrom ee.hogai.utils.dispatcher import AssistantDispatcher, create_dispatcher_from_configfrom ee.hogai.utils.feature_flags import is_core_memory_disabledfrom ee.hogai.utils.helpers import find_start_messagefrom ee.hogai.utils.types.base import AssistantState, BaseStateWithIntermediateSteps, NodePath-from ee.models import Conversation, CoreMemoryclass AssistantContextMixin(ABC):diff --git a/ee/hogai/core/node.py b/ee/hogai/core/node.pyindex 186b367fe0b5..20fd79c9543f 100644--- a/ee/hogai/core/node.py+++ b/ee/hogai/core/node.py@@ -4,6 +4,8 @@ from langchain_core.runnables import RunnableConfigfrom posthog.models import Team, User+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.context import get_node_pathfrom ee.hogai.core.executable import BaseAgentExecutablefrom ee.hogai.utils.exceptions import GenerationCanceled@@ -16,7 +18,6 @@ from ee.hogai.utils.types.base import (PartialStateType,StateType,)-from ee.models import Conversationclass BaseAssistantNode(BaseAgentExecutable[StateType, PartialStateType]):diff --git a/ee/hogai/core/runner.py b/ee/hogai/core/runner.pyindex fa89b21f84e5..4ea5c55a7be6 100644--- a/ee/hogai/core/runner.py+++ b/ee/hogai/core/runner.py@@ -40,6 +40,8 @@ from posthog.ph_client import get_clientfrom posthog.sync import database_sync_to_asyncfrom posthog.utils import get_instance_region+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.base import BaseAssistantGraphfrom ee.hogai.core.stream_processor import AssistantStreamProcessorProtocolfrom ee.hogai.tool import ApprovalRequest@@ -67,7 +69,6 @@ from ee.hogai.utils.types.base import (LangGraphUpdateEvent,)from ee.hogai.utils.types.composed import AssistantMaxGraphState, AssistantMaxPartialGraphState-from ee.models import Conversationlogger = structlog.get_logger(__name__)_tracer = trace.get_tracer(__name__)diff --git a/ee/hogai/core/test/test_agent_executor.py b/ee/hogai/core/test/test_agent_executor.pyindex 5ad39ef731c1..c13b1958f1db 100644--- a/ee/hogai/core/test/test_agent_executor.py+++ b/ee/hogai/core/test/test_agent_executor.py@@ -13,6 +13,8 @@ from posthog.schema import AssistantEventType, AssistantMessage, HumanMessagefrom posthog.temporal.ai.chat_agent import ChatAgentWorkflow, ChatAgentWorkflowInputs+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.executor import AgentExecutorfrom ee.hogai.stream.redis_stream import (ConversationEvent,@@ -25,7 +27,6 @@ from ee.hogai.stream.redis_stream import (get_conversation_stream_key,)from ee.hogai.utils.types.base import AssistantOutput-from ee.models.assistant import Conversationclass TestAgentExecutor(BaseTest):diff --git a/ee/hogai/core/test/test_base_callback_handlers.py b/ee/hogai/core/test/test_base_callback_handlers.pyindex 3b037a26cfa5..63b539d9c477 100644--- a/ee/hogai/core/test/test_base_callback_handlers.py+++ b/ee/hogai/core/test/test_base_callback_handlers.py@@ -6,9 +6,10 @@ from unittest.mock import Mock, patchimport posthoganalyticsfrom posthoganalytics.ai.langchain.callbacks import CallbackHandler+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.runner import ChatAgentRunnerfrom ee.hogai.core.runner import SubagentCallbackHandler-from ee.models import Conversationclass TestBaseAgentRunnerCallbackHandlers(BaseTest):diff --git a/ee/hogai/core/test/test_mixins.py b/ee/hogai/core/test/test_mixins.pyindex 8bf426a6deaf..4dcce2f50a65 100644--- a/ee/hogai/core/test/test_mixins.py+++ b/ee/hogai/core/test/test_mixins.py@@ -1,7 +1,8 @@from posthog.test.base import BaseTest+from products.posthog_ai.backend.models.assistant import CoreMemory+from ee.hogai.core.mixins import AssistantContextMixin-from ee.models.assistant import CoreMemoryclass TestAssistantNodeMixin(BaseTest):diff --git a/ee/hogai/core/test/test_node_path.py b/ee/hogai/core/test/test_node_path.pyindex 83206305b536..ea10068731de 100644--- a/ee/hogai/core/test/test_node_path.py+++ b/ee/hogai/core/test/test_node_path.py@@ -2,12 +2,13 @@ from posthog.test.base import BaseTestfrom langchain_core.runnables import RunnableConfig+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.base import BaseAssistantGraphfrom ee.hogai.core.context import get_node_pathfrom ee.hogai.core.node import AssistantNodefrom ee.hogai.utils.types import AssistantNodeName, AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import AssistantGraphName, NodePath-from ee.models import Conversationclass TestNodePath(BaseTest):diff --git a/ee/hogai/core/test/test_runner.py b/ee/hogai/core/test/test_runner.pyindex 3a582eeac8c0..aa5a81aa68a1 100644--- a/ee/hogai/core/test/test_runner.py+++ b/ee/hogai/core/test/test_runner.py@@ -12,9 +12,10 @@ from parameterized import parameterizedfrom posthog.schema import AssistantEventType, FailureMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.base import BaseAssistantGraphfrom ee.hogai.utils.types.base import AssistantState, ConversationTitleAction, PartialAssistantState-from ee.models.assistant import Conversation@asynccontextmanagerdiff --git a/ee/hogai/core/title_generator/nodes.py b/ee/hogai/core/title_generator/nodes.pyindex 1f7ff167b3c2..5345b360f889 100644--- a/ee/hogai/core/title_generator/nodes.py+++ b/ee/hogai/core/title_generator/nodes.py@@ -5,13 +5,14 @@ from langgraph.config import get_stream_writerfrom posthog.schema import HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.node import AssistantNodefrom ee.hogai.core.title_generator.prompts import TITLE_GENERATION_PROMPTfrom ee.hogai.llm import MaxChatOpenAIfrom ee.hogai.utils.helpers import find_last_message_of_typefrom ee.hogai.utils.types import AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import ConversationTitleAction-from ee.models.assistant import Conversationclass TitleGeneratorNode(AssistantNode):diff --git a/ee/hogai/core/title_generator/test/test_title_generator.py b/ee/hogai/core/title_generator/test/test_title_generator.pyindex 06b20032b4ff..594fb4c17766 100644--- a/ee/hogai/core/title_generator/test/test_title_generator.py+++ b/ee/hogai/core/title_generator/test/test_title_generator.py@@ -5,11 +5,12 @@ from langchain_core.messages import AIMessage as LangchainAIMessagefrom posthog.schema import HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.core.title_generator.nodes import TitleGeneratorNodefrom ee.hogai.utils.tests import FakeChatOpenAIfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ConversationTitleAction-from ee.models.assistant import Conversationclass TestTitleGenerator(BaseTest):diff --git a/ee/hogai/django_checkpoint/checkpointer.py b/ee/hogai/django_checkpoint/checkpointer.pyindex 69d0ee1dc8d6..a1d252dbb59a 100644--- a/ee/hogai/django_checkpoint/checkpointer.py+++ b/ee/hogai/django_checkpoint/checkpointer.py@@ -21,7 +21,11 @@ from langgraph.checkpoint.serde.types import TASKS, ChannelProtocolfrom posthog.sync import database_sync_to_async-from ee.models.assistant import ConversationCheckpoint, ConversationCheckpointBlob, ConversationCheckpointWrite+from products.posthog_ai.backend.models.assistant import (+ ConversationCheckpoint,+ ConversationCheckpointBlob,+ ConversationCheckpointWrite,+)class DjangoCheckpointer(BaseCheckpointSaver[str]):diff --git a/ee/hogai/django_checkpoint/test/test_checkpointer.py b/ee/hogai/django_checkpoint/test/test_checkpointer.pyindex b68bc67d225a..9bbd261e8738 100644--- a/ee/hogai/django_checkpoint/test/test_checkpointer.py+++ b/ee/hogai/django_checkpoint/test/test_checkpointer.py@@ -19,14 +19,15 @@ from langgraph.graph import END, STARTfrom langgraph.graph.state import CompiledStateGraph, StateGraphfrom pydantic import BaseModel, Field-from ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointer-from ee.models.assistant import (+from products.posthog_ai.backend.models.assistant import (Conversation,ConversationCheckpoint,ConversationCheckpointBlob,ConversationCheckpointWrite,)+from ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointer+class TestDjangoCheckpointer(NonAtomicBaseTest):CLASS_DATA_LEVEL_SETUP = Falsediff --git a/ee/hogai/eval/ci/conftest.py b/ee/hogai/eval/ci/conftest.pyindex bc44506b3916..db896ee803c9 100644--- a/ee/hogai/eval/ci/conftest.py+++ b/ee/hogai/eval/ci/conftest.py@@ -10,6 +10,8 @@ from posthog.schema import FailureMessage, HumanMessagefrom posthog.models import Organization, Team, User+from products.posthog_ai.backend.models.assistant import Conversation, CoreMemory+from ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.artifacts.utils import unwrap_visualization_artifact_contentfrom ee.hogai.chat_agent import AssistantGraph@@ -27,7 +29,6 @@ from ee.hogai.eval.data_setup import (from ee.hogai.eval.scorers import PlanAndQueryOutputfrom ee.hogai.utils.types import AssistantNodeName, AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import Conversation, CoreMemoryhandler = BraintrustCallbackHandler()if os.environ.get("BRAINTRUST_API_KEY") and os.environ.get("EVAL_MODE") != "offline":diff --git a/ee/hogai/eval/ci/eval_insight_search.py b/ee/hogai/eval/ci/eval_insight_search.pyindex 1219417fe06d..b0a1305ab144 100644--- a/ee/hogai/eval/ci/eval_insight_search.py+++ b/ee/hogai/eval/ci/eval_insight_search.py@@ -7,11 +7,12 @@ from braintrust import EvalCasefrom posthog.schema import HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantNodeName, AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvalfrom ..scorers import InsightEvaluationAccuracy, InsightSearchOutputdiff --git a/ee/hogai/eval/ci/eval_memory.py b/ee/hogai/eval/ci/eval_memory.pyindex 76a3c5de2307..545b61dbdfee 100644--- a/ee/hogai/eval/ci/eval_memory.py+++ b/ee/hogai/eval/ci/eval_memory.py@@ -8,10 +8,11 @@ from langchain_core.messages import AIMessage as LangchainAIMessagefrom posthog.schema import AssistantMessage, AssistantToolCall, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvalfrom ..scorers import ToolRelevancediff --git a/ee/hogai/eval/ci/eval_memory_onboarding.py b/ee/hogai/eval/ci/eval_memory_onboarding.pyindex bf7713bd03c8..266d3461d509 100644--- a/ee/hogai/eval/ci/eval_memory_onboarding.py+++ b/ee/hogai/eval/ci/eval_memory_onboarding.py@@ -12,6 +12,8 @@ from posthog.schema import AssistantMessage, EventTaxonomyItem, HumanMessagefrom posthog.models.user import Userfrom posthog.sync import database_sync_to_async+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.chat_agent.memory.prompts import (ENQUIRY_INITIAL_MESSAGE,@@ -22,7 +24,6 @@ from ee.hogai.chat_agent.memory.prompts import (from ee.hogai.core.agent_modes import SlashCommandNamefrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvaldiff --git a/ee/hogai/eval/ci/eval_root.py b/ee/hogai/eval/ci/eval_root.pyindex 74e0ab7075c1..123fc7fb4e61 100644--- a/ee/hogai/eval/ci/eval_root.py+++ b/ee/hogai/eval/ci/eval_root.py@@ -6,10 +6,11 @@ from braintrust import EvalCasefrom posthog.schema import AssistantMessage, AssistantToolCall, AssistantToolCallMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantMessageUnion, AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvalfrom ..scorers import ToolRelevancediff --git a/ee/hogai/eval/ci/eval_root_documentation.py b/ee/hogai/eval/ci/eval_root_documentation.pyindex 0d9ecb5560e6..19f3ff60aaf9 100644--- a/ee/hogai/eval/ci/eval_root_documentation.py+++ b/ee/hogai/eval/ci/eval_root_documentation.py@@ -4,10 +4,11 @@ from braintrust import EvalCasefrom posthog.schema import AssistantMessage, AssistantToolCall, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvalfrom ..scorers import ToolRelevancediff --git a/ee/hogai/eval/ci/eval_root_entity_search.py b/ee/hogai/eval/ci/eval_root_entity_search.pyindex 376533b393a9..bc02b07517d9 100644--- a/ee/hogai/eval/ci/eval_root_entity_search.py+++ b/ee/hogai/eval/ci/eval_root_entity_search.py@@ -4,10 +4,11 @@ from braintrust import EvalCasefrom posthog.schema import AssistantMessage, AssistantToolCall, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvalfrom ..scorers import ToolRelevancediff --git a/ee/hogai/eval/ci/eval_root_style.py b/ee/hogai/eval/ci/eval_root_style.pyindex 11c5bbf5c67e..7ec1de1686cc 100644--- a/ee/hogai/eval/ci/eval_root_style.py+++ b/ee/hogai/eval/ci/eval_root_style.py@@ -5,9 +5,10 @@ from braintrust import EvalCasefrom posthog.schema import AssistantMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.utils.types import AssistantMessageUnion, AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvalfrom .conftest import EVAL_USER_FULL_NAMEdiff --git a/ee/hogai/eval/ci/eval_sql.py b/ee/hogai/eval/ci/eval_sql.pyindex eefc7d64e375..749b23c8bb2b 100644--- a/ee/hogai/eval/ci/eval_sql.py+++ b/ee/hogai/eval/ci/eval_sql.py@@ -9,11 +9,12 @@ from posthog.schema import AgentMode, AssistantMessage, HumanMessagefrom posthog.models import Team+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.eval.scorers.sql import SQLSemanticsCorrectness, evaluate_sql_queryfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvaldiff --git a/ee/hogai/eval/ci/eval_surveys.py b/ee/hogai/eval/ci/eval_surveys.pyindex da49582c5b49..5b8a920fd79a 100644--- a/ee/hogai/eval/ci/eval_surveys.py+++ b/ee/hogai/eval/ci/eval_surveys.py@@ -9,11 +9,11 @@ from autoevals.ragas import AnswerSimilarityfrom braintrust import EvalCase, Scorefrom products.feature_flags.backend.models.feature_flag import FeatureFlag+from products.posthog_ai.backend.models.assistant import Conversationfrom products.surveys.backend.max_tools import CreateSurveyTool, SimpleSurveyQuestionfrom products.surveys.backend.models import Surveyfrom ee.hogai.eval.base import MaxPublicEval-from ee.models.assistant import Conversationdef unique_name(base_name: str) -> str:diff --git a/ee/hogai/eval/ci/eval_ui_context.py b/ee/hogai/eval/ci/eval_ui_context.pyindex 06a584977ce7..e98b54cd6847 100644--- a/ee/hogai/eval/ci/eval_ui_context.py+++ b/ee/hogai/eval/ci/eval_ui_context.py@@ -14,11 +14,11 @@ from posthog.schema import (from posthog.models.team.team import Teamfrom products.actions.backend.models.action import Action+from products.posthog_ai.backend.models.assistant import Conversationfrom ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationfrom ..base import MaxPublicEvalfrom ..scorers import ToolRelevancediff --git a/ee/hogai/eval/ci/max_tools/eval_create_experiment_tool.py b/ee/hogai/eval/ci/max_tools/eval_create_experiment_tool.pyindex 39481cf69900..2344db7a8998 100644--- a/ee/hogai/eval/ci/max_tools/eval_create_experiment_tool.py+++ b/ee/hogai/eval/ci/max_tools/eval_create_experiment_tool.py@@ -11,11 +11,12 @@ from langchain_core.runnables import RunnableConfigfrom posthog.schema import AgentMode, AssistantMessage, AssistantToolCallMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.eval.base import MaxPublicEvalfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationclass EvalInput(TypedDict):diff --git a/ee/hogai/eval/ci/max_tools/eval_create_feature_flag_tool.py b/ee/hogai/eval/ci/max_tools/eval_create_feature_flag_tool.pyindex 6d4eead8c28e..40703120a199 100644--- a/ee/hogai/eval/ci/max_tools/eval_create_feature_flag_tool.py+++ b/ee/hogai/eval/ci/max_tools/eval_create_feature_flag_tool.py@@ -13,11 +13,12 @@ from langchain_core.runnables import RunnableConfigfrom posthog.schema import AgentMode, AssistantMessage, AssistantToolCallMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.eval.base import MaxPublicEvalfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationclass FeatureFlagOutputScorer(ScorerWithPartial):diff --git a/ee/hogai/eval/ci/max_tools/eval_experiment_summary.py b/ee/hogai/eval/ci/max_tools/eval_experiment_summary.pyindex e809404677e6..cba77dea8f76 100644--- a/ee/hogai/eval/ci/max_tools/eval_experiment_summary.py+++ b/ee/hogai/eval/ci/max_tools/eval_experiment_summary.py@@ -27,12 +27,12 @@ from posthog.schema import (from products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlag+from products.posthog_ai.backend.models.assistant import Conversationfrom ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.eval.base import MaxPublicEvalfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversation_SUMMARY_PROMPT = "Summarize experiment {experiment_id}. What do the results show?"diff --git a/ee/hogai/eval/ci/max_tools/eval_revenue_analytics_filter_generation.py b/ee/hogai/eval/ci/max_tools/eval_revenue_analytics_filter_generation.pyindex abc5cbbaf937..6a05ba95d619 100644--- a/ee/hogai/eval/ci/max_tools/eval_revenue_analytics_filter_generation.py+++ b/ee/hogai/eval/ci/max_tools/eval_revenue_analytics_filter_generation.py@@ -13,11 +13,11 @@ from posthog.schema import (RevenueAnalyticsPropertyFilter,)+from products.posthog_ai.backend.models.assistant import Conversationfrom products.revenue_analytics.backend.max_tools import RevenueAnalyticsFilterOptionsGraphfrom products.revenue_analytics.backend.prompts import USER_FILTER_OPTIONS_PROMPTfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointer-from ee.models.assistant import Conversationfrom ...base import MaxPublicEvaldiff --git a/ee/hogai/eval/ci/max_tools/eval_session_replay_filter_generation.py b/ee/hogai/eval/ci/max_tools/eval_session_replay_filter_generation.pyindex f47abd4d0e7a..98b73e01967f 100644--- a/ee/hogai/eval/ci/max_tools/eval_session_replay_filter_generation.py+++ b/ee/hogai/eval/ci/max_tools/eval_session_replay_filter_generation.py@@ -20,11 +20,11 @@ from posthog.schema import (RecordingOrderDirection,)+from products.posthog_ai.backend.models.assistant import Conversationfrom products.replay.backend.max_tools import SessionReplayFilterOptionsGraphfrom products.replay.backend.prompts import USER_FILTER_OPTIONS_PROMPTfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointer-from ee.models.assistant import Conversationfrom ...base import MaxPublicEvaldiff --git a/ee/hogai/eval/ci/max_tools/eval_subscription_tool.py b/ee/hogai/eval/ci/max_tools/eval_subscription_tool.pyindex ce0d0a52a681..04abdf9de5cc 100644--- a/ee/hogai/eval/ci/max_tools/eval_subscription_tool.py+++ b/ee/hogai/eval/ci/max_tools/eval_subscription_tool.py@@ -20,11 +20,12 @@ from langchain_core.runnables import RunnableConfigfrom posthog.schema import AgentMode, AssistantMessage, AssistantToolCallMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.eval.base import MaxPublicEvalfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationclass EvalInput(TypedDict):diff --git a/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py b/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.pyindex bfcc4ec3b9dc..013512e4a2d2 100644--- a/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py+++ b/ee/hogai/eval/ci/max_tools/eval_upsert_dashboard.py@@ -19,13 +19,13 @@ from posthog.schema import (from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile+from products.posthog_ai.backend.models.assistant import Conversationfrom products.product_analytics.backend.models.insight import Insightfrom ee.hogai.chat_agent import AssistantGraphfrom ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.eval.base import MaxPublicEvalfrom ee.hogai.utils.types import AssistantNodeName, AssistantState-from ee.models.assistant import Conversationclass EvalInput(TypedDict):diff --git a/ee/hogai/eval/data_setup.py b/ee/hogai/eval/data_setup.pyindex cb1861543a9e..95e992ec988b 100644--- a/ee/hogai/eval/data_setup.py+++ b/ee/hogai/eval/data_setup.py@@ -23,10 +23,9 @@ from posthog.models.person.sql import COPY_PERSON_DISTINCT_ID2S_BETWEEN_TEAMS, Cfrom posthog.tasks.demo_create_data import HedgeboxMatrixfrom products.dashboards.backend.models import Dashboard, DashboardTile+from products.posthog_ai.backend.models.assistant import CoreMemoryfrom products.product_analytics.backend.models.insight import Insight-from ee.models.assistant import CoreMemory-logger = logging.getLogger(__name__)EVAL_SEED = "b1ef3c66-5f43-488a-98be-6b46d92fbcef"diff --git a/ee/hogai/eval/offline/eval_sql.py b/ee/hogai/eval/offline/eval_sql.pyindex 25264f2e3593..558e7ec6d29c 100644--- a/ee/hogai/eval/offline/eval_sql.py+++ b/ee/hogai/eval/offline/eval_sql.py@@ -15,6 +15,8 @@ from posthog.hogql.database.database import Databasefrom posthog.models import Team, Userfrom posthog.sync import database_sync_to_async+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.artifacts.utils import unwrap_visualization_artifact_contentfrom ee.hogai.chat_agent import AssistantGraph@@ -26,7 +28,6 @@ from ee.hogai.utils.helpers import find_last_message_of_typefrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessagefrom ee.hogai.utils.warehouse import serialize_database_schema-from ee.models import Conversationclass EvalOutput(BaseModel):diff --git a/ee/hogai/insights_assistant.py b/ee/hogai/insights_assistant.pyindex 3c6ebb903b6a..cb4f8a8389e9 100644--- a/ee/hogai/insights_assistant.py+++ b/ee/hogai/insights_assistant.py@@ -14,13 +14,14 @@ from posthog.schema import (from posthog.models import Team, User+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.artifacts.utils import unwrap_visualization_artifact_contentfrom ee.hogai.chat_agent.insights_graph.graph import InsightsGraphfrom ee.hogai.chat_agent.stream_processor import ChatAgentStreamProcessorfrom ee.hogai.core.runner import BaseAgentRunnerfrom ee.hogai.utils.types import AssistantOutput, AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import AssistantNodeName-from ee.models import Conversationif TYPE_CHECKING:from ee.hogai.utils.types.composed import MaxNodeNamediff --git a/ee/hogai/llm_traces_summaries/summarize_traces.py b/ee/hogai/llm_traces_summaries/summarize_traces.pyindex ab30c445dfae..6121a114938d 100644--- a/ee/hogai/llm_traces_summaries/summarize_traces.py+++ b/ee/hogai/llm_traces_summaries/summarize_traces.py@@ -5,13 +5,14 @@ from posthog.schema import DateRangefrom posthog.models.team.team import Teamfrom posthog.sync import database_sync_to_async+from products.ai_observability.backend.models.llm_traces_summaries import LLMTraceSummary+from ee.hogai.llm_traces_summaries.tools.embed_summaries import LLMTracesSummarizerEmbedderfrom ee.hogai.llm_traces_summaries.tools.find_similar_traces import LLMTracesSummarizerFinderfrom ee.hogai.llm_traces_summaries.tools.generate_stringified_summaries import LLMTraceSummarizerGeneratorfrom ee.hogai.llm_traces_summaries.tools.get_traces import LLMTracesSummarizerCollectorfrom ee.hogai.llm_traces_summaries.tools.stringify_trace import LLMTracesSummarizerStringifierfrom ee.hogai.llm_traces_summaries.utils.load_from_csv import load_traces_from_csv_files-from ee.models.llm_traces_summaries import LLMTraceSummarylogger = structlog.get_logger(__name__)diff --git a/ee/hogai/llm_traces_summaries/tools/embed_summaries.py b/ee/hogai/llm_traces_summaries/tools/embed_summaries.pyindex 5acfa63e8f1e..f2da55bb566e 100644--- a/ee/hogai/llm_traces_summaries/tools/embed_summaries.py+++ b/ee/hogai/llm_traces_summaries/tools/embed_summaries.py@@ -9,6 +9,8 @@ from posthog.clickhouse.client import sync_executefrom posthog.kafka_client.routing import get_producerfrom posthog.models.team.team import Team+from products.ai_observability.backend.models.llm_traces_summaries import LLMTraceSummary+from ee.hogai.llm_traces_summaries.constants import (DOCUMENT_EMBEDDINGS_TOPIC,LLM_TRACES_SUMMARIES_DOCUMENT_TYPE,@@ -17,7 +19,6 @@ from ee.hogai.llm_traces_summaries.constants import (LLM_TRACES_SUMMARIES_SEARCH_QUERY_MAX_ATTEMPTS,LLM_TRACES_SUMMARIES_SEARCH_QUERY_POLL_INTERVAL_SECONDS,)-from ee.models.llm_traces_summaries import LLMTraceSummaryclass LLMTracesSummarizerEmbedder:diff --git a/ee/hogai/llm_traces_summaries/tools/find_similar_traces.py b/ee/hogai/llm_traces_summaries/tools/find_similar_traces.pyindex 6e0facbe5d62..2ac2a7477513 100644--- a/ee/hogai/llm_traces_summaries/tools/find_similar_traces.py+++ b/ee/hogai/llm_traces_summaries/tools/find_similar_traces.py@@ -16,13 +16,14 @@ from posthog.event_usage import EventSourcefrom posthog.hogql_queries.document_embeddings_query_runner import DocumentEmbeddingsQueryRunnerfrom posthog.models.team.team import Team+from products.ai_observability.backend.models.llm_traces_summaries import LLMTraceSummary+from ee.hogai.llm_traces_summaries.constants import (LLM_TRACES_SUMMARIES_DOCUMENT_TYPE,LLM_TRACES_SUMMARIES_PRODUCT,LLM_TRACES_SUMMARIES_SEARCH_QUERY_DOCUMENT_TYPE,)from ee.hogai.llm_traces_summaries.tools.embed_summaries import LLMTracesSummarizerEmbedder-from ee.models.llm_traces_summaries import LLMTraceSummarylogger = structlog.get_logger(__name__)diff --git a/ee/hogai/llm_traces_summaries/tools/generate_stringified_summaries.py b/ee/hogai/llm_traces_summaries/tools/generate_stringified_summaries.pyindex e171a2d3b9eb..2e86e88fae2d 100644--- a/ee/hogai/llm_traces_summaries/tools/generate_stringified_summaries.py+++ b/ee/hogai/llm_traces_summaries/tools/generate_stringified_summaries.py@@ -13,8 +13,9 @@ from rich.console import Consolefrom posthog.models.team.team import Teamfrom posthog.sync import database_sync_to_async+from products.ai_observability.backend.models.llm_traces_summaries import LLMTraceSummary+from ee.hogai.llm_traces_summaries.constants import LLM_TRACES_SUMMARIES_MODEL_TO_SUMMARIZE_STRINGIFIED_TRACES-from ee.models.llm_traces_summaries import LLMTraceSummarylogger = structlog.get_logger(__name__)diff --git a/ee/hogai/research_agent/runner.py b/ee/hogai/research_agent/runner.pyindex 319576785b9c..0f7f7f2cff27 100644--- a/ee/hogai/research_agent/runner.py+++ b/ee/hogai/research_agent/runner.py@@ -11,12 +11,13 @@ from posthog import event_usagefrom posthog.models import Team, Userfrom posthog.sync import database_sync_to_async+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.stream_processor import ChatAgentStreamProcessorfrom ee.hogai.core.runner import BaseAgentRunnerfrom ee.hogai.research_agent.graph import ResearchAgentGraphfrom ee.hogai.utils.types import AssistantOutputfrom ee.hogai.utils.types.base import AssistantNodeName, AssistantState, PartialAssistantState-from ee.models import Conversation_tracer = trace.get_tracer(__name__)diff --git a/ee/hogai/research_agent/test/test_runner.py b/ee/hogai/research_agent/test/test_runner.pyindex 6a53dabb818a..a80ac41e0f8a 100644--- a/ee/hogai/research_agent/test/test_runner.py+++ b/ee/hogai/research_agent/test/test_runner.py@@ -5,10 +5,11 @@ from unittest.mock import AsyncMock, patchfrom posthog.schema import AgentMode, AssistantMessage, HumanMessage+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.research_agent.runner import STREAMING_NODES, VERBOSE_NODES, ResearchAgentRunnerfrom ee.hogai.utils.types import AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import AssistantNodeName-from ee.models import Conversationclass TestResearchAgentRunnerConfiguration(BaseTest):diff --git a/ee/hogai/sandbox/executor.py b/ee/hogai/sandbox/executor.pyindex 858415c35428..3462e381c499 100644--- a/ee/hogai/sandbox/executor.py+++ b/ee/hogai/sandbox/executor.py@@ -20,6 +20,7 @@ from posthog.models.team.team import Teamfrom posthog.models.user import Userfrom posthog.temporal.common.client import sync_connect+from products.posthog_ai.backend.models.assistant import Conversationfrom products.tasks.backend.models import Task, TaskRunfrom products.tasks.backend.stream.redis_stream import TaskRunRedisStream, TaskRunStreamError, get_task_run_stream_keyfrom products.tasks.backend.temporal.client import execute_task_processing_workflow@@ -38,7 +39,6 @@ from ee.hogai.sandbox.types import ()from ee.hogai.utils.aio import async_to_syncfrom ee.hogai.utils.feature_flags import has_sandbox_mode_feature_flag-from ee.models.assistant import Conversationlogger = structlog.get_logger(__name__)diff --git a/ee/hogai/stream/redis_stream.py b/ee/hogai/stream/redis_stream.pyindex 8358d81d7c38..3cd1645a23b5 100644--- a/ee/hogai/stream/redis_stream.py+++ b/ee/hogai/stream/redis_stream.py@@ -23,9 +23,10 @@ from posthog.schema import (from posthog.redis import get_async_client+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.utils.types import AssistantOutputfrom ee.hogai.utils.types.base import ApprovalPayload, AssistantStreamedMessageUnion-from ee.models.assistant import Conversationlogger = structlog.get_logger(__name__)_tracer = trace.get_tracer(__name__)diff --git a/ee/hogai/stream/test/test_redis_stream.py b/ee/hogai/stream/test/test_redis_stream.pyindex b93c25bdc54e..f33f2bbd0698 100644--- a/ee/hogai/stream/test/test_redis_stream.py+++ b/ee/hogai/stream/test/test_redis_stream.py@@ -15,6 +15,8 @@ from posthog.schema import (AssistantMessage,)+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.stream.redis_stream import (CONVERSATION_STREAM_PREFIX,CONVERSATION_STREAM_TIMEOUT,@@ -28,7 +30,6 @@ from ee.hogai.stream.redis_stream import (get_subagent_stream_key,)from ee.hogai.utils.types.base import AssistantOutput-from ee.models.assistant import Conversationclass TestRedisStream(BaseTest):diff --git a/ee/hogai/test/base.py b/ee/hogai/test/base.pyindex 96c0ae06aa55..e550dcffb131 100644--- a/ee/hogai/test/base.py+++ b/ee/hogai/test/base.py@@ -10,9 +10,10 @@ from pydantic import BaseModelfrom posthog.schema import AssistantEventType, AssistantToolCallMessage+from products.posthog_ai.backend.models.assistant import Conversation, CoreMemory+from ee.hogai.django_checkpoint.checkpointer import DjangoCheckpointerfrom ee.hogai.utils.types import AssistantOutput-from ee.models.assistant import Conversation, CoreMemoryclass BaseAssistantTest(NonAtomicBaseTest):diff --git a/ee/hogai/test/test_insights_assistant.py b/ee/hogai/test/test_insights_assistant.pyindex d526aa91f363..e247fe3f85b2 100644--- a/ee/hogai/test/test_insights_assistant.py+++ b/ee/hogai/test/test_insights_assistant.py@@ -25,6 +25,7 @@ from posthog.schema import ()from products.actions.backend.models.action import Action+from products.posthog_ai.backend.models.assistant import Conversationfrom ee.hogai.chat_agent.funnels.nodes import FunnelsSchemaGeneratorOutputfrom ee.hogai.chat_agent.retention.nodes import RetentionSchemaGeneratorOutput@@ -34,7 +35,6 @@ from ee.hogai.insights_assistant import InsightsAssistantfrom ee.hogai.test.base import BaseAssistantTestfrom ee.hogai.utils.tests import FakeAnthropicRunnableLambdaWithTokenCounter, FakeChatOpenAIfrom ee.hogai.utils.types import AssistantOutput, AssistantState-from ee.models.assistant import Conversationquery_executor_mock = patch("ee.hogai.context.insight.context.execute_and_format_query", new=AsyncMock(return_value="Result")diff --git a/ee/hogai/tools/create_notebook/helpers.py b/ee/hogai/tools/create_notebook/helpers.pyindex 42d2b881592d..79ea6c4ebece 100644--- a/ee/hogai/tools/create_notebook/helpers.py+++ b/ee/hogai/tools/create_notebook/helpers.py@@ -4,12 +4,12 @@ from enum import Enumfrom posthog.models import Team, Userfrom products.notebooks.backend.models import Notebook+from products.posthog_ai.backend.models.assistant import AgentArtifactfrom ee.hogai.artifacts.manager import ArtifactManagerfrom ee.hogai.artifacts.types import StoredBlock, StoredNotebookArtifactContent, VisualizationRefBlockfrom ee.hogai.tools.create_notebook.parsing import parse_notebook_content_for_storagefrom ee.hogai.tools.create_notebook.tiptap import blocks_to_tiptap_doc-from ee.models.assistant import AgentArtifactclass ArtifactStatus(Enum):diff --git a/ee/hogai/tools/create_notebook/test/test_helpers.py b/ee/hogai/tools/create_notebook/test/test_helpers.pyindex 547176d36432..8cb960cbca33 100644--- a/ee/hogai/tools/create_notebook/test/test_helpers.py+++ b/ee/hogai/tools/create_notebook/test/test_helpers.py@@ -4,10 +4,10 @@ from asgiref.sync import async_to_syncfrom parameterized import parameterizedfrom products.notebooks.backend.models import Notebook+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversationfrom ee.hogai.artifacts.types import StoredBlock, VisualizationRefBlockfrom ee.hogai.tools.create_notebook.helpers import save_notebook_to_db-from ee.models.assistant import AgentArtifact, Conversationdef _find_ph_query_nodes(doc: dict) -> list[dict]:diff --git a/ee/hogai/tools/create_notebook/test/test_tool.py b/ee/hogai/tools/create_notebook/test/test_tool.pyindex eaf440ffccee..fd4e96616563 100644--- a/ee/hogai/tools/create_notebook/test/test_tool.py+++ b/ee/hogai/tools/create_notebook/test/test_tool.py@@ -4,11 +4,11 @@ from asgiref.sync import async_to_syncfrom langchain_core.runnables import RunnableConfigfrom products.notebooks.backend.models import Notebook+from products.posthog_ai.backend.models.assistant import Conversationfrom ee.hogai.context import AssistantContextManagerfrom ee.hogai.tools.create_notebook.tool import CreateNotebookToolfrom ee.hogai.utils.types.base import AssistantState, NodePath-from ee.models.assistant import Conversationclass TestCreateNotebookTool(BaseTest):@@ -139,7 +139,7 @@ class TestCreateNotebookTool(BaseTest):)assert artifact is not None- from ee.models.assistant import AgentArtifact+ from products.posthog_ai.backend.models.assistant import AgentArtifactagent_artifact = AgentArtifact.objects.filter(team=self.team).last()notebook = Notebook.objects.filter(team=self.team).first()diff --git a/ee/hogai/tools/execute_sql/test/test_tool.py b/ee/hogai/tools/execute_sql/test/test_tool.pyindex 04e106ca8050..ac1ef2967510 100644--- a/ee/hogai/tools/execute_sql/test/test_tool.py+++ b/ee/hogai/tools/execute_sql/test/test_tool.py@@ -14,13 +14,13 @@ from posthog.schema import (VisualizationArtifactContent,)+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversationfrom products.product_analytics.backend.models.insight import Insightfrom ee.hogai.context.context import AssistantContextManagerfrom ee.hogai.tools.execute_sql.tool import ExecuteSQLTool, ExecuteSQLToolArgsfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import NodePath-from ee.models import AgentArtifact, Conversationclass TestExecuteSQLTool(ClickhouseTestMixin, NonAtomicBaseTest):diff --git a/ee/hogai/tools/read_data/tool.py b/ee/hogai/tools/read_data/tool.pyindex 16cf7b5f0728..86ae81b43dfe 100644--- a/ee/hogai/tools/read_data/tool.py+++ b/ee/hogai/tools/read_data/tool.py@@ -33,6 +33,7 @@ from products.ai_observability.backend.text_repr.formatters.trace_formatter impollm_trace_to_formatter_format,)from products.dashboards.backend.models.dashboard import Dashboard+from products.posthog_ai.backend.models.assistant import AgentArtifactfrom ee.hogai.artifacts.types import ModelArtifactResultfrom ee.hogai.chat_agent.sql.mixins import HogQLDatabaseMixin@@ -61,7 +62,6 @@ from ee.hogai.tools.read_data.prompts import (from ee.hogai.utils.prompt import format_prompt_stringfrom ee.hogai.utils.query import validate_assistant_queryfrom ee.hogai.utils.types.base import ArtifactRefMessage, AssistantState, NodePath-from ee.models.assistant import AgentArtifactclass ReadDataWarehouseSchema(BaseModel):diff --git a/ee/hogai/tools/read_taxonomy/test/test_tool.py b/ee/hogai/tools/read_taxonomy/test/test_tool.pyindex 25ecd1fe3dc3..36e371b1c7d9 100644--- a/ee/hogai/tools/read_taxonomy/test/test_tool.py+++ b/ee/hogai/tools/read_taxonomy/test/test_tool.py@@ -5,6 +5,8 @@ from unittest.mock import AsyncMock, MagicMock, patchfrom langchain_core.runnables import RunnableConfigfrom parameterized import parameterized+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.tool_errors import MaxToolRetryableErrorfrom ee.hogai.tools.read_taxonomy.core import (DYNAMIC_EVENT_PROPERTIES_HINT,@@ -17,7 +19,6 @@ from ee.hogai.tools.read_taxonomy.core import (from ee.hogai.tools.read_taxonomy.tool import ReadTaxonomyToolfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import NodePath-from ee.models import Conversationclass TestReadTaxonomyTool(NonAtomicBaseTest):diff --git a/ee/hogai/tools/task.py b/ee/hogai/tools/task.pyindex c459e3726f3f..a3bf19774ce8 100644--- a/ee/hogai/tools/task.py+++ b/ee/hogai/tools/task.py@@ -18,6 +18,8 @@ from posthog.schema import (from posthog.models import Team, User+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.artifacts.utils import unwrap_notebook_artifact_content, unwrap_visualization_artifact_contentfrom ee.hogai.context.context import AssistantContextManagerfrom ee.hogai.core.executor import AgentExecutor@@ -25,7 +27,6 @@ from ee.hogai.stream.redis_stream import get_subagent_stream_keyfrom ee.hogai.tool import MaxTool, ToolMessagesArtifactfrom ee.hogai.utils.prompt import format_prompt_stringfrom ee.hogai.utils.types.base import AssistantState, NodePath-from ee.models import Conversationlogger = structlog.get_logger(__name__)diff --git a/ee/hogai/tools/test/test_create_insight.py b/ee/hogai/tools/test/test_create_insight.pyindex c450391ff043..bd560e0837fc 100644--- a/ee/hogai/tools/test/test_create_insight.py+++ b/ee/hogai/tools/test/test_create_insight.py@@ -15,12 +15,13 @@ from posthog.schema import (VisualizationArtifactContent,)+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversation+from ee.hogai.chat_agent.schema_generator.nodes import SchemaGenerationExceptionfrom ee.hogai.context.context import AssistantContextManagerfrom ee.hogai.tools.create_insight import INSIGHT_TOOL_FAILURE_SYSTEM_REMINDER_PROMPT, CreateInsightToolfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import ArtifactRefMessage, AssistantNodeName, NodePath-from ee.models import AgentArtifact, Conversationclass TestCreateInsightTool(ClickhouseTestMixin, NonAtomicBaseTest):diff --git a/ee/hogai/tools/test/test_task.py b/ee/hogai/tools/test/test_task.pyindex d8c2cba9a207..63b96b516c01 100644--- a/ee/hogai/tools/test/test_task.py+++ b/ee/hogai/tools/test/test_task.py@@ -14,12 +14,13 @@ from posthog.schema import (VisualizationArtifactContent,)+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.context.context import AssistantContextManagerfrom ee.hogai.stream.redis_stream import get_subagent_stream_keyfrom ee.hogai.tools.task import SubagentExecutor, TaskToolfrom ee.hogai.utils.types import AssistantStatefrom ee.hogai.utils.types.base import NodePath-from ee.models.assistant import Conversationclass TestSubagentExecutor(ClickhouseTestMixin, NonAtomicBaseTest):diff --git a/ee/hogai/tools/upsert_dashboard/test/test_tool.py b/ee/hogai/tools/upsert_dashboard/test/test_tool.pyindex de8b2f30c5e8..e3219455adca 100644--- a/ee/hogai/tools/upsert_dashboard/test/test_tool.py+++ b/ee/hogai/tools/upsert_dashboard/test/test_tool.py@@ -26,6 +26,7 @@ from posthog.schema import (from products.dashboards.backend.models.dashboard import Dashboardfrom products.dashboards.backend.models.dashboard_tile import DashboardTile, Text+from products.posthog_ai.backend.models.assistant import AgentArtifact, Conversationfrom products.product_analytics.backend.models.insight import Insightfrom ee.hogai.artifacts.types import ModelArtifactResult, StateArtifactResult, VisualizationWithSourceResult@@ -34,7 +35,6 @@ from ee.hogai.context.insight.context import InsightContextfrom ee.hogai.tool_errors import MaxToolAccessDeniedError, MaxToolFatalError, MaxToolRetryableErrorfrom ee.hogai.tools.upsert_dashboard.tool import CreateDashboardToolArgs, UpdateDashboardToolArgs, UpsertDashboardToolfrom ee.hogai.utils.types import AssistantState-from ee.models.assistant import AgentArtifact, ConversationDEFAULT_TRENDS_QUERY = TrendsQuery(series=[EventsNode(name="$pageview")])diff --git a/ee/hogai/utils/sse.py b/ee/hogai/utils/sse.pyindex fb919ae4c18d..dfb35e041c9f 100644--- a/ee/hogai/utils/sse.py+++ b/ee/hogai/utils/sse.py@@ -5,9 +5,10 @@ from posthog.schema import AssistantEventType, AssistantGenerationStatusEvent, Afrom posthog.sync import database_sync_to_async+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.api.serializers import ConversationMinimalSerializerfrom ee.hogai.utils.types import AssistantMessageUnion, AssistantOutput-from ee.models.assistant import Conversationclass AssistantSSESerializer:diff --git a/ee/hogai/utils/test/test_assistant_node.py b/ee/hogai/utils/test/test_assistant_node.pyindex b763eb05e702..d6f608bd05f1 100644--- a/ee/hogai/utils/test/test_assistant_node.py+++ b/ee/hogai/utils/test/test_assistant_node.py@@ -2,9 +2,10 @@ from posthog.test.base import BaseTestfrom langchain_core.runnables import RunnableConfig+from products.posthog_ai.backend.models.assistant import CoreMemory+from ee.hogai.core.node import AssistantNodefrom ee.hogai.utils.types import AssistantState, PartialAssistantState-from ee.models.assistant import CoreMemoryclass TestAssistantNode(BaseTest):diff --git a/ee/hogai/utils/types/base.py b/ee/hogai/utils/types/base.pyindex 863b2898bdd2..bba7fda5f204 100644--- a/ee/hogai/utils/types/base.py+++ b/ee/hogai/utils/types/base.py@@ -45,7 +45,7 @@ from posthog.schema import (VisualizationMessage,)-from ee.models import Conversation+from products.posthog_ai.backend.models.assistant import Conversationclass ArtifactRefMessage(BaseAssistantMessage):diff --git a/ee/migrations/0031_agentartifact.py b/ee/migrations/0031_agentartifact.pyindex 15894832c033..aac969febebc 100644--- a/ee/migrations/0031_agentartifact.py+++ b/ee/migrations/0031_agentartifact.py@@ -6,7 +6,7 @@ from django.db import migrations, modelsimport posthog.models.utils-import ee.models.assistant+import products.posthog_ai.backend.models.assistantclass Migration(migrations.Migration):@@ -30,7 +30,12 @@ class Migration(migrations.Migration):default=posthog.models.utils.uuid7, editable=False, primary_key=True, serialize=False),),- ("short_id", models.CharField(default=ee.models.assistant.generate_short_id, max_length=4)),+ (+ "short_id",+ models.CharField(+ default=products.posthog_ai.backend.models.assistant.generate_short_id, max_length=4+ ),+ ),("name", models.CharField(max_length=400)),("type",diff --git a/ee/migrations/0047_migrate_ai_observability_models.py b/ee/migrations/0047_migrate_ai_observability_models.pynew file mode 100644index 000000000000..d59fc0a17abb--- /dev/null+++ b/ee/migrations/0047_migrate_ai_observability_models.py@@ -0,0 +1,53 @@+# Generated by Django 5.2.14 on 2026-06-03 09:06++from django.db import migrations++MODELS_TO_MOVE = ("llmtracesummary",)+++def _move_content_types(apps, schema_editor, from_label, to_label):+ """Move ContentTypes between apps, handling duplicates idempotently.++ If the target (app_label, model) already exists (e.g. Django auto-created it,+ or a prior failed attempt left one behind), merge permissions onto the target+ and delete the source to avoid a unique-constraint violation. Uses the+ migration's own connection alias for multi-DB safety.+ """+ db_alias = schema_editor.connection.alias+ ContentType = apps.get_model("contenttypes", "ContentType")+ Permission = apps.get_model("auth", "Permission")++ for model_name in MODELS_TO_MOVE:+ source = ContentType.objects.using(db_alias).filter(app_label=from_label, model=model_name).first()+ target = ContentType.objects.using(db_alias).filter(app_label=to_label, model=model_name).first()++ if source and target:+ Permission.objects.using(db_alias).filter(content_type=source).update(content_type=target)+ source.delete(using=db_alias)+ elif source:+ source.app_label = to_label+ source.save(using=db_alias)+++def update_content_types(apps, schema_editor):+ _move_content_types(apps, schema_editor, "ee", "ai_observability")+++def reverse_content_types(apps, schema_editor):+ _move_content_types(apps, schema_editor, "ai_observability", "ee")+++class Migration(migrations.Migration):+ dependencies = [("ee", "0046_migrate_cdp_models"), ("ai_observability", "0002_migrate_ai_observability_models")]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.DeleteModel(+ name="LLMTraceSummary",+ ),+ ],+ database_operations=[],+ ),+ migrations.RunPython(update_content_types, reverse_content_types),+ ]diff --git a/ee/migrations/0048_migrate_posthog_ai_models.py b/ee/migrations/0048_migrate_posthog_ai_models.pynew file mode 100644index 000000000000..4b884b7e7523--- /dev/null+++ b/ee/migrations/0048_migrate_posthog_ai_models.py@@ -0,0 +1,54 @@+# Generated by Django 5.2.14 on 2026-06-03 09:18++from django.db import migrations+++class Migration(migrations.Migration):+ dependencies = [+ ("ee", "0047_migrate_ai_observability_models"),+ ("posthog_ai", "0002_migrate_posthog_ai_models"),+ ("signals", "0027_migrate_posthog_ai_models"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.RemoveField(+ model_name="conversation",+ name="team",+ ),+ migrations.RemoveField(+ model_name="conversation",+ name="user",+ ),+ migrations.RemoveField(+ model_name="conversationcheckpoint",+ name="thread",+ ),+ migrations.RemoveField(+ model_name="conversationcheckpointblob",+ name="thread",+ ),+ migrations.RemoveField(+ model_name="conversationcheckpoint",+ name="parent_checkpoint",+ ),+ migrations.RemoveField(+ model_name="conversationcheckpointwrite",+ name="checkpoint",+ ),+ migrations.RemoveField(+ model_name="conversationcheckpointblob",+ name="checkpoint",+ ),+ migrations.RemoveField(+ model_name="corememory",+ name="team",+ ),+ migrations.DeleteModel(+ name="AgentArtifact",+ ),+ ],+ database_operations=[],+ )+ ]diff --git a/ee/migrations/0049_migrate_posthog_ai_models.py b/ee/migrations/0049_migrate_posthog_ai_models.pynew file mode 100644index 000000000000..38138534dff0--- /dev/null+++ b/ee/migrations/0049_migrate_posthog_ai_models.py@@ -0,0 +1,76 @@+# Generated by Django 5.2.14 on 2026-06-03 09:18++from django.db import migrations++MODELS_TO_MOVE = (+ "agentartifact",+ "conversation",+ "conversationcheckpoint",+ "conversationcheckpointblob",+ "conversationcheckpointwrite",+ "corememory",+)+++def _move_content_types(apps, schema_editor, from_label, to_label):+ """Move ContentTypes between apps, handling duplicates idempotently.++ If the target (app_label, model) already exists (e.g. Django auto-created it,+ or a prior failed attempt left one behind), merge permissions onto the target+ and delete the source to avoid a unique-constraint violation. Uses the+ migration's own connection alias for multi-DB safety.+ """+ db_alias = schema_editor.connection.alias+ ContentType = apps.get_model("contenttypes", "ContentType")+ Permission = apps.get_model("auth", "Permission")++ for model_name in MODELS_TO_MOVE:+ source = ContentType.objects.using(db_alias).filter(app_label=from_label, model=model_name).first()+ target = ContentType.objects.using(db_alias).filter(app_label=to_label, model=model_name).first()++ if source and target:+ Permission.objects.using(db_alias).filter(content_type=source).update(content_type=target)+ source.delete(using=db_alias)+ elif source:+ source.app_label = to_label+ source.save(using=db_alias)+++def update_content_types(apps, schema_editor):+ _move_content_types(apps, schema_editor, "ee", "posthog_ai")+++def reverse_content_types(apps, schema_editor):+ _move_content_types(apps, schema_editor, "posthog_ai", "ee")+++class Migration(migrations.Migration):+ dependencies = [+ ("ee", "0048_migrate_posthog_ai_models"),+ ("signals", "0027_migrate_posthog_ai_models"),+ ("posthog_ai", "0002_migrate_posthog_ai_models"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.DeleteModel(+ name="Conversation",+ ),+ migrations.DeleteModel(+ name="ConversationCheckpointWrite",+ ),+ migrations.DeleteModel(+ name="ConversationCheckpoint",+ ),+ migrations.DeleteModel(+ name="ConversationCheckpointBlob",+ ),+ migrations.DeleteModel(+ name="CoreMemory",+ ),+ ],+ database_operations=[],+ ),+ migrations.RunPython(update_content_types, reverse_content_types),+ ]diff --git a/ee/migrations/max_migration.txt b/ee/migrations/max_migration.txtindex a3ba18c59c19..34dac5f25de8 100644--- a/ee/migrations/max_migration.txt+++ b/ee/migrations/max_migration.txt@@ -1 +1 @@-0046_migrate_cdp_models+0049_migrate_posthog_ai_modelsdiff --git a/ee/models/__init__.py b/ee/models/__init__.pyindex d517fdea8f8d..f0df59755ad4 100644--- a/ee/models/__init__.py+++ b/ee/models/__init__.py@@ -1,11 +1,3 @@-from .assistant import (- AgentArtifact,- Conversation,- ConversationCheckpoint,- ConversationCheckpointBlob,- ConversationCheckpointWrite,- CoreMemory,-)from .dashboard_privilege import DashboardPrivilegefrom .event_definition import EnterpriseEventDefinitionfrom .license import License@@ -19,13 +11,7 @@ from .team_session_summaries_config import TeamSessionSummariesConfig__all__ = ["AccessControl",- "AgentArtifact",- "ConversationCheckpoint",- "ConversationCheckpointBlob",- "ConversationCheckpointWrite",- "CoreMemory","DashboardPrivilege",- "Conversation","EnterpriseEventDefinition","EnterprisePropertyDefinition","License",diff --git a/ee/models/test/test_assistant.py b/ee/models/test/test_assistant.pyindex e4760484abe3..d921be5fe7bb 100644--- a/ee/models/test/test_assistant.py+++ b/ee/models/test/test_assistant.py@@ -5,7 +5,7 @@ from posthog.test.base import BaseTestfrom django.utils import timezone-from ee.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemory+from products.posthog_ai.backend.models.assistant import CORE_MEMORY_MAX_CHARACTERS, CoreMemoryclass TestCoreMemory(BaseTest):diff --git a/posthog/api/llm_prompt.py b/posthog/api/llm_prompt.pyindex 0e877e509fe0..2060b1f1bfdb 100644--- a/posthog/api/llm_prompt.py+++ b/posthog/api/llm_prompt.py@@ -53,14 +53,14 @@ from posthog.auth import ()from posthog.event_usage import report_team_action, report_user_actionfrom posthog.exceptions_capture import capture_exception-from posthog.models import LLMPrompt, User-from posthog.models.llm_prompt import get_prompt_outline+from posthog.models import Userfrom posthog.permissions import AccessControlPermission, get_organization_from_viewfrom posthog.rate_limit import BurstRateThrottle, LLMPromptPublishBurstRateThrottle, SustainedRateThrottlefrom posthog.rbac.access_control_api_mixin import AccessControlViewSetMixinfrom posthog.storage.llm_prompt_cache import get_prompt_by_name_from_cachefrom products.ai_observability.backend.api.metrics import llma_track_latency+from products.ai_observability.backend.models.llm_prompt import LLMPrompt, get_prompt_outlinePROMPT_FETCHED_EVENT = "$llm_prompt_fetched"PROMPT_FETCHED_EVENT_SOURCE = "llm_prompt_management"diff --git a/posthog/api/llm_prompt_serializers.py b/posthog/api/llm_prompt_serializers.pyindex c23e908896c3..7323ecf5a931 100644--- a/posthog/api/llm_prompt_serializers.py+++ b/posthog/api/llm_prompt_serializers.py@@ -6,7 +6,12 @@ from drf_spectacular.utils import extend_schema_fieldfrom rest_framework import serializersfrom posthog.api.shared import UserBasicSerializer-from posthog.models.llm_prompt import LLMPrompt, get_prompt_outline, normalize_prompt_to_string++from products.ai_observability.backend.models.llm_prompt import (+ LLMPrompt,+ get_prompt_outline,+ normalize_prompt_to_string,+)class LLMPromptOutlineEntrySerializer(serializers.Serializer):diff --git a/posthog/api/services/llm_prompt.py b/posthog/api/services/llm_prompt.pyindex cb75cac74e57..15d3b4f35523 100644--- a/posthog/api/services/llm_prompt.py+++ b/posthog/api/services/llm_prompt.py@@ -9,9 +9,10 @@ from django.db.models import QuerySetfrom posthog.api.llm_prompt_serializers import MAX_PROMPT_PAYLOAD_BYTESfrom posthog.exceptions_capture import capture_exceptionfrom posthog.models import Team, User-from posthog.models.llm_prompt import LLMPrompt, annotate_llm_prompt_version_history_metadatafrom posthog.storage.llm_prompt_cache import invalidate_prompt_latest_cache, invalidate_prompt_version_caches+from products.ai_observability.backend.models.llm_prompt import LLMPrompt, annotate_llm_prompt_version_history_metadata+SYNC_ARCHIVE_VERSION_INVALIDATION_LIMIT = 100MAX_PROMPT_VERSION = 2000diff --git a/posthog/api/test/test_llm_prompt.py b/posthog/api/test/test_llm_prompt.pyindex e02eb336a050..a9155d292524 100644--- a/posthog/api/test/test_llm_prompt.py+++ b/posthog/api/test/test_llm_prompt.py@@ -12,9 +12,10 @@ from rest_framework.test import APIRequestFactoryfrom posthog.api.llm_prompt import LLMPromptViewSetfrom posthog.api.llm_prompt_serializers import MAX_PROMPT_PAYLOAD_BYTESfrom posthog.api.services.llm_prompt import MAX_PROMPT_VERSION-from posthog.models.llm_prompt import LLMPromptfrom posthog.rate_limit import BurstRateThrottle, LLMPromptPublishBurstRateThrottle, SustainedRateThrottle+from products.ai_observability.backend.models.llm_prompt import LLMPrompt+@patch("posthog.api.llm_prompt.posthoganalytics.feature_enabled", return_value=True)class TestLLMPromptAPI(APIBaseTest):diff --git a/posthog/hogql_queries/ai/suggested_questions_query_runner.py b/posthog/hogql_queries/ai/suggested_questions_query_runner.pyindex 65df86148323..8d20a51966fc 100644--- a/posthog/hogql_queries/ai/suggested_questions_query_runner.py+++ b/posthog/hogql_queries/ai/suggested_questions_query_runner.py@@ -16,7 +16,7 @@ from posthog.hogql_queries.ai.team_taxonomy_query_runner import TeamTaxonomyQuerfrom posthog.hogql_queries.query_runner import QueryRunnerfrom posthog.utils import get_instance_region-from ee.models.assistant import CoreMemory+from products.posthog_ai.backend.models.assistant import CoreMemoryclass SuggestedQuestionsQueryRunner(QueryRunner):diff --git a/posthog/migrations/1207_migrate_ai_observability_models.py b/posthog/migrations/1207_migrate_ai_observability_models.pynew file mode 100644index 000000000000..06da55b62aa1--- /dev/null+++ b/posthog/migrations/1207_migrate_ai_observability_models.py@@ -0,0 +1,56 @@+# Generated by Django 5.2.14 on 2026-06-03 09:06++from django.db import migrations++MODELS_TO_MOVE = ("llmprompt",)+++def _move_content_types(apps, schema_editor, from_label, to_label):+ """Move ContentTypes between apps, handling duplicates idempotently.++ If the target (app_label, model) already exists (e.g. Django auto-created it,+ or a prior failed attempt left one behind), merge permissions onto the target+ and delete the source to avoid a unique-constraint violation. Uses the+ migration's own connection alias for multi-DB safety.+ """+ db_alias = schema_editor.connection.alias+ ContentType = apps.get_model("contenttypes", "ContentType")+ Permission = apps.get_model("auth", "Permission")++ for model_name in MODELS_TO_MOVE:+ source = ContentType.objects.using(db_alias).filter(app_label=from_label, model=model_name).first()+ target = ContentType.objects.using(db_alias).filter(app_label=to_label, model=model_name).first()++ if source and target:+ Permission.objects.using(db_alias).filter(content_type=source).update(content_type=target)+ source.delete(using=db_alias)+ elif source:+ source.app_label = to_label+ source.save(using=db_alias)+++def update_content_types(apps, schema_editor):+ _move_content_types(apps, schema_editor, "posthog", "ai_observability")+++def reverse_content_types(apps, schema_editor):+ _move_content_types(apps, schema_editor, "ai_observability", "posthog")+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1206_cohort_list_indexes"),+ ("ai_observability", "0002_migrate_ai_observability_models"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.DeleteModel(+ name="LLMPrompt",+ ),+ ],+ database_operations=[],+ ),+ migrations.RunPython(update_content_types, reverse_content_types),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex 306d58808fe4..482d3ea41f7a 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1206_cohort_list_indexes+1207_migrate_ai_observability_modelsdiff --git a/posthog/models/__init__.py b/posthog/models/__init__.pyindex 99224ea5de9e..9c7b4ab9a634 100644--- a/posthog/models/__init__.py+++ b/posthog/models/__init__.py@@ -39,7 +39,6 @@ from .health_issue import HealthIssuefrom .instance_setting import InstanceSettingfrom .integration import Integrationfrom .integration_repository_cache import IntegrationRepositoryCacheEntry-from .llm_prompt import LLMPromptfrom .materialized_column_slots import MaterializedColumnSlot, MaterializedColumnSlotStatefrom .messaging import MessagingRecordfrom .object_media_preview import ObjectMediaPreview@@ -124,7 +123,6 @@ __all__ = ["GroupUsageMetric","GroupTypeMapping","HealthIssue",- "LLMPrompt","HostDefinition","InstanceSetting","Integration",diff --git a/posthog/models/test/test_llm_prompt.py b/posthog/models/test/test_llm_prompt.pyindex c7689fb28f4f..2780902fcb7c 100644--- a/posthog/models/test/test_llm_prompt.py+++ b/posthog/models/test/test_llm_prompt.py@@ -2,7 +2,7 @@ from unittest import TestCasefrom parameterized import parameterized-from posthog.models.llm_prompt import get_prompt_outline, normalize_prompt_to_string+from products.ai_observability.backend.models.llm_prompt import get_prompt_outline, normalize_prompt_to_stringclass TestNormalizePromptToString(TestCase):diff --git a/posthog/settings/web.py b/posthog/settings/web.pyindex ed9fda0999dd..2caf25d7cfde 100644--- a/posthog/settings/web.py+++ b/posthog/settings/web.py@@ -451,8 +451,8 @@ SPECTACULAR_SETTINGS = {"OrganizationMembershipLevelEnum": "posthog.models.organization.OrganizationMembership.Level","SetupTaskId": "posthog.models.team.setup_tasks.SetupTaskId","SurveyType": "products.surveys.backend.models.Survey.SurveyType",- "ConversationStatus": "ee.models.assistant.Conversation.Status",- "ConversationType": "ee.models.assistant.Conversation.Type",+ "ConversationStatus": "products.posthog_ai.backend.models.assistant.Conversation.Status",+ "ConversationType": "products.posthog_ai.backend.models.assistant.Conversation.Type","DetailModeEnum": "products.ai_observability.backend.summarization.models.SummarizationMode","SavedQueryStatusEnum": "products.data_modeling.backend.models.datawarehouse_saved_query.DataWarehouseSavedQuery.Status","DesktopRecordingStatusEnum": "products.desktop_recordings.backend.models.DesktopRecording.Status",diff --git a/posthog/storage/llm_prompt_cache.py b/posthog/storage/llm_prompt_cache.pyindex dbe60a4370d7..fe31869646e6 100644--- a/posthog/storage/llm_prompt_cache.py+++ b/posthog/storage/llm_prompt_cache.py@@ -5,7 +5,6 @@ from django.conf import settingsfrom django.db.models import QuerySetfrom posthog.exceptions_capture import capture_exception-from posthog.models.llm_prompt import LLMPrompt, annotate_llm_prompt_version_history_metadatafrom posthog.models.team.team import Teamfrom posthog.storage.hypercache import HyperCache, HyperCacheStoreMissing, KeyTypefrom posthog.storage.llm_prompt_cache_keys import (@@ -22,6 +21,8 @@ from posthog.storage.llm_prompt_cache_payloads import (strip_internal_metadata,)+from products.ai_observability.backend.models.llm_prompt import LLMPrompt, annotate_llm_prompt_version_history_metadata+# Used in tests; keep as module export._serialize_prompt = serialize_promptdiff --git a/posthog/storage/llm_prompt_cache_payloads.py b/posthog/storage/llm_prompt_cache_payloads.pyindex 2447489270b9..600f3b7a8e13 100644--- a/posthog/storage/llm_prompt_cache_payloads.py+++ b/posthog/storage/llm_prompt_cache_payloads.py@@ -1,7 +1,7 @@from datetime import datetimefrom typing import Any-from posthog.models.llm_prompt import LLMPrompt, normalize_prompt_to_string+from products.ai_observability.backend.models.llm_prompt import LLMPrompt, normalize_prompt_to_stringINTERNAL_FIRST_VERSION_ID_KEY = "_first_version_id"diff --git a/posthog/storage/test/test_llm_prompt_cache.py b/posthog/storage/test/test_llm_prompt_cache.pyindex 584c6a55e5a5..c03911fd5f4d 100644--- a/posthog/storage/test/test_llm_prompt_cache.py+++ b/posthog/storage/test/test_llm_prompt_cache.py@@ -5,7 +5,6 @@ from unittest.mock import patchfrom django.utils import timezone-from posthog.models.llm_prompt import LLMPromptfrom posthog.storage.llm_prompt_cache import (_serialize_prompt,get_prompt_by_name_from_cache,@@ -16,6 +15,8 @@ from posthog.storage.llm_prompt_cache import ()from posthog.storage.llm_prompt_cache_keys import prompt_latest_cache_key+from products.ai_observability.backend.models.llm_prompt import LLMPrompt+class TestLLMPromptCache(BaseTest):version_cache_names = ["cached-prompt", "existing-prompt", "new-prompt", "reused-prompt", "serializer-shape"]@@ -180,7 +181,10 @@ class TestLLMPromptCache(BaseTest):self.create_prompt_version(name="existing-prompt", version=1, is_latest=True)get_prompt_by_name_from_cache(self.team, "existing-prompt")- with patch("posthog.models.llm_prompt.transaction.on_commit", side_effect=lambda callback: None):+ with patch(+ "products.ai_observability.backend.models.llm_prompt.transaction.on_commit",+ side_effect=lambda callback: None,+ ):self.create_prompt_version(name="new-prompt", version=1, is_latest=True)cached_prompt = get_prompt_by_name_from_cache(self.team, "new-prompt")@@ -215,7 +219,10 @@ class TestLLMPromptCache(BaseTest):assert cached_old is not Noneself.assertEqual(cached_old["id"], str(old_v1.id))- with patch("posthog.models.llm_prompt.transaction.on_commit", side_effect=lambda callback: None):+ with patch(+ "products.ai_observability.backend.models.llm_prompt.transaction.on_commit",+ side_effect=lambda callback: None,+ ):LLMPrompt.objects.filter(team=self.team, name="reused-prompt", deleted=False).update(deleted=True, is_latest=False)@@ -236,7 +243,10 @@ class TestLLMPromptCache(BaseTest):assert cached_old is not Noneself.assertEqual(cached_old["id"], str(old_v1.id))- with patch("posthog.models.llm_prompt.transaction.on_commit", side_effect=lambda callback: None):+ with patch(+ "products.ai_observability.backend.models.llm_prompt.transaction.on_commit",+ side_effect=lambda callback: None,+ ):LLMPrompt.objects.filter(team=self.team, name="reused-prompt", deleted=False).update(deleted=True,is_latest=False,@@ -274,7 +284,7 @@ class TestLLMPromptCache(BaseTest):class TestLLMPromptCacheSignals(BaseTest):def test_model_signal_invalidates_latest_and_exact_version_caches_on_commit(self):with (- patch("posthog.models.llm_prompt.transaction.on_commit") as mock_on_commit,+ patch("products.ai_observability.backend.models.llm_prompt.transaction.on_commit") as mock_on_commit,patch("posthog.storage.llm_prompt_cache.invalidate_prompt_latest_cache") as mock_invalidate_latest,patch("posthog.storage.llm_prompt_cache.invalidate_prompt_version_cache") as mock_invalidate_version,):diff --git a/posthog/temporal/ai/chat_agent.py b/posthog/temporal/ai/chat_agent.pyindex ba645e249c8f..4b585e3e63b7 100644--- a/posthog/temporal/ai/chat_agent.py+++ b/posthog/temporal/ai/chat_agent.py@@ -19,11 +19,12 @@ from posthog.models import Team, Userfrom posthog.temporal.ai.base import AgentBaseWorkflowfrom posthog.temporal.common.client import async_connect+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.runner import ChatAgentRunnerfrom ee.hogai.queue import ConversationQueueMessage, ConversationQueueStorefrom ee.hogai.stream.redis_stream import ConversationRedisStream, get_conversation_stream_keyfrom ee.hogai.utils.types import AssistantMode, AssistantOutput-from ee.models import Conversationlogger = structlog.get_logger(__name__)diff --git a/posthog/temporal/ai/research_agent.py b/posthog/temporal/ai/research_agent.pyindex 258fdb38a001..57dc18ea8763 100644--- a/posthog/temporal/ai/research_agent.py+++ b/posthog/temporal/ai/research_agent.py@@ -14,9 +14,10 @@ from posthog.schema import HumanMessage, MaxBillingContextfrom posthog.models import Team, Userfrom posthog.temporal.ai.base import AgentBaseWorkflow+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.research_agent.runner import ResearchAgentRunnerfrom ee.hogai.stream.redis_stream import ConversationRedisStream-from ee.models import Conversationlogger = structlog.get_logger(__name__)diff --git a/posthog/temporal/ai/slack_conversation.py b/posthog/temporal/ai/slack_conversation.pyindex 1fb05b757eaf..3275f9a23ddb 100644--- a/posthog/temporal/ai/slack_conversation.py+++ b/posthog/temporal/ai/slack_conversation.py@@ -182,8 +182,9 @@ async def process_slack_conversation_activity(inputs: SlackConversationRunnerWorfrom posthog.models import Team, Userfrom posthog.models.integration import Integration+ from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.chat_agent.runner import ChatAgentRunner- from ee.models import Conversationteam = await Team.objects.aget(id=inputs.team_id)integration = await Integration.objects.aget(id=inputs.integration_id)diff --git a/posthog/temporal/tests/ai/test_chat_agent_activity.py b/posthog/temporal/tests/ai/test_chat_agent_activity.pyindex aa4462523ddc..394f4a99ab1b 100644--- a/posthog/temporal/tests/ai/test_chat_agent_activity.py+++ b/posthog/temporal/tests/ai/test_chat_agent_activity.py@@ -13,8 +13,9 @@ from posthog.temporal.ai.chat_agent import (process_conversation_activity,)+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.stream.redis_stream import CONVERSATION_STREAM_PREFIX-from ee.models import Conversation@pytest.mark.django_db(transaction=True)diff --git a/posthog/temporal/tests/ai/test_research_agent_activity.py b/posthog/temporal/tests/ai/test_research_agent_activity.pyindex 6eafd66624cb..58c8581895d0 100644--- a/posthog/temporal/tests/ai/test_research_agent_activity.py+++ b/posthog/temporal/tests/ai/test_research_agent_activity.py@@ -5,8 +5,9 @@ from unittest.mock import AsyncMock, MagicMock, Mock, patchfrom posthog.temporal.ai.research_agent import ResearchAgentWorkflowInputs, process_research_agent_activity+from products.posthog_ai.backend.models.assistant import Conversation+from ee.hogai.stream.redis_stream import CONVERSATION_STREAM_PREFIX-from ee.models import Conversationdef get_research_agent_stream_key(conversation_id):diff --git a/products/ai_observability/backend/migrations/0002_migrate_ai_observability_models.py b/products/ai_observability/backend/migrations/0002_migrate_ai_observability_models.pynew file mode 100644index 000000000000..73979252958a--- /dev/null+++ b/products/ai_observability/backend/migrations/0002_migrate_ai_observability_models.py@@ -0,0 +1,122 @@+# Generated by Django 5.2.14 on 2026-06-03 09:06++import django.utils.timezone+import django.db.models.deletion+from django.conf import settings+from django.db import migrations, models++import posthog.models.utils+++class Migration(migrations.Migration):+ dependencies = [+ ("ai_observability", "0001_adopt_llm_analytics_models"),+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),+ ("posthog", "1205_delete_batch_export_models"),+ ("ee", "0046_migrate_cdp_models"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.CreateModel(+ name="LLMPrompt",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.uuid7,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ ("name", models.CharField(max_length=255)),+ ("prompt", models.JSONField()),+ ("version", models.PositiveIntegerField(default=1)),+ ("is_latest", models.BooleanField(default=True)),+ ("created_at", models.DateTimeField(default=django.utils.timezone.now)),+ ("updated_at", models.DateTimeField(auto_now=True)),+ ("deleted", models.BooleanField(default=False)),+ (+ "created_by",+ models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ to=settings.AUTH_USER_MODEL,+ ),+ ),+ (+ "team",+ models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.team"),+ ),+ ],+ options={+ "db_table": "posthog_llmprompt",+ "constraints": [+ models.UniqueConstraint(+ condition=models.Q(("deleted", False)),+ fields=("team", "name", "version"),+ name="unique_llm_prompt_version_per_team",+ ),+ models.UniqueConstraint(+ condition=models.Q(("deleted", False), ("is_latest", True)),+ fields=("team", "name"),+ name="unique_llm_prompt_latest_per_team",+ ),+ ],+ },+ ),+ migrations.CreateModel(+ name="LLMTraceSummary",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.UUIDT,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ ("created_at", models.DateTimeField(auto_now_add=True, null=True)),+ ("updated_at", models.DateTimeField(auto_now=True, null=True)),+ (+ "trace_summary_type",+ models.CharField(+ choices=[("issues_search", "Issues Search")],+ default="issues_search",+ max_length=100,+ ),+ ),+ ("trace_id", models.CharField(help_text="Trace ID", max_length=255)),+ (+ "summary",+ models.CharField(help_text="Trace summary", max_length=1000),+ ),+ (+ "team",+ models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.team"),+ ),+ ],+ options={+ "db_table": "ee_llmtracesummary",+ "indexes": [+ models.Index(+ fields=["team", "trace_id", "trace_summary_type"],+ name="ee_llmtrace_team_id_93a147_idx",+ )+ ],+ "constraints": [+ models.UniqueConstraint(+ fields=("team", "trace_id", "trace_summary_type"),+ name="unique_trace_summary",+ )+ ],+ },+ ),+ ],+ database_operations=[],+ )+ ]diff --git a/products/ai_observability/backend/migrations/max_migration.txt b/products/ai_observability/backend/migrations/max_migration.txtindex 9be3e494aea9..0c8ab2cf305c 100644--- a/products/ai_observability/backend/migrations/max_migration.txt+++ b/products/ai_observability/backend/migrations/max_migration.txt@@ -1 +1 @@-0001_adopt_llm_analytics_models+0002_migrate_ai_observability_modelsdiff --git a/products/ai_observability/backend/models/__init__.py b/products/ai_observability/backend/models/__init__.pyindex 04b039ace4e1..324758bf24e7 100644--- a/products/ai_observability/backend/models/__init__.py+++ b/products/ai_observability/backend/models/__init__.py@@ -4,6 +4,8 @@ from .datasets import Dataset, DatasetItemfrom .evaluation_config import EvaluationConfigfrom .evaluation_reports import EvaluationReport, EvaluationReportRunfrom .evaluations import Evaluation+from .llm_prompt import LLMPrompt+from .llm_traces_summaries import LLMTraceSummaryfrom .model_configuration import LLMModelConfigurationfrom .provider_keys import LLMProvider, LLMProviderKeyfrom .review_queues import ReviewQueue, ReviewQueueItem@@ -22,8 +24,10 @@ __all__ = ["Dataset","DatasetItem","LLMModelConfiguration",+ "LLMPrompt","LLMProvider","LLMProviderKey",+ "LLMTraceSummary","LLMSkill","LLMSkillFile","ReviewQueue",diff --git a/posthog/models/llm_prompt.py b/products/ai_observability/backend/models/llm_prompt.pysimilarity index 99%rename from posthog/models/llm_prompt.pyrename to products/ai_observability/backend/models/llm_prompt.pyindex 367b878f040c..09e26d734f79 100644--- a/posthog/models/llm_prompt.py+++ b/products/ai_observability/backend/models/llm_prompt.py@@ -47,6 +47,7 @@ class LLMPrompt(UUIDModel):name="unique_llm_prompt_latest_per_team",),]+ db_table = "posthog_llmprompt"name = models.CharField(max_length=255)diff --git a/ee/models/llm_traces_summaries.py b/products/ai_observability/backend/models/llm_traces_summaries.pysimilarity index 90%rename from ee/models/llm_traces_summaries.pyrename to products/ai_observability/backend/models/llm_traces_summaries.pyindex 69038086beb2..3cfda948c6e9 100644--- a/ee/models/llm_traces_summaries.py+++ b/products/ai_observability/backend/models/llm_traces_summaries.py@@ -1,6 +1,5 @@from django.db import models-from posthog.models.team.team import Teamfrom posthog.models.utils import UUIDTModel@@ -12,6 +11,7 @@ class LLMTraceSummary(UUIDTModel):constraints = [models.UniqueConstraint(fields=["team", "trace_id", "trace_summary_type"], name="unique_trace_summary"),]+ db_table = "ee_llmtracesummary"class LLMTraceSummaryType(models.TextChoices):"""@@ -20,7 +20,7 @@ class LLMTraceSummary(UUIDTModel):ISSUES_SEARCH = "issues_search"- team = models.ForeignKey(Team, on_delete=models.CASCADE)+ team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE)created_at = models.DateTimeField(auto_now_add=True, null=True)updated_at = models.DateTimeField(auto_now=True, null=True)trace_summary_type = models.CharField(diff --git a/products/conversations/backend/ai/runner.py b/products/conversations/backend/ai/runner.pyindex ee94553f8ef8..5416efd4ae4a 100644--- a/products/conversations/backend/ai/runner.py+++ b/products/conversations/backend/ai/runner.py@@ -6,13 +6,13 @@ from posthog.schema import AssistantMessage, FailureMessage, HumanMessagefrom posthog.models import Team, Userfrom products.conversations.backend.ai.graph import SupportAgentGraph+from products.posthog_ai.backend.models.assistant import Conversationfrom ee.hogai.chat_agent.stream_processor import BaseStreamProcessorfrom ee.hogai.core.runner import BaseAgentRunnerfrom ee.hogai.utils.types import AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import AssistantNodeName, ContextMessagefrom ee.hogai.utils.types.composed import MaxNodeName-from ee.models import ConversationSUPPORT_TRIGGER_MESSAGE = "Generate a suggested reply for this support ticket."diff --git a/products/conversations/backend/ai/suggest.py b/products/conversations/backend/ai/suggest.pyindex 1114f00a7ce0..b4609427049c 100644--- a/products/conversations/backend/ai/suggest.py+++ b/products/conversations/backend/ai/suggest.py@@ -17,8 +17,7 @@ from posthog.models.comment import Commentfrom posthog.models.person.util import get_persons_by_distinct_idsfrom products.conversations.backend.ai.runner import SupportAgentRunner--from ee.models import Conversation+from products.posthog_ai.backend.models.assistant import Conversationif TYPE_CHECKING:from posthog.models.team import Teamdiff --git a/products/experiments/backend/presentation/serializers.py b/products/experiments/backend/presentation/serializers.pyindex 682789bfad0b..a3d31543a566 100644--- a/products/experiments/backend/presentation/serializers.py+++ b/products/experiments/backend/presentation/serializers.py@@ -20,10 +20,10 @@ from posthog.api.scoped_related_fields import TeamScopedPrimaryKeyRelatedFieldfrom posthog.api.shared import UserBasicSerializerfrom posthog.hogql_queries.experiments.experiment_metric_fingerprint import compute_metric_fingerprintfrom posthog.hogql_queries.experiments.utils import get_experiment_stats_method-from posthog.models.llm_prompt import LLMPromptfrom posthog.models.team.team import Teamfrom posthog.rbac.user_access_control import UserAccessControlSerializerMixin+from products.ai_observability.backend.models.llm_prompt import LLMPromptfrom products.experiments.backend.experiment_service import ExperimentServicefrom products.experiments.backend.facade.contracts import CreateExperimentInputfrom products.experiments.backend.llm_metric_templates import TEMPLATE_NAMESdiff --git a/products/experiments/backend/test/test_create_from_prompt.py b/products/experiments/backend/test/test_create_from_prompt.pyindex e14dcc2b12e8..3866b9432756 100644--- a/products/experiments/backend/test/test_create_from_prompt.py+++ b/products/experiments/backend/test/test_create_from_prompt.py@@ -6,8 +6,7 @@ from unittest.mock import patchfrom parameterized import parameterizedfrom rest_framework import status-from posthog.models.llm_prompt import LLMPrompt-+from products.ai_observability.backend.models.llm_prompt import LLMPromptfrom products.experiments.backend.llm_metric_templates import TEMPLATE_NAMESfrom products.experiments.backend.models.experiment import Experimentfrom products.feature_flags.backend.models.feature_flag import FeatureFlagdiff --git a/products/exports/backend/temporal/subscriptions/llm_change_summary.py b/products/exports/backend/temporal/subscriptions/llm_change_summary.pyindex 49ad467d2f7e..c751fc568dc9 100644--- a/products/exports/backend/temporal/subscriptions/llm_change_summary.py+++ b/products/exports/backend/temporal/subscriptions/llm_change_summary.py@@ -17,9 +17,9 @@ if TYPE_CHECKING:from posthog.models.team.team import Teamfrom posthog.exceptions_capture import capture_exception-from posthog.models.llm_prompt import normalize_prompt_to_stringfrom posthog.utils import get_instance_region+from products.ai_observability.backend.models.llm_prompt import normalize_prompt_to_stringfrom products.exports.backend.temporal.subscriptions.prompt_sanitization import (INSIGHT_DESCRIPTION_MAX_LEN,INSIGHT_NAME_MAX_LEN,diff --git a/products/exports/backend/temporal/subscriptions/snapshot_activities.py b/products/exports/backend/temporal/subscriptions/snapshot_activities.pyindex 600a04e3dc77..c8bbaf574536 100644--- a/products/exports/backend/temporal/subscriptions/snapshot_activities.py+++ b/products/exports/backend/temporal/subscriptions/snapshot_activities.py@@ -19,10 +19,10 @@ from products.exports.backend.temporal.subscriptions.llm_change_summary import gfrom products.exports.backend.temporal.subscriptions.prompt_sanitization import PROMPT_GUIDE_MAX_LEN, sanitize_user_textfrom products.exports.backend.temporal.subscriptions.results_summarizer import build_results_summaryfrom products.exports.backend.temporal.subscriptions.types import SnapshotInsightsInputs, SnapshotInsightsResult+from products.posthog_ai.backend.models.assistant import CoreMemoryfrom products.product_analytics.backend.models.insight import Insightfrom ee.billing.quota_limiting import QuotaLimitingCaches, QuotaResource, is_team_limited-from ee.models import CoreMemoryLOGGER = get_logger(__name__)diff --git a/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py b/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.pyindex deaab86eec38..548b6f0395b0 100644--- a/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py+++ b/products/exports/backend/temporal/subscriptions/test_snapshot_ai_consent.py@@ -11,10 +11,9 @@ from temporalio.testing import ActivityEnvironmentfrom products.exports.backend.models.subscription import Subscription, SubscriptionDeliveryfrom products.exports.backend.temporal.subscriptions.snapshot_activities import snapshot_subscription_insightsfrom products.exports.backend.temporal.subscriptions.types import SnapshotInsightsInputs+from products.posthog_ai.backend.models.assistant import CoreMemoryfrom products.product_analytics.backend.models.insight import Insight-from ee.models import CoreMemory-pytestmark = [pytest.mark.asyncio, pytest.mark.django_db(transaction=True)]diff --git a/products/posthog_ai/backend/migrations/0002_migrate_posthog_ai_models.py b/products/posthog_ai/backend/migrations/0002_migrate_posthog_ai_models.pynew file mode 100644index 000000000000..9093d24f7f77--- /dev/null+++ b/products/posthog_ai/backend/migrations/0002_migrate_posthog_ai_models.py@@ -0,0 +1,466 @@+# Generated by Django 5.2.14 on 2026-06-03 09:18++import django.db.models.deletion+from django.conf import settings+from django.db import migrations, models++import posthog.models.utils++import products.posthog_ai.backend.models.assistant+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog", "1207_migrate_ai_observability_models"),+ ("posthog_ai", "0001_initial"),+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),+ ("ee", "0047_migrate_ai_observability_models"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.CreateModel(+ name="Conversation",+ fields=[+ ("deleted", models.BooleanField(blank=True, default=False, null=True)),+ ("deleted_at", models.DateTimeField(blank=True, null=True)),+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.UUIDT,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ ("created_at", models.DateTimeField(auto_now_add=True, null=True)),+ ("updated_at", models.DateTimeField(auto_now=True, null=True)),+ (+ "status",+ models.CharField(+ choices=[+ ("idle", "Idle"),+ ("in_progress", "In progress"),+ ("canceling", "Canceling"),+ ],+ default="idle",+ max_length=20,+ ),+ ),+ (+ "type",+ models.CharField(+ choices=[+ ("assistant", "Assistant"),+ ("tool_call", "Tool call"),+ ("deep_research", "Deep research"),+ ("slack", "Slack"),+ ],+ default="assistant",+ max_length=20,+ ),+ ),+ (+ "title",+ models.CharField(+ blank=True,+ help_text="Title of the conversation.",+ max_length=250,+ null=True,+ ),+ ),+ (+ "is_internal",+ models.BooleanField(+ default=False,+ help_text="Whether this conversation was created during an impersonated session (e.g., by support agents). Internal conversations are hidden from customers.",+ null=True,+ ),+ ),+ (+ "slack_thread_key",+ models.CharField(+ blank=True,+ help_text="Unique key for Slack thread: '{workspace_id}:{channel}:{thread_ts}'",+ max_length=200,+ null=True,+ ),+ ),+ (+ "slack_workspace_domain",+ models.CharField(+ blank=True,+ help_text="Slack workspace subdomain (e.g. 'posthog' for posthog.slack.com)",+ max_length=100,+ null=True,+ ),+ ),+ (+ "approval_decisions",+ models.JSONField(+ blank=True,+ default=dict,+ help_text="Stores approval card metadata for dangerous operations (payload lives in checkpoint). Format: {proposal_id: {decision_status: 'pending' | 'approved' | 'rejected' | 'auto_rejected', tool_name: str, preview: str, ...}}",+ ),+ ),+ (+ "messages_json",+ models.JSONField(+ blank=True,+ default=None,+ help_text="Stored messages for non-LangGraph modes (e.g., sandbox).",+ null=True,+ ),+ ),+ (+ "sandbox_task_id",+ models.UUIDField(+ blank=True,+ help_text="Permanent link to Task for sandbox conversations.",+ null=True,+ ),+ ),+ (+ "sandbox_run_id",+ models.UUIDField(+ blank=True,+ help_text="Permanent link to current TaskRun for sandbox conversations.",+ null=True,+ ),+ ),+ (+ "team",+ models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.team"),+ ),+ (+ "user",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ to=settings.AUTH_USER_MODEL,+ ),+ ),+ ],+ options={+ "db_table": "ee_conversation",+ },+ ),+ migrations.CreateModel(+ name="AgentArtifact",+ fields=[+ ("created_at", models.DateTimeField(auto_now_add=True)),+ ("updated_at", models.DateTimeField(auto_now=True, null=True)),+ ("deleted", models.BooleanField(blank=True, default=False, null=True)),+ ("deleted_at", models.DateTimeField(blank=True, null=True)),+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.uuid7,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ (+ "short_id",+ models.CharField(+ default=products.posthog_ai.backend.models.assistant.generate_short_id,+ max_length=4,+ ),+ ),+ ("name", models.CharField(max_length=400)),+ (+ "type",+ models.CharField(+ choices=[+ ("visualization", "Visualization"),+ ("notebook", "Notebook"),+ ],+ max_length=50,+ ),+ ),+ (+ "data",+ models.JSONField(help_text="Artifact content. Structure depends on artifact type."),+ ),+ (+ "created_by",+ models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ to=settings.AUTH_USER_MODEL,+ ),+ ),+ (+ "team",+ models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.team"),+ ),+ (+ "conversation",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="artifacts",+ to="posthog_ai.conversation",+ ),+ ),+ ],+ options={+ "db_table": "ee_agentartifact",+ },+ ),+ migrations.CreateModel(+ name="ConversationCheckpoint",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.UUIDT,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ (+ "checkpoint_ns",+ models.TextField(+ default="",+ help_text='Checkpoint namespace. Denotes the path to the subgraph node the checkpoint originates from, separated by `|` character, e.g. `"child|grandchild"`. Defaults to "" (root graph).',+ ),+ ),+ (+ "checkpoint",+ models.JSONField(help_text="Serialized checkpoint data.", null=True),+ ),+ (+ "metadata",+ models.JSONField(help_text="Serialized checkpoint metadata.", null=True),+ ),+ (+ "parent_checkpoint",+ models.ForeignKey(+ help_text="Parent checkpoint ID.",+ null=True,+ on_delete=django.db.models.deletion.CASCADE,+ related_name="children",+ to="posthog_ai.conversationcheckpoint",+ ),+ ),+ (+ "thread",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="checkpoints",+ to="posthog_ai.conversation",+ ),+ ),+ ],+ options={+ "db_table": "ee_conversationcheckpoint",+ },+ ),+ migrations.CreateModel(+ name="ConversationCheckpointBlob",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.UUIDT,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ (+ "checkpoint_ns",+ models.TextField(+ default="",+ help_text='Checkpoint namespace. Denotes the path to the subgraph node the checkpoint originates from, separated by `|` character, e.g. `"child|grandchild"`. Defaults to "" (root graph).',+ ),+ ),+ (+ "channel",+ models.TextField(+ help_text="An arbitrary string defining the channel name. For example, it can be a node name or a reserved LangGraph's enum."+ ),+ ),+ (+ "version",+ models.TextField(help_text="Monotonically increasing version of the channel."),+ ),+ (+ "type",+ models.TextField(+ help_text="Type of the serialized blob. For example, `json`.",+ null=True,+ ),+ ),+ ("blob", models.BinaryField(null=True)),+ (+ "checkpoint",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="blobs",+ to="posthog_ai.conversationcheckpoint",+ ),+ ),+ (+ "thread",+ models.ForeignKey(+ null=True,+ on_delete=django.db.models.deletion.CASCADE,+ related_name="blobs",+ to="posthog_ai.conversation",+ ),+ ),+ ],+ options={+ "db_table": "ee_conversationcheckpointblob",+ },+ ),+ migrations.CreateModel(+ name="ConversationCheckpointWrite",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.UUIDT,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ (+ "task_id",+ models.UUIDField(help_text="Identifier for the task creating the checkpoint write."),+ ),+ (+ "idx",+ models.IntegerField(+ help_text="Index of the checkpoint write. It is an integer value where negative numbers are reserved for special cases, such as node interruption."+ ),+ ),+ (+ "channel",+ models.TextField(+ help_text="An arbitrary string defining the channel name. For example, it can be a node name or a reserved LangGraph's enum."+ ),+ ),+ (+ "type",+ models.TextField(+ help_text="Type of the serialized blob. For example, `json`.",+ null=True,+ ),+ ),+ ("blob", models.BinaryField(null=True)),+ (+ "checkpoint",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="writes",+ to="posthog_ai.conversationcheckpoint",+ ),+ ),+ ],+ options={+ "db_table": "ee_conversationcheckpointwrite",+ },+ ),+ migrations.CreateModel(+ name="CoreMemory",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.models.utils.UUIDT,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ (+ "text",+ models.TextField(+ default="",+ help_text="Dumped core memory where facts are separated by newlines.",+ ),+ ),+ (+ "initial_text",+ models.TextField(default="", help_text="Scraped memory about the business."),+ ),+ (+ "scraping_status",+ models.CharField(+ blank=True,+ choices=[+ ("pending", "Pending"),+ ("completed", "Completed"),+ ("skipped", "Skipped"),+ ],+ max_length=20,+ null=True,+ ),+ ),+ ("scraping_started_at", models.DateTimeField(null=True)),+ (+ "team",+ models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to="posthog.team"),+ ),+ ],+ options={+ "db_table": "ee_corememory",+ },+ ),+ migrations.AddIndex(+ model_name="conversation",+ index=models.Index(fields=["updated_at"], name="ee_conversa_updated_19e4e6_idx"),+ ),+ migrations.AddConstraint(+ model_name="conversation",+ constraint=models.UniqueConstraint(+ condition=models.Q(("slack_thread_key__isnull", False)),+ fields=("team", "slack_thread_key"),+ name="unique_team_slack_thread_key",+ ),+ ),+ migrations.AddIndex(+ model_name="agentartifact",+ index=models.Index(fields=["team", "short_id"], name="ee_agentart_team_id_d05587_idx"),+ ),+ migrations.AddIndex(+ model_name="agentartifact",+ index=models.Index(+ fields=["team", "conversation", "created_at"],+ name="ee_agentart_team_id_e402e1_idx",+ ),+ ),+ migrations.AddConstraint(+ model_name="agentartifact",+ constraint=models.UniqueConstraint(fields=("team", "short_id"), name="unique_team_short_id"),+ ),+ migrations.AddConstraint(+ model_name="conversationcheckpoint",+ constraint=models.UniqueConstraint(+ fields=("id", "checkpoint_ns", "thread"), name="unique_checkpoint"+ ),+ ),+ migrations.AddConstraint(+ model_name="conversationcheckpointblob",+ constraint=models.UniqueConstraint(+ fields=("thread_id", "checkpoint_ns", "channel", "version"),+ name="unique_checkpoint_blob",+ ),+ ),+ migrations.AddConstraint(+ model_name="conversationcheckpointwrite",+ constraint=models.UniqueConstraint(+ fields=("checkpoint_id", "task_id", "idx"),+ name="unique_checkpoint_write",+ ),+ ),+ ],+ database_operations=[],+ )+ ]diff --git a/products/posthog_ai/backend/migrations/max_migration.txt b/products/posthog_ai/backend/migrations/max_migration.txtindex cbab66dde92a..e249f03108e9 100644--- a/products/posthog_ai/backend/migrations/max_migration.txt+++ b/products/posthog_ai/backend/migrations/max_migration.txt@@ -1 +1 @@-0001_initial+0002_migrate_posthog_ai_modelsdiff --git a/products/posthog_ai/backend/models/__init__.py b/products/posthog_ai/backend/models/__init__.pynew file mode 100644index 000000000000..b6f06a0fa916--- /dev/null+++ b/products/posthog_ai/backend/models/__init__.py@@ -0,0 +1,19 @@+from .agent_memory import AgentMemory+from .assistant import (+ AgentArtifact,+ Conversation,+ ConversationCheckpoint,+ ConversationCheckpointBlob,+ ConversationCheckpointWrite,+ CoreMemory,+)++__all__ = [+ "AgentArtifact",+ "AgentMemory",+ "Conversation",+ "ConversationCheckpoint",+ "ConversationCheckpointBlob",+ "ConversationCheckpointWrite",+ "CoreMemory",+]diff --git a/products/posthog_ai/backend/models.py b/products/posthog_ai/backend/models/agent_memory.pysimilarity index 100%rename from products/posthog_ai/backend/models.pyrename to products/posthog_ai/backend/models/agent_memory.pydiff --git a/ee/models/assistant.py b/products/posthog_ai/backend/models/assistant.pysimilarity index 93%rename from ee/models/assistant.pyrename to products/posthog_ai/backend/models/assistant.pyindex d7f1c287bd1b..deba504ebed1 100644--- a/ee/models/assistant.py+++ b/products/posthog_ai/backend/models/assistant.py@@ -10,7 +10,7 @@ from posthog.models.user import Userfrom posthog.models.utils import CreatedMetaFields, DeletedMetaFields, UpdatedMetaFields, UUIDModel, UUIDTModel-def generate_short_id():+def generate_short_id() -> str:"""Generate securely random 4 characters long alphanumeric ID.With team-scoped uniqueness, 4 characters (62^4 = 14.7M combinations)@@ -33,6 +33,7 @@ class Conversation(UUIDTModel, DeletedMetaFields):condition=models.Q(slack_thread_key__isnull=False),)]+ db_table = "ee_conversation"class Status(models.TextChoices):IDLE = "idle", "Idle"@@ -120,6 +121,7 @@ class ConversationCheckpoint(UUIDTModel):name="unique_checkpoint",)]+ db_table = "ee_conversationcheckpoint"class ConversationCheckpointBlob(UUIDTModel):@@ -146,6 +148,7 @@ class ConversationCheckpointBlob(UUIDTModel):name="unique_checkpoint_blob",)]+ db_table = "ee_conversationcheckpointblob"class ConversationCheckpointWrite(UUIDTModel):@@ -167,6 +170,7 @@ class ConversationCheckpointWrite(UUIDTModel):name="unique_checkpoint_write",)]+ db_table = "ee_conversationcheckpointwrite"MAX_ONBOARDING_QUESTIONS = 3@@ -189,12 +193,15 @@ class CoreMemory(UUIDTModel):scraping_status = models.CharField(max_length=20, choices=ScrapingStatus, blank=True, null=True)scraping_started_at = models.DateTimeField(null=True)- async def achange_status_to_pending(self):+ class Meta:+ db_table = "ee_corememory"++ async def achange_status_to_pending(self) -> None:self.scraping_started_at = timezone.now()self.scraping_status = CoreMemory.ScrapingStatus.PENDINGawait self.asave()- async def achange_status_to_skipped(self):+ async def achange_status_to_skipped(self) -> None:self.scraping_status = CoreMemory.ScrapingStatus.SKIPPEDawait self.asave()@@ -212,24 +219,24 @@ class CoreMemory(UUIDTModel):CoreMemory.ScrapingStatus.SKIPPED,]- async def aappend_question_to_initial_text(self, text: str):+ async def aappend_question_to_initial_text(self, text: str) -> None:if self.initial_text != "":self.initial_text += "\n"self.initial_text += "Question: " + text + "\nAnswer:"self.initial_text = self.initial_text.strip()await self.asave()- async def aappend_answer_to_initial_text(self, text: str):+ async def aappend_answer_to_initial_text(self, text: str) -> None:self.initial_text += " " + textself.initial_text = self.initial_text.strip()await self.asave()- async def aset_core_memory(self, text: str):+ async def aset_core_memory(self, text: str) -> None:self.text = textself.scraping_status = CoreMemory.ScrapingStatus.COMPLETEDawait self.asave()- async def aappend_core_memory(self, text: str):+ async def aappend_core_memory(self, text: str) -> None:new_text = text if self.text == "" else self.text + "\n" + textif len(new_text) > CORE_MEMORY_MAX_CHARACTERS:raise ValueError(@@ -239,7 +246,7 @@ class CoreMemory(UUIDTModel):self.text = new_textawait self.asave()- async def areplace_core_memory(self, original_fragment: str, new_fragment: str):+ async def areplace_core_memory(self, original_fragment: str, new_fragment: str) -> None:if original_fragment not in self.text:raise ValueError(f"Original fragment {original_fragment} not found in core memory")new_text = self.text.replace(original_fragment, new_fragment)@@ -287,8 +294,9 @@ class AgentArtifact(UUIDModel, CreatedMetaFields, UpdatedMetaFields, DeletedMetaconstraints = [models.UniqueConstraint(fields=["team", "short_id"], name="unique_team_short_id"),]+ db_table = "ee_agentartifact"- def save(self, *args, **kwargs):+ def save(self, *args, **kwargs) -> None:max_retries = 5for attempt in range(max_retries):try:diff --git a/products/signals/backend/migrations/0027_migrate_posthog_ai_models.py b/products/signals/backend/migrations/0027_migrate_posthog_ai_models.pynew file mode 100644index 000000000000..2a3deede37d0--- /dev/null+++ b/products/signals/backend/migrations/0027_migrate_posthog_ai_models.py@@ -0,0 +1,29 @@+# Generated by Django 5.2.14 on 2026-06-03 09:18++import django.db.models.deletion+from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("posthog_ai", "0002_migrate_posthog_ai_models"),+ ("signals", "0026_alter_signalsourceconfig_source_product_and_more"),+ ]++ operations = [+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.AlterField(+ model_name="signalreport",+ name="conversation",+ field=models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ to="posthog_ai.conversation",+ ),+ ),+ ],+ database_operations=[],+ )+ ]diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txtindex a8203d9e43eb..bcf3247dd676 100644--- a/products/signals/backend/migrations/max_migration.txt+++ b/products/signals/backend/migrations/max_migration.txt@@ -1 +1 @@-0026_alter_signalsourceconfig_source_product_and_more+0027_migrate_posthog_ai_modelsdiff --git a/products/signals/backend/models.py b/products/signals/backend/models.pyindex 1887eea52ccf..ee1ea9644919 100644--- a/products/signals/backend/models.py+++ b/products/signals/backend/models.py@@ -183,7 +183,7 @@ class SignalReport(UUIDModel):cluster_centroid_updated_at = deprecate_field(models.DateTimeField(blank=True, null=True))# Deprecated - unusedconversation = deprecate_field(- models.ForeignKey("ee.Conversation", null=True, blank=True, on_delete=models.SET_NULL)+ models.ForeignKey("posthog_ai.Conversation", null=True, blank=True, on_delete=models.SET_NULL))relevant_user_count = deprecate_field(models.IntegerField(blank=True, null=True))diff --git a/products/user_interviews/backend/test_interview_sharing.py b/products/user_interviews/backend/test_interview_sharing.pyindex ec80587f0fb3..abab27c6a3c5 100644--- a/products/user_interviews/backend/test_interview_sharing.py+++ b/products/user_interviews/backend/test_interview_sharing.py@@ -472,7 +472,7 @@ class TestResolveFirstMessageTemplate(APIBaseTest):assert template == DEFAULT_FIRST_MESSAGE_TEMPLATEdef test_returns_team_override_when_prompt_published(self):- from posthog.models.llm_prompt import LLMPrompt+ from products.ai_observability.backend.models.llm_prompt import LLMPromptLLMPrompt.objects.create(team=self.team,@@ -486,7 +486,7 @@ class TestResolveFirstMessageTemplate(APIBaseTest):assert template == "Hey $user_name! Quick chat about $topic_text?"def test_returns_default_when_published_prompt_is_empty(self):- from posthog.models.llm_prompt import LLMPrompt+ from products.ai_observability.backend.models.llm_prompt import LLMPromptLLMPrompt.objects.create(team=self.team,diff --git a/tach.toml b/tach.tomlindex f519f888021f..32ae073e5836 100644--- a/tach.toml+++ b/tach.toml@@ -167,6 +167,7 @@ path = "products.conversations"depends_on = ["ee","posthog",+ "products.posthog_ai",]layer = "modules"@@ -271,6 +272,7 @@ depends_on = ["ee","posthog","products.actions",+ "products.ai_observability","products.event_definitions","products.feature_flags","products.notifications",@@ -574,6 +576,7 @@ path = "products.user_interviews"depends_on = ["ee","posthog",+ "products.ai_observability","products.exports",]layer = "modules"@@ -780,7 +783,7 @@ from = [[[modules]]path = "products.exports"-depends_on = ["posthog", "products.actions", "products.dashboards", "ee", "products.annotations", "products.product_analytics"]+depends_on = ["posthog", "products.actions", "products.dashboards", "ee", "products.annotations", "products.ai_observability", "products.posthog_ai", "products.product_analytics"]layer = "modules"[[modules]]