Skip to content

Commit c09562c

Browse files
committed
feat: replay mode
1 parent b90e114 commit c09562c

File tree

10 files changed

+628
-13
lines changed

10 files changed

+628
-13
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from posthog.schema import AgentMode
22

3+
from ee.hogai.graph.agent_modes.presets.session_replay import session_replay_agent
4+
35
from .product_analytics import product_analytics_agent
46
from .sql import sql_agent
57

68
MODE_REGISTRY = {
79
AgentMode.PRODUCT_ANALYTICS: product_analytics_agent,
810
AgentMode.SQL: sql_agent,
11+
AgentMode.SESSION_REPLAY: session_replay_agent,
912
}

ee/hogai/graph/agent_modes/presets/product_analytics.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from posthog.schema import AgentMode
66

7-
from ee.hogai.tools import CreateAndQueryInsightTool, CreateDashboardTool, SessionSummarizationTool
7+
from ee.hogai.tools import CreateAndQueryInsightTool, CreateDashboardTool
88

99
from ..factory import AgentDefinition
1010
from ..nodes import AgentToolkit
@@ -22,10 +22,6 @@ def custom_tools(self) -> list[type["MaxTool"]]:
2222
if not CreateAndQueryInsightTool.is_editing_mode(self._context_manager):
2323
tools.append(CreateAndQueryInsightTool)
2424

25-
# Add session summarization tool if enabled
26-
if self._has_session_summarization_feature_flag():
27-
tools.append(SessionSummarizationTool)
28-
2925
# Add other lower-priority tools
3026
tools.append(CreateDashboardTool)
3127

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import TYPE_CHECKING
2+
3+
import posthoganalytics
4+
5+
from posthog.schema import AgentMode
6+
7+
from ee.hogai.tools.replay.summarize_sessions import SummarizeSessionsTool
8+
9+
from ..factory import AgentDefinition
10+
from ..nodes import AgentToolkit
11+
12+
if TYPE_CHECKING:
13+
from ee.hogai.tool import MaxTool
14+
15+
16+
class SessionReplayAgentToolkit(AgentToolkit):
17+
@property
18+
def custom_tools(self) -> list[type["MaxTool"]]:
19+
tools: list[type[MaxTool]] = []
20+
21+
# Add session summarization tool if enabled
22+
if self._has_session_summarization_feature_flag():
23+
tools.append(SummarizeSessionsTool)
24+
25+
return tools
26+
27+
def _has_session_summarization_feature_flag(self) -> bool:
28+
"""
29+
Check if the user has the session summarization feature flag enabled.
30+
"""
31+
return posthoganalytics.feature_enabled(
32+
"max-session-summarization",
33+
str(self._user.distinct_id),
34+
groups={"organization": str(self._team.organization_id)},
35+
group_properties={"organization": {"id": str(self._team.organization_id)}},
36+
send_feature_flag_events=False,
37+
)
38+
39+
40+
session_replay_agent = AgentDefinition(
41+
mode=AgentMode.SESSION_REPLAY,
42+
mode_description="Specialized mode for analyzing session recordings and user behavior. This mode allows you to get summaries of session recordings and insights about them in natural language.",
43+
toolkit_class=SessionReplayAgentToolkit,
44+
)

ee/hogai/mode_registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from posthog.schema import AgentMode
22

33
from ee.hogai.graph.agent_modes.presets.product_analytics import product_analytics_agent
4+
from ee.hogai.graph.agent_modes.presets.session_replay import session_replay_agent
45
from ee.hogai.graph.agent_modes.presets.sql import sql_agent
56

67
MODE_REGISTRY = {
78
AgentMode.PRODUCT_ANALYTICS: product_analytics_agent,
89
AgentMode.SQL: sql_agent,
10+
AgentMode.SESSION_REPLAY: session_replay_agent,
911
}

ee/hogai/tools/create_and_query_insight.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
from typing import Literal
1+
from typing import Literal, Self
22

3+
from langchain_core.runnables import RunnableConfig
34
from pydantic import BaseModel, Field
45

56
from posthog.schema import AssistantTool, AssistantToolCallMessage, VisualizationMessage
67

8+
from posthog.models import Team, User
9+
710
from ee.hogai.context.context import AssistantContextManager
811
from ee.hogai.graph.insights_graph.graph import InsightsGraph
912
from ee.hogai.graph.schema_generator.nodes import SchemaGenerationException
1013
from ee.hogai.tool import MaxTool, ToolMessagesArtifact
1114
from ee.hogai.utils.prompt import format_prompt_string
12-
from ee.hogai.utils.types.base import AssistantNodeName, AssistantState
15+
from ee.hogai.utils.types.base import AssistantNodeName, AssistantState, NodePath
1316

1417
INSIGHT_TOOL_PROMPT = """
1518
Use this tool to generate an insight from a structured plan. It will return a visualization that the user will be able to analyze and textual representation for your analysis.
@@ -516,9 +519,25 @@ class CreateAndQueryInsightToolArgs(BaseModel):
516519
class CreateAndQueryInsightTool(MaxTool):
517520
name: Literal["create_and_query_insight"] = "create_and_query_insight"
518521
args_schema: type[BaseModel] = CreateAndQueryInsightToolArgs
519-
description: str = INSIGHT_TOOL_PROMPT
520522
context_prompt_template: str = INSIGHT_TOOL_CONTEXT_PROMPT_TEMPLATE
521-
thinking_message: str = "Coming up with an insight"
523+
524+
@classmethod
525+
async def create_tool_class(
526+
cls,
527+
*,
528+
team: Team,
529+
user: User,
530+
node_path: tuple[NodePath, ...] | None = None,
531+
state: AssistantState | None = None,
532+
config: RunnableConfig | None = None,
533+
context_manager: AssistantContextManager | None = None,
534+
) -> Self:
535+
context_manager = context_manager or AssistantContextManager(team, user, config)
536+
prompt = format_prompt_string(
537+
INSIGHT_TOOL_PROMPT,
538+
groups=await context_manager.get_group_names(),
539+
)
540+
return cls(team=team, user=user, state=state, node_path=node_path, config=config, description=prompt)
522541

523542
async def _arun_impl(
524543
self, query_description: str, insight_type: InsightType

ee/hogai/tools/replay/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)