From 82e31403572b35a565ce2bcc64181e6183529117 Mon Sep 17 00:00:00 2001 From: liangxinbing <1580466765@qq.com> Date: Fri, 21 Mar 2025 17:37:16 +0800 Subject: [PATCH] update structure of flow --- app/flow/base.py | 34 ---------------------------------- app/flow/flow_factory.py | 7 ++++++- app/flow/planning.py | 32 +++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/app/flow/base.py b/app/flow/base.py index 13066ce..dc57b39 100644 --- a/app/flow/base.py +++ b/app/flow/base.py @@ -1,5 +1,4 @@ from abc import ABC, abstractmethod -from enum import Enum from typing import Dict, List, Optional, Union from pydantic import BaseModel @@ -7,10 +6,6 @@ from pydantic import BaseModel from app.agent.base import BaseAgent -class FlowType(str, Enum): - PLANNING = "planning" - - class BaseFlow(BaseModel, ABC): """Base class for execution flows supporting multiple agents""" @@ -60,32 +55,3 @@ class BaseFlow(BaseModel, ABC): @abstractmethod async def execute(self, input_text: str) -> str: """Execute the flow with given input""" - - -class PlanStepStatus(str, Enum): - """Enum class defining possible statuses of a plan step""" - - NOT_STARTED = "not_started" - IN_PROGRESS = "in_progress" - COMPLETED = "completed" - BLOCKED = "blocked" - - @classmethod - def get_all_statuses(cls) -> list[str]: - """Return a list of all possible step status values""" - return [status.value for status in cls] - - @classmethod - def get_active_statuses(cls) -> list[str]: - """Return a list of values representing active statuses (not started or in progress)""" - return [cls.NOT_STARTED.value, cls.IN_PROGRESS.value] - - @classmethod - def get_status_marks(cls) -> Dict[str, str]: - """Return a mapping of statuses to their marker symbols""" - return { - cls.COMPLETED.value: "[✓]", - cls.IN_PROGRESS.value: "[→]", - cls.BLOCKED.value: "[!]", - cls.NOT_STARTED.value: "[ ]", - } diff --git a/app/flow/flow_factory.py b/app/flow/flow_factory.py index 7272282..2936940 100644 --- a/app/flow/flow_factory.py +++ b/app/flow/flow_factory.py @@ -1,10 +1,15 @@ +from enum import Enum from typing import Dict, List, Union from app.agent.base import BaseAgent -from app.flow.base import BaseFlow, FlowType +from app.flow.base import BaseFlow from app.flow.planning import PlanningFlow +class FlowType(str, Enum): + PLANNING = "planning" + + class FlowFactory: """Factory for creating different types of flows with support for multiple agents""" diff --git a/app/flow/planning.py b/app/flow/planning.py index 55ec5c9..6ba5aae 100644 --- a/app/flow/planning.py +++ b/app/flow/planning.py @@ -1,17 +1,47 @@ import json import time +from enum import Enum from typing import Dict, List, Optional, Union from pydantic import Field from app.agent.base import BaseAgent -from app.flow.base import BaseFlow, PlanStepStatus +from app.flow.base import BaseFlow from app.llm import LLM from app.logger import logger from app.schema import AgentState, Message, ToolChoice from app.tool import PlanningTool +class PlanStepStatus(str, Enum): + """Enum class defining possible statuses of a plan step""" + + NOT_STARTED = "not_started" + IN_PROGRESS = "in_progress" + COMPLETED = "completed" + BLOCKED = "blocked" + + @classmethod + def get_all_statuses(cls) -> list[str]: + """Return a list of all possible step status values""" + return [status.value for status in cls] + + @classmethod + def get_active_statuses(cls) -> list[str]: + """Return a list of values representing active statuses (not started or in progress)""" + return [cls.NOT_STARTED.value, cls.IN_PROGRESS.value] + + @classmethod + def get_status_marks(cls) -> Dict[str, str]: + """Return a mapping of statuses to their marker symbols""" + return { + cls.COMPLETED.value: "[✓]", + cls.IN_PROGRESS.value: "[→]", + cls.BLOCKED.value: "[!]", + cls.NOT_STARTED.value: "[ ]", + } + + class PlanningFlow(BaseFlow): """A flow that manages planning and execution of tasks using agents."""