AgentLogEvent类缺少parallel_id属性导致并行执行错误 #8867

Closed
opened 2026-02-21 18:28:15 -05:00 by yindo · 2 comments
Owner

Originally created by @alleneee on GitHub (Mar 2, 2025).

问题描述

在使用Dify的工作流进行并行执行时,系统报错:'AgentLogEvent' object has no attribute 'parallel_id'。这表明AgentLogEvent类缺少parallel_id属性,导致在处理并行节点时出现错误。

复现步骤

  1. 使用Docker部署Dify应用
  2. 创建一个包含并行执行节点(parallel execution nodes)的工作流
  3. 运行该工作流
  4. 当工作流执行到并行节点时,系统报错:'AgentLogEvent' object has no attribute 'parallel_id'

代码分析

通过分析代码发现,在api/core/workflow/graph_engine/entities/event.py文件中,AgentLogEvent类的定义如下:

class AgentLogEvent(BaseEvent):
    def __init__(self, agent_chat_message: AgentChatMessage) -> None:
        super().__init__()
        self.agent_chat_message = agent_chat_message

而其他类如BaseParallelBranchEventBaseIterationEvent则包含parallel_id属性:

class BaseParallelBranchEvent(BaseEvent):
    def __init__(self, parallel_id: str, parallel_start_node_id: str) -> None:
        super().__init__()
        self.parallel_id = parallel_id
        self.parallel_start_node_id = parallel_start_node_id

WorkflowBasedAppRunner._handle_event方法中处理事件时,系统尝试访问AgentLogEvent对象的parallel_id属性,但该属性不存在,从而导致错误。

建议修复

  1. AgentLogEvent类中添加parallel_id属性,可能也需要添加parallel_start_node_id属性:
class AgentLogEvent(BaseEvent):
    def __init__(self, agent_chat_message: AgentChatMessage, parallel_id: str = None, parallel_start_node_id: str = None) -> None:
        super().__init__()
        self.agent_chat_message = agent_chat_message
        self.parallel_id = parallel_id
        self.parallel_start_node_id = parallel_start_node_id
  1. 同时,需要检查api/core/app/entities/queue_entities.py中的QueueAgentLogEvent类,确保也添加了相应的属性:
class QueueAgentLogEvent(QueueEvent):
    def __init__(self, end_user_id: str, conversation_id: str, agent_chat_message: AgentChatMessage, 
                 parallel_id: str = None, parallel_start_node_id: str = None, task_id: str = None) -> None:
        super().__init__(end_user_id, conversation_id, task_id)
        self.agent_chat_message = agent_chat_message
        self.parallel_id = parallel_id
        self.parallel_start_node_id = parallel_start_node_id
  1. 确保在事件处理逻辑中正确传递parallel_id参数。

环境信息

  • 操作系统:macOS 24.3.0
  • 部署方式:Docker
  • Dify版本:最新版

感谢您的关注和解决这个问题!

Originally created by @alleneee on GitHub (Mar 2, 2025). ## 问题描述 在使用Dify的工作流进行并行执行时,系统报错:`'AgentLogEvent' object has no attribute 'parallel_id'`。这表明`AgentLogEvent`类缺少`parallel_id`属性,导致在处理并行节点时出现错误。 ## 复现步骤 1. 使用Docker部署Dify应用 2. 创建一个包含并行执行节点(parallel execution nodes)的工作流 3. 运行该工作流 4. 当工作流执行到并行节点时,系统报错:`'AgentLogEvent' object has no attribute 'parallel_id'` ## 代码分析 通过分析代码发现,在`api/core/workflow/graph_engine/entities/event.py`文件中,`AgentLogEvent`类的定义如下: ```python class AgentLogEvent(BaseEvent): def __init__(self, agent_chat_message: AgentChatMessage) -> None: super().__init__() self.agent_chat_message = agent_chat_message ``` 而其他类如`BaseParallelBranchEvent`和`BaseIterationEvent`则包含`parallel_id`属性: ```python class BaseParallelBranchEvent(BaseEvent): def __init__(self, parallel_id: str, parallel_start_node_id: str) -> None: super().__init__() self.parallel_id = parallel_id self.parallel_start_node_id = parallel_start_node_id ``` 在`WorkflowBasedAppRunner._handle_event`方法中处理事件时,系统尝试访问`AgentLogEvent`对象的`parallel_id`属性,但该属性不存在,从而导致错误。 ## 建议修复 1. 在`AgentLogEvent`类中添加`parallel_id`属性,可能也需要添加`parallel_start_node_id`属性: ```python class AgentLogEvent(BaseEvent): def __init__(self, agent_chat_message: AgentChatMessage, parallel_id: str = None, parallel_start_node_id: str = None) -> None: super().__init__() self.agent_chat_message = agent_chat_message self.parallel_id = parallel_id self.parallel_start_node_id = parallel_start_node_id ``` 2. 同时,需要检查`api/core/app/entities/queue_entities.py`中的`QueueAgentLogEvent`类,确保也添加了相应的属性: ```python class QueueAgentLogEvent(QueueEvent): def __init__(self, end_user_id: str, conversation_id: str, agent_chat_message: AgentChatMessage, parallel_id: str = None, parallel_start_node_id: str = None, task_id: str = None) -> None: super().__init__(end_user_id, conversation_id, task_id) self.agent_chat_message = agent_chat_message self.parallel_id = parallel_id self.parallel_start_node_id = parallel_start_node_id ``` 3. 确保在事件处理逻辑中正确传递`parallel_id`参数。 ## 环境信息 - 操作系统:macOS 24.3.0 - 部署方式:Docker - Dify版本:最新版 感谢您的关注和解决这个问题!
yindo added the 🐞 bug🌊 feat:workflow labels 2026-02-21 18:28:15 -05:00
yindo closed this issue 2026-02-21 18:28:15 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 2, 2025):

Hey there, @alleneee! I'm here to help you with any bugs, questions, or contributions you have on Dify. Let's get this issue sorted out together.

要解决AgentLogEvent类缺少parallel_id属性导致的并行执行错误,可以按照以下步骤进行修改:

  1. AgentLogEvent类中添加parallel_id属性

    api/core/workflow/graph_engine/entities/event.py文件中,修改AgentLogEvent类以包含parallel_id属性:

    class AgentLogEvent(BaseAgentEvent):
        id: str = Field(..., description="id")
        label: str = Field(..., description="label")
        node_execution_id: str = Field(..., description="node execution id")
        parent_id: str | None = Field(..., description="parent id")
        error: str | None = Field(..., description="error")
        status: str = Field(..., description="status")
        data: Mapping[str, Any] = Field(..., description="data")
        metadata: Optional[Mapping[str, Any]] = Field(default=None, description="metadata")
        parallel_id: Optional[str] = None  # 添加此行
    
  2. QueueAgentLogEvent类中添加parallel_id属性

    api/core/app/entities/queue_entities.py文件中,确保QueueAgentLogEvent类也包含parallel_id属性:

    class QueueAgentLogEvent(QueueEvent):
        def __init__(self, end_user_id: str, conversation_id: str, agent_chat_message: AgentChatMessage, 
                     parallel_id: str = None, parallel_start_node_id: str = None, task_id: str = None) -> None:
            super().__init__(end_user_id, conversation_id, task_id)
            self.agent_chat_message = agent_chat_message
            self.parallel_id = parallel_id
            self.parallel_start_node_id = parallel_start_node_id
    
  3. 确保在事件处理逻辑中正确传递parallel_id参数

    WorkflowBasedAppRunner._handle_event方法中,确保在创建QueueAgentLogEvent对象时传递parallel_id参数。

通过这些修改,可以解决AgentLogEvent类缺少parallel_id属性导致的并行执行错误[1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 2, 2025): <!-- Greeting --> Hey there, @alleneee! I'm here to help you with any bugs, questions, or contributions you have on Dify. Let's get this issue sorted out together. <!-- Answer --> 要解决`AgentLogEvent`类缺少`parallel_id`属性导致的并行执行错误,可以按照以下步骤进行修改: 1. **在`AgentLogEvent`类中添加`parallel_id`属性**: 在`api/core/workflow/graph_engine/entities/event.py`文件中,修改`AgentLogEvent`类以包含`parallel_id`属性: ```python class AgentLogEvent(BaseAgentEvent): id: str = Field(..., description="id") label: str = Field(..., description="label") node_execution_id: str = Field(..., description="node execution id") parent_id: str | None = Field(..., description="parent id") error: str | None = Field(..., description="error") status: str = Field(..., description="status") data: Mapping[str, Any] = Field(..., description="data") metadata: Optional[Mapping[str, Any]] = Field(default=None, description="metadata") parallel_id: Optional[str] = None # 添加此行 ``` 2. **在`QueueAgentLogEvent`类中添加`parallel_id`属性**: 在`api/core/app/entities/queue_entities.py`文件中,确保`QueueAgentLogEvent`类也包含`parallel_id`属性: ```python class QueueAgentLogEvent(QueueEvent): def __init__(self, end_user_id: str, conversation_id: str, agent_chat_message: AgentChatMessage, parallel_id: str = None, parallel_start_node_id: str = None, task_id: str = None) -> None: super().__init__(end_user_id, conversation_id, task_id) self.agent_chat_message = agent_chat_message self.parallel_id = parallel_id self.parallel_start_node_id = parallel_start_node_id ``` 3. **确保在事件处理逻辑中正确传递`parallel_id`参数**: 在`WorkflowBasedAppRunner._handle_event`方法中,确保在创建`QueueAgentLogEvent`对象时传递`parallel_id`参数。 通过这些修改,可以解决`AgentLogEvent`类缺少`parallel_id`属性导致的并行执行错误<sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/graph_engine/entities/event.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/app/entities/queue_entities.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/035a532e-33c2-4918-bb93-9177407797df?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/035a532e-33c2-4918-bb93-9177407797df?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/035a532e-33c2-4918-bb93-9177407797df?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/035a532e-33c2-4918-bb93-9177407797df?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/035a532e-33c2-4918-bb93-9177407797df?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/035a532e-33c2-4918-bb93-9177407797df?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/035a532e-33c2-4918-bb93-9177407797df?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Mar 2, 2025):

Close due to #1542

@crazywoola commented on GitHub (Mar 2, 2025): Close due to #1542
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8867