-
Notifications
You must be signed in to change notification settings - Fork 2.1k
refactor(ph-ai): conversation stream manager to agent executor #41613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(ph-ai): conversation stream manager to agent executor #41613
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 files reviewed, no comments
Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format
047f7db to
6427e90
Compare
sortafreel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The missing part is the consistency test (because you changed the activity name), easy fix.
6427e90 to
7424d72
Compare
skoob13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Let's not merge it into the agent modes branch to keep this isolated.
1b6baaf to
affac80
Compare
affac80 to
786c1dd
Compare
e7e4fcb to
c982e8f
Compare
786c1dd to
576e70c
Compare
576e70c to
801decb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the conversation streaming infrastructure to support multiple types of agent workflows. The main change renames ConversationStreamManager to AgentExecutor and introduces a base workflow class to enable different workflow types beyond the basic chat agent.
Key changes:
- Introduced
AgentBaseWorkflowas a base class for different agent workflow types - Refactored
ConversationStreamManagertoAgentExecutorwith configurable timeout and max_length parameters - Moved Redis stream implementation from
ee/hogai/stream/toee/hogai/agent/
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| posthog/temporal/ai/base.py | Adds new AgentBaseWorkflow base class for agent workflows |
| posthog/temporal/ai/chat_agent.py | Updates imports and constants for chat agent workflow; maintains existing workflow class name |
| posthog/temporal/ai/init.py | Updates imports to reference chat_agent module |
| posthog/temporal/tests/ai/test_chat_agent_activity.py | Updates test imports and patches (contains bugs - patching wrong class) |
| ee/hogai/agent/redis_stream.py | Makes timeout and max_length configurable parameters in ConversationRedisStream |
| ee/hogai/agent/executor.py | Renames class to AgentExecutor, adds workflow type parameter to support multiple workflows |
| ee/hogai/agent/test/test_redis_stream.py | Updates import paths for redis_stream module |
| ee/hogai/agent/test/test_agent_executor.py | Updates test class name and patches for AgentExecutor |
| ee/api/conversation.py | Updates imports and usage to work with AgentExecutor and new workflow structure |
| ee/api/test/test_conversation.py | Updates test patches and call argument indices for new method signature |
Comments suppressed due to low confidence (8)
posthog/temporal/tests/ai/test_chat_agent_activity.py:106
- The test is patching
ChatAgentManagerbut the actual implementation usesAssistant.create. This patch should be"posthog.temporal.ai.chat_agent.Assistant.create"instead of"posthog.temporal.ai.chat_agent.ChatAgentManager"to properly mock the Assistant creation in the activity.
posthog/temporal/tests/ai/test_chat_agent_activity.py:152 - The test is patching
ChatAgentManagerbut the actual implementation usesAssistant.create. This patch should be"posthog.temporal.ai.chat_agent.Assistant.create"instead of"posthog.temporal.ai.chat_agent.ChatAgentManager"to properly mock the Assistant creation in the activity.
ee/hogai/agent/test/test_agent_executor.py:42 - The docstring should be updated to reflect the new class name. It should say "Test AgentExecutor initialization" instead of "Test ConversationStreamManager initialization".
ee/hogai/agent/executor.py:182 - The method name
cancel_workflowis generic but the docstring still says "Cancel the current conversation". While the method name was updated for generality, the docstring should be updated to say "Cancel the current workflow" to match the new naming convention and reflect that this executor can run different types of workflows, not just conversations.
ee/hogai/agent/executor.py:64 - The method call
self.stream_conversation()is using the old conversation-specific naming. For consistency with the refactoring to support multiple workflow types, this should be renamed to something more generic likeself.stream_workflow(). However, sincestream_conversationis not being changed in this PR, this is noted for future refactoring.
posthog/temporal/tests/ai/test_chat_agent_activity.py:187 - The test is patching
ChatAgentManagerbut the actual implementation usesAssistant.create. This patch should be"posthog.temporal.ai.chat_agent.Assistant.create"instead of"posthog.temporal.ai.chat_agent.ChatAgentManager"to properly mock the Assistant creation in the activity.
posthog/temporal/tests/ai/test_chat_agent_activity.py:217 - The test is patching
ChatAgentManagerbut the actual implementation usesAssistant.create. This patch should be"posthog.temporal.ai.chat_agent.Assistant.create"instead of"posthog.temporal.ai.chat_agent.ChatAgentManager"to properly mock the Assistant creation in the activity.
ee/hogai/agent/executor.py:58 - The docstring should be updated to reflect the new generic nature of the method. It should say "Stream agent workflow updates" instead of just repeating the first line, and the description should clarify that this method can handle different types of agent workflows.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| from posthog.temporal.common.base import PostHogWorkflow | ||
|
|
||
|
|
||
| class AgentBaseWorkflow(PostHogWorkflow): | ||
| """Base temporal workflow for processing agents asynchronously.""" | ||
|
|
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run method should be marked as abstract using the @abstractmethod decorator from the abc module. Additionally, AgentBaseWorkflow should inherit from ABC to properly define it as an abstract base class. This makes the interface contract clearer and prevents instantiation of the base class.
| from posthog.temporal.common.base import PostHogWorkflow | |
| class AgentBaseWorkflow(PostHogWorkflow): | |
| """Base temporal workflow for processing agents asynchronously.""" | |
| from abc import ABC, abstractmethod | |
| from posthog.temporal.common.base import PostHogWorkflow | |
| class AgentBaseWorkflow(PostHogWorkflow, ABC): | |
| """Base temporal workflow for processing agents asynchronously.""" | |
| @abstractmethod |
| if is_deep_research: | ||
| raise NotImplementedError("Deep research is not supported yet") |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for deep research mode was replaced with a NotImplementedError. While this prevents the use of an incomplete feature, the variable is_deep_research is still being extracted from serializer.validated_data on line 140 but is no longer used. Consider removing the unused variable assignment.
801decb to
ed27e9e
Compare
ed27e9e to
0601e49
Compare

Problem
ConversationStreamManageris nowAgentExecutor, a class to run an agent workflow and stream its content, taking as input the workflow type and workflow inputs. This will allow us to run deep research using a different workflow than the base chat agent one.Changes
ConversationStreamManagertoAgentExecutorand moved it fromee/hogai/stream/toee/hogai/agent/AssistantConversationRunnerWorkflowtoChatAgentWorkflowfor better clarityAgentBaseWorkflowto support different types of agent workflowsHow did you test this code?
Changelog: Yes