|
2 | 2 |
|
3 | 3 | from posthog.schema import AgentMode |
4 | 4 |
|
5 | | -from ee.hogai.tools.replay.filter_session_recordings import FilterSessionRecordingsTool |
6 | 5 | from ee.hogai.tools.replay.summarize_sessions import SummarizeSessionsTool |
7 | | -from ee.hogai.tools.todo_write import TodoWriteExample |
8 | 6 |
|
9 | 7 | from ..factory import AgentModeDefinition |
10 | 8 | from ..toolkit import AgentToolkit |
11 | 9 |
|
12 | 10 | if TYPE_CHECKING: |
13 | 11 | from ee.hogai.tool import MaxTool |
14 | 12 |
|
15 | | -POSITIVE_EXAMPLE_FILTER_WITH_PROPERTIES = """ |
16 | | -User: Show me recordings of mobile users from the US who encountered errors |
17 | | -Assistant: I'll help you find those recordings. Let me create a todo list to ensure I discover the right properties and filters. |
18 | | -*Creates todo list with the following items:* |
19 | | -1. Use read_taxonomy to discover person properties for country filtering |
20 | | -2. Use read_taxonomy to discover session properties for device type |
21 | | -3. Use read_taxonomy to discover recording properties for errors |
22 | | -4. Filter session recordings with the discovered properties |
23 | | -*Begins working on the first task* |
24 | | -""".strip() |
25 | | - |
26 | | -POSITIVE_EXAMPLE_FILTER_WITH_PROPERTIES_REASONING = """ |
27 | | -The assistant used the todo list because: |
28 | | -1. Filtering session recordings requires discovering multiple property types (person, session, recording) |
29 | | -2. Property names and values must be validated through read_taxonomy before creating filters |
30 | | -3. The query involves multiple filter criteria that need to be combined |
31 | | -4. The filter_session_recordings tool documentation explicitly requires using read_taxonomy for property discovery |
32 | | -5. Breaking this into steps ensures all properties are discovered before attempting to filter |
33 | | -""".strip() |
34 | | - |
35 | | -POSITIVE_EXAMPLE_SUMMARIZE_WITH_CONTEXT = """ |
36 | | -User: Summarize sessions where users clicked the checkout button but didn't complete purchase |
37 | | -Assistant: I'll help you analyze those sessions. This requires multiple steps to ensure we get the right recordings. |
38 | | -*Creates todo list with the following items:* |
39 | | -1. Use read_taxonomy to discover events related to checkout |
40 | | -2. Use read_taxonomy to discover events related to purchase completion |
41 | | -3. Filter session recordings for sessions with checkout events but without purchase events |
42 | | -4. Summarize the filtered sessions to identify patterns and issues |
43 | | -*Begins working on the first task* |
44 | | -""".strip() |
45 | | - |
46 | | -POSITIVE_EXAMPLE_SUMMARIZE_WITH_CONTEXT_REASONING = """ |
47 | | -The assistant used the todo list because: |
48 | | -1. Session summarization requires filtering first (can't summarize without identifying relevant sessions) |
49 | | -2. The filtering requires discovering event properties through read_taxonomy |
50 | | -3. Complex event-based filters need validation before being used |
51 | | -4. The summarize_sessions tool requires filter_session_recordings to be called first |
52 | | -5. This is a multi-step analysis requiring systematic progression through discovery, filtering, and summarization |
53 | | -""".strip() |
54 | | - |
55 | | -POSITIVE_EXAMPLE_MULTIPLE_RECORDING_ANALYSES = """ |
56 | | -User: Compare mobile vs desktop user behavior and also check if users with errors have different session patterns |
57 | | -Assistant: I'll help you analyze these different user segments. Let me break this down into separate analyses. |
58 | | -*Creates todo list with the following items:* |
59 | | -1. Filter and summarize mobile user sessions |
60 | | -2. Filter and summarize desktop user sessions |
61 | | -3. Filter and summarize sessions with console errors |
62 | | -4. Filter and summarize sessions without errors |
63 | | -5. Compare findings across segments |
64 | | -*Begins working on the first task* |
65 | | -""".strip() |
66 | | - |
67 | | -POSITIVE_EXAMPLE_MULTIPLE_RECORDING_ANALYSES_REASONING = """ |
68 | | -The assistant used the todo list because: |
69 | | -1. The user requested multiple separate recording analyses that need distinct filters |
70 | | -2. Each segment (mobile, desktop, errors, no errors) requires its own filter_session_recordings call |
71 | | -3. Each segment needs individual summarization |
72 | | -4. The todo list helps organize these parallel analyses into manageable tasks |
73 | | -5. This approach allows for tracking progress across multiple recording queries and summaries |
74 | | -""".strip() |
75 | | - |
76 | 13 |
|
77 | 14 | class SessionReplayAgentToolkit(AgentToolkit): |
78 | | - POSITIVE_TODO_EXAMPLES = [ |
79 | | - TodoWriteExample( |
80 | | - example=POSITIVE_EXAMPLE_FILTER_WITH_PROPERTIES, |
81 | | - reasoning=POSITIVE_EXAMPLE_FILTER_WITH_PROPERTIES_REASONING, |
82 | | - ), |
83 | | - TodoWriteExample( |
84 | | - example=POSITIVE_EXAMPLE_SUMMARIZE_WITH_CONTEXT, |
85 | | - reasoning=POSITIVE_EXAMPLE_SUMMARIZE_WITH_CONTEXT_REASONING, |
86 | | - ), |
87 | | - TodoWriteExample( |
88 | | - example=POSITIVE_EXAMPLE_MULTIPLE_RECORDING_ANALYSES, |
89 | | - reasoning=POSITIVE_EXAMPLE_MULTIPLE_RECORDING_ANALYSES_REASONING, |
90 | | - ), |
91 | | - ] |
92 | | - |
93 | 15 | @property |
94 | 16 | def tools(self) -> list[type["MaxTool"]]: |
95 | | - tools: list[type[MaxTool]] = [FilterSessionRecordingsTool, SummarizeSessionsTool] |
| 17 | + tools: list[type[MaxTool]] = [SummarizeSessionsTool] |
96 | 18 | return tools |
97 | 19 |
|
98 | 20 |
|
99 | 21 | session_replay_agent = AgentModeDefinition( |
100 | 22 | mode=AgentMode.SESSION_REPLAY, |
101 | | - mode_description="Specialized mode for analyzing session recordings and user behavior. This mode allows you to filter session recordings, and summarize entire sessions or a set of them.", |
| 23 | + 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.", |
102 | 24 | toolkit_class=SessionReplayAgentToolkit, |
103 | 25 | ) |
0 commit comments