Skip to content

Commit 458276d

Browse files
author
kappa90
committed
refactor(ph-ai): clean up scaffolding
1 parent dde8e06 commit 458276d

File tree

246 files changed

+655
-734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+655
-734
lines changed

ee/clickhouse/queries/test/__snapshots__/test_cohort_query.ambr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,15 +1085,15 @@
10851085
(
10861086
(SELECT persons.id AS id
10871087
FROM
1088-
(SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', ''), person.version) AS properties___name,
1088+
(SELECT tupleElement(argMax(tuple(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'name'), ''), 'null'), '^"|"$', '')), person.version), 1) AS properties___name,
10891089
person.id AS id
10901090
FROM person
10911091
WHERE and(equals(person.team_id, 99999), in(id,
10921092
(SELECT where_optimization.id AS id
10931093
FROM person AS where_optimization
10941094
WHERE and(equals(where_optimization.team_id, 99999), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(where_optimization.properties, 'name'), ''), 'null'), '^"|"$', ''), 'test'), 0)))))
10951095
GROUP BY person.id
1096-
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))) AS persons
1096+
HAVING and(ifNull(equals(tupleElement(argMax(tuple(person.is_deleted), person.version), 1), 0), 0), ifNull(less(tupleElement(argMax(tuple(toTimeZone(person.created_at, 'UTC')), person.version), 1), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))) AS persons
10971097
WHERE ifNull(equals(persons.properties___name, 'test'), 0)
10981098
ORDER BY persons.id ASC
10991099
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,
@@ -1112,13 +1112,13 @@
11121112
e.distinct_id AS distinct_id
11131113
FROM events AS e
11141114
LEFT OUTER JOIN
1115-
(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,
1115+
(SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
11161116
person_distinct_id_overrides.distinct_id AS distinct_id
11171117
FROM person_distinct_id_overrides
11181118
WHERE equals(person_distinct_id_overrides.team_id, 99999)
11191119
GROUP BY person_distinct_id_overrides.distinct_id
1120-
HAVING ifNull(equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)
1121-
WHERE and(equals(e.team_id, 99999), greaterOrEquals(timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), equals(e.event, '$pageview')))
1120+
HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)
1121+
WHERE and(equals(e.team_id, 99999), greaterOrEquals(timestamp, toDateTime64('2025-11-14 00:00:00.000000', 6, 'UTC')), lessOrEquals(timestamp, toDateTime64('today', 6, 'UTC')), equals(e.event, '$pageview')))
11221122
GROUP BY actor_id) AS source
11231123
ORDER BY source.id ASC
11241124
LIMIT 1000000000 SETTINGS optimize_aggregation_in_order=1,

ee/hogai/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ class MaxToolTaxonomyOutput(BaseModel):
234234

235235
```python
236236
from pydantic import BaseModel, Field
237-
from ee.hogai.graph.taxonomy.toolkit import TaxonomyAgentToolkit
238-
from ee.hogai.graph.taxonomy.tools import base_final_answer
237+
from ee.hogai.chat_agent.taxonomy.toolkit import TaxonomyAgentToolkit
238+
from ee.hogai.chat_agent.taxonomy.tools import base_final_answer
239239
from posthog.models import Team
240240
241241
@@ -276,9 +276,9 @@ class YourToolkit(TaxonomyAgentToolkit):
276276
```python
277277
from langchain_core.prompts import ChatPromptTemplate
278278
from posthog.models import Team, User
279-
from ee.hogai.graph.taxonomy.nodes import TaxonomyAgentNode, TaxonomyAgentToolsNode
280-
from ee.hogai.graph.taxonomy.agent import TaxonomyAgent
281-
from ee.hogai.graph.taxonomy.types import TaxonomyAgentState
279+
from ee.hogai.chat_agent.taxonomy.nodes import TaxonomyAgentNode, TaxonomyAgentToolsNode
280+
from ee.hogai.chat_agent.taxonomy.agent import TaxonomyAgent
281+
from ee.hogai.chat_agent.taxonomy.types import TaxonomyAgentState
282282
283283
class LoopNode(TaxonomyAgentNode[TaxonomyAgentState, TaxonomyAgentState[MaxToolTaxonomyOutput]]):
284284
def __init__(self, team: Team, user: User, toolkit_class: type[YourToolkit]):

ee/hogai/api/serializers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
from posthog.exceptions_capture import capture_exception
99

10-
from ee.hogai.chat_agent.graph import AssistantGraph
11-
from ee.hogai.graph.deep_research.graph import DeepResearchAssistantGraph
12-
from ee.hogai.graph.deep_research.types import DeepResearchState
10+
from ee.hogai.chat_agent import AssistantGraph
11+
from ee.hogai.research_agent.graph import DeepResearchAssistantGraph
12+
from ee.hogai.research_agent.types import DeepResearchState
1313
from ee.hogai.utils.helpers import should_output_assistant_message
1414
from ee.hogai.utils.types import AssistantState
1515
from ee.hogai.utils.types.composed import AssistantMaxGraphState

ee/hogai/api/test/test_serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from posthog.schema import AssistantMessage, AssistantToolCallMessage, ContextMessage
55

66
from ee.hogai.api.serializers import ConversationSerializer
7-
from ee.hogai.chat_agent.graph import AssistantGraph
7+
from ee.hogai.chat_agent import AssistantGraph
88
from ee.hogai.utils.types import AssistantState
99
from ee.models.assistant import Conversation
1010

ee/hogai/chat_agent/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .graph import AssistantGraph
2+
3+
__all__ = ["AssistantGraph"]

ee/hogai/graph/dashboards/nodes.py renamed to ee/hogai/chat_agent/dashboards/nodes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
from posthog.sync import database_sync_to_async
2121
from posthog.utils import pluralize
2222

23-
from ee.hogai.graph.base import AssistantNode
24-
from ee.hogai.graph.parallel_task_execution.mixins import (
23+
from ee.hogai.chat_agent.parallel_task_execution.mixins import (
2524
WithInsightCreationTaskExecution,
2625
WithInsightSearchTaskExecution,
2726
)
28-
from ee.hogai.graph.parallel_task_execution.nodes import BaseTaskExecutorNode, TaskExecutionInputTuple
29-
from ee.hogai.graph.shared_prompts import HYPERLINK_USAGE_INSTRUCTIONS
27+
from ee.hogai.chat_agent.parallel_task_execution.nodes import BaseTaskExecutorNode, TaskExecutionInputTuple
28+
from ee.hogai.core.node import AssistantNode
29+
from ee.hogai.core.shared_prompts import HYPERLINK_USAGE_INSTRUCTIONS
3030
from ee.hogai.llm import MaxChatOpenAI
3131
from ee.hogai.utils.helpers import build_dashboard_url, build_insight_url, cast_assistant_query
3232
from ee.hogai.utils.types import AssistantState, PartialAssistantState
File renamed without changes.
File renamed without changes.

ee/hogai/graph/dashboards/test/test_nodes.py renamed to ee/hogai/chat_agent/dashboards/test/test_nodes.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from posthog.models import Dashboard, Insight, Team, User
1010

11-
from ee.hogai.graph.dashboards.nodes import DashboardCreationExecutorNode, DashboardCreationNode, QueryMetadata
11+
from ee.hogai.chat_agent.dashboards.nodes import DashboardCreationExecutorNode, DashboardCreationNode, QueryMetadata
1212
from ee.hogai.utils.helpers import build_dashboard_url, build_insight_url
1313
from ee.hogai.utils.types import AssistantState, PartialAssistantState
1414
from ee.hogai.utils.types.base import (
@@ -163,7 +163,7 @@ def test_build_dashboard_url(self):
163163
expected_url = f"/project/{self.mock_team.id}/dashboard/{dashboard_id}"
164164
assert url == expected_url
165165

166-
@patch("ee.hogai.graph.dashboards.nodes.DashboardCreationExecutorNode")
166+
@patch("ee.hogai.chat_agent.dashboards.nodes.DashboardCreationExecutorNode")
167167
async def test_arun_missing_search_insights_queries(self, mock_executor_node_class):
168168
"""Test arun returns error when search_insights_queries is missing."""
169169
mock_executor_node = MagicMock()
@@ -183,7 +183,7 @@ async def test_arun_missing_search_insights_queries(self, mock_executor_node_cla
183183
assert isinstance(result.messages[0], AssistantToolCallMessage)
184184
assert "Search insights queries are required" in result.messages[0].content
185185

186-
@patch("ee.hogai.graph.dashboards.nodes.DashboardCreationExecutorNode")
186+
@patch("ee.hogai.chat_agent.dashboards.nodes.DashboardCreationExecutorNode")
187187
@patch.object(DashboardCreationNode, "_search_insights")
188188
@patch.object(DashboardCreationNode, "_create_insights")
189189
@patch.object(DashboardCreationNode, "_create_dashboard_with_insights")
@@ -238,7 +238,7 @@ async def test_arun_successful_flow(
238238
assert "Dashboard Created" in result.messages[0].content
239239
assert "Test Dashboard" in result.messages[0].content
240240

241-
@patch("ee.hogai.graph.dashboards.nodes.DashboardCreationExecutorNode")
241+
@patch("ee.hogai.chat_agent.dashboards.nodes.DashboardCreationExecutorNode")
242242
@patch.object(DashboardCreationNode, "_search_insights")
243243
@patch.object(DashboardCreationNode, "_create_insights")
244244
async def test_arun_no_insights_found_or_created(
@@ -275,9 +275,9 @@ async def test_arun_no_insights_found_or_created(
275275
assert isinstance(result.messages[0], AssistantToolCallMessage)
276276
assert "No existing insights matched" in result.messages[0].content
277277

278-
@patch("ee.hogai.graph.dashboards.nodes.DashboardCreationExecutorNode")
278+
@patch("ee.hogai.chat_agent.dashboards.nodes.DashboardCreationExecutorNode")
279279
@patch.object(DashboardCreationNode, "_search_insights")
280-
@patch("ee.hogai.graph.dashboards.nodes.logger")
280+
@patch("ee.hogai.chat_agent.dashboards.nodes.logger")
281281
async def test_arun_exception_handling(self, mock_logger, mock_search_insights, mock_executor_node_class):
282282
"""Test arun handles exceptions properly."""
283283
mock_executor_node = MagicMock()
@@ -338,7 +338,7 @@ def test_create_no_insights_response(self):
338338

339339
def test_create_error_response(self):
340340
"""Test _create_error_response creates correct error message."""
341-
with patch("ee.hogai.graph.dashboards.nodes.capture_exception") as mock_capture:
341+
with patch("ee.hogai.chat_agent.dashboards.nodes.capture_exception") as mock_capture:
342342
result = self.node._create_error_response("Test error", "test_tool_call_id")
343343

344344
assert isinstance(result, PartialAssistantState)
@@ -363,7 +363,7 @@ def setUp(self):
363363
node_path=(NodePath(name="test_node", message_id="test-id", tool_call_id="test_tool_call_id"),),
364364
)
365365

366-
@patch("ee.hogai.graph.dashboards.nodes.DashboardCreationExecutorNode")
366+
@patch("ee.hogai.chat_agent.dashboards.nodes.DashboardCreationExecutorNode")
367367
async def test_create_insights(self, mock_executor_node_class):
368368
"""Test _create_insights method."""
369369
# Setup mocks
@@ -411,7 +411,7 @@ async def mock_process_insight_creation_results(tool_calls, task_results, query_
411411
assert len(result["task_1"].created_insight_ids) == 2
412412
assert len(result["task_1"].created_insight_messages) == 1
413413

414-
@patch("ee.hogai.graph.dashboards.nodes.DashboardCreationExecutorNode")
414+
@patch("ee.hogai.chat_agent.dashboards.nodes.DashboardCreationExecutorNode")
415415
async def test_search_insights(self, mock_executor_node_class):
416416
"""Test _search_insights method."""
417417
# Setup mocks
@@ -451,7 +451,7 @@ async def test_search_insights(self, mock_executor_node_class):
451451
assert len(result["task_1"].found_insight_ids) == 2
452452
assert len(result["task_1"].found_insight_messages) == 2
453453

454-
@patch("ee.hogai.graph.dashboards.nodes.database_sync_to_async")
454+
@patch("ee.hogai.chat_agent.dashboards.nodes.database_sync_to_async")
455455
async def test_create_dashboard_with_insights(self, mock_db_sync):
456456
"""Test _create_dashboard_with_insights method."""
457457

0 commit comments

Comments
 (0)