Commit dde8e06
authored
refactor(ph-ai): move chat agent specifics to dedicated classes (#41697)
## Problem
This PR extracts the Chat Agent -related logics and classes, so that the base architecture can be reused for other agents, e.g. the Research agent.
Additionally, the mode manager is now responsible for tools and system prompts, while the mode definitions only define positive/negative examples and custom tools.
## Changes
- The old `Assistant` class is now `AgentManager`. You don't need to use the `Assistant.create` factory anymore, instead, create an `AgentManager` class for your specific agent. The only legacy assistant class still in the repo is the `InsightsAssistant` one, which is connected to the MCP
- New `agent`, `chat_agent` and `research_agent` folders: the `agent` folder contains all base implementations, `chat_agent` contains the agent specific implementation, `research_agent` is mostly empty and will be filled up with the new agent in the next PRs
- `agent` contains:
- `agent_modes/` - Agent mode system
- `executables.py` - Agent and tools executable implementations (formerly `nodes.py`)
- `mode_manager.py` - Base mode manager class
- `factory.py` - Mode definition factory
- `toolkit.py` - Base toolkit class
- `utils.py` - Utility functions
- `feature_flags.py` - Feature flag checks
- `prompts.py` - Agent-specific prompts
- `presets/` - Mode preset configurations (product_analytics, sql, session_replay)
- `compaction_manager.py` - State compaction management
- `manager.py` - Base agent manager (formerly `assistant/base.py`)
- `stream_processor.py` - Agent stream processor protocol
- `agent_executor.py`: Agent executor to run Temporal workflow and stream from Redis
- `redis_stream.py`: class to stream from Redis
- `chat_agent` contains:
- `manager.py` - ChatAgentManager implementation (formerly `assistant/main_assistant.py`)
- `mode_manager.py` - Chat-specific mode management, this adds contextual tools to the default tools, and manages the mode registry and default tooling
- `graph.py` - Chat agent graph definition (formerly `graph/graph.py`)
- `loop_graph/` - Agent executor loop graph (formerly `graph/agent_executor/`)
- `graph.py` - Loop graph implementation
- `nodes.py` - Loop graph node implementations
- `stream_processor.py` - Chat-specific stream processor (formerly `utils/stream_processor.py`)
- `prompts.py` - Chat-specific prompts (cleaned up from `graph/agent_modes/prompts.py`)
- `conversation_summarizer/nodes.py` is now `conversation_summarizer/summarizer.py` as it's not a node, and is moved to the `utils` folder
- **MAIN LOGIC CHANGE**: the mode manager is now the source of truth for tools and system prompts, it injects two functions to get system prompts and tools into the executables, and is responsible for defining the default tools and mode registry. Modes stay lean, only implementing positive/negative examples and custom tools. The `SwitchModeTool` is also initialized in the mode manager so that we can inject the mode registry and default tools.
## How did you test this code?
- Refactored tests + locally
## Changelog: No1 parent 4676bc8 commit dde8e06
File tree
87 files changed
+1472
-1151
lines changed- ee
- api
- test
- hogai
- api
- test
- assistant
- chat_agent
- loop_graph
- test
- test
- core
- agent_modes
- presets
- test
- test
- test
- eval
- ci
- offline
- graph
- agent_executor
- agent_modes
- base
- memory
- test
- usage
- research_agent
- stream
- test
- tools
- utils/conversation_summarizer
- test
- posthog/temporal
- ai
- tests/ai
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
87 files changed
+1472
-1151
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| |||
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
330 | | - | |
| 330 | + | |
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
| 350 | + | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | | - | |
| 418 | + | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
584 | | - | |
| 584 | + | |
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
608 | | - | |
| 608 | + | |
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
This file was deleted.
This file was deleted.
File renamed without changes.
Lines changed: 6 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 5 | + | |
10 | 6 | | |
11 | 7 | | |
12 | 8 | | |
| |||
16 | 12 | | |
17 | 13 | | |
18 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | | - | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
0 commit comments