Skip to content

Conversation

@kappa90
Copy link
Contributor

@kappa90 kappa90 commented Nov 17, 2025

Problem

ConversationStreamManager is now AgentExecutor, 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

  • Renamed ConversationStreamManager to AgentExecutor and moved it from ee/hogai/stream/ to ee/hogai/agent/
  • Renamed AssistantConversationRunnerWorkflow to ChatAgentWorkflow for better clarity
  • Created a new base class AgentBaseWorkflow to support different types of agent workflows
  • Moved Redis stream implementation to the agent package
  • Made timeout and max length parameters configurable in the executor

How did you test this code?

  • Migrated all existing tests to the new structure

Changelog: Yes

Copy link
Contributor Author

kappa90 commented Nov 17, 2025

@kappa90 kappa90 requested a review from a team November 17, 2025 12:57
@kappa90 kappa90 marked this pull request as ready for review November 17, 2025 12:57
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch 3 times, most recently from 047f7db to 6427e90 Compare November 17, 2025 15:06
Copy link
Contributor

@sortafreel sortafreel left a 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.

@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch from 6427e90 to 7424d72 Compare November 17, 2025 15:24
Copy link
Contributor

@skoob13 skoob13 left a 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.

@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch 3 times, most recently from 1b6baaf to affac80 Compare November 18, 2025 17:19
@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch from affac80 to 786c1dd Compare November 18, 2025 18:17
@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch from 786c1dd to 576e70c Compare November 19, 2025 15:38
Base automatically changed from feat/agent-modes to master November 19, 2025 16:28
Copilot AI review requested due to automatic review settings November 19, 2025 20:02
@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch from 576e70c to 801decb Compare November 19, 2025 20:02
Copy link
Contributor

Copilot AI left a 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 AgentBaseWorkflow as a base class for different agent workflow types
  • Refactored ConversationStreamManager to AgentExecutor with configurable timeout and max_length parameters
  • Moved Redis stream implementation from ee/hogai/stream/ to ee/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 ChatAgentManager but the actual implementation uses Assistant.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 ChatAgentManager but the actual implementation uses Assistant.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_workflow is 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 like self.stream_workflow(). However, since stream_conversation is 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 ChatAgentManager but the actual implementation uses Assistant.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 ChatAgentManager but the actual implementation uses Assistant.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.

Comment on lines +2 to +8

from posthog.temporal.common.base import PostHogWorkflow


class AgentBaseWorkflow(PostHogWorkflow):
"""Base temporal workflow for processing agents asynchronously."""

Copy link

Copilot AI Nov 19, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +141 to +140
if is_deep_research:
raise NotImplementedError("Deep research is not supported yet")
Copy link

Copilot AI Nov 19, 2025

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.

Copilot uses AI. Check for mistakes.
@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch from 801decb to ed27e9e Compare November 19, 2025 20:25
@kappa90 kappa90 force-pushed the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch from ed27e9e to 0601e49 Compare November 20, 2025 15:19
@kappa90 kappa90 merged commit a39feb2 into master Nov 20, 2025
175 checks passed
@kappa90 kappa90 deleted the 11-17-refactor_ph-ai_conversation_stream_manager_to_agent_executor branch November 20, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants