diff --git a/dbgpt/agent/core/action/base.py b/dbgpt/agent/core/action/base.py index 9061efdfa..79929999e 100644 --- a/dbgpt/agent/core/action/base.py +++ b/dbgpt/agent/core/action/base.py @@ -72,7 +72,7 @@ def from_dict( """Convert dict to ActionOutput object.""" if not param: return None - return cls.parse_obj(param) + return cls.model_validate(param) def to_dict(self) -> Dict[str, Any]: """Convert the object to a dictionary.""" @@ -181,10 +181,12 @@ def _input_convert(self, ai_message: str, cls: Type[T]) -> T: if get_origin(cls) == list: inner_type = get_args(cls)[0] typed_cls = cast(Type[BaseModel], inner_type) - return [typed_cls.parse_obj(item) for item in json_result] # type: ignore + return [ + typed_cls.model_validate(item) for item in json_result + ] # type: ignore else: typed_cls = cast(Type[BaseModel], cls) - return typed_cls.parse_obj(json_result) + return typed_cls.model_validate(json_result) @abstractmethod async def run( diff --git a/dbgpt/agent/core/memory/gpts/default_gpts_memory.py b/dbgpt/agent/core/memory/gpts/default_gpts_memory.py index f636df634..b95dbc11b 100644 --- a/dbgpt/agent/core/memory/gpts/default_gpts_memory.py +++ b/dbgpt/agent/core/memory/gpts/default_gpts_memory.py @@ -23,7 +23,7 @@ def batch_save(self, plans: list[GptsPlan]): def get_by_conv_id(self, conv_id: str) -> List[GptsPlan]: """Get plans by conv_id.""" - result = self.df.query(f"conv_id==@conv_id") # noqa: F541 + result = self.df.query("conv_id==@conv_id") # noqa: F541 plans = [] for row in result.itertuples(index=False, name=None): row_dict = dict(zip(self.df.columns, row)) @@ -36,7 +36,7 @@ def get_by_conv_id_and_num( """Get plans by conv_id and task number.""" task_nums_int = [int(num) for num in task_nums] # noqa:F841 result = self.df.query( # noqa - f"conv_id==@conv_id and sub_task_num in @task_nums_int" # noqa + "conv_id==@conv_id and sub_task_num in @task_nums_int" # noqa ) plans = [] for row in result.itertuples(index=False, name=None): @@ -47,7 +47,7 @@ def get_by_conv_id_and_num( def get_todo_plans(self, conv_id: str) -> List[GptsPlan]: """Get unfinished planning steps.""" todo_states = [Status.TODO.value, Status.RETRYING.value] # noqa: F841 - result = self.df.query(f"conv_id==@conv_id and state in @todo_states") # noqa + result = self.df.query("conv_id==@conv_id and state in @todo_states") # noqa plans = [] for row in result.itertuples(index=False, name=None): row_dict = dict(zip(self.df.columns, row)) @@ -105,7 +105,7 @@ def append(self, message: GptsMessage): def get_by_agent(self, conv_id: str, agent: str) -> Optional[List[GptsMessage]]: """Get all messages sent or received by the agent in the conversation.""" result = self.df.query( - f"conv_id==@conv_id and (sender==@agent or receiver==@agent)" # noqa: F541 + "conv_id==@conv_id and (sender==@agent or receiver==@agent)" # noqa: F541 ) messages = [] for row in result.itertuples(index=False, name=None): @@ -123,11 +123,11 @@ def get_between_agents( """Get all messages between two agents in the conversation.""" if current_goal: result = self.df.query( - f"conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1)) and current_goal==@current_goal" # noqa + "conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1)) and current_goal==@current_goal" # noqa ) else: result = self.df.query( - f"conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1))" # noqa + "conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1))" # noqa ) messages = [] for row in result.itertuples(index=False, name=None): @@ -137,7 +137,7 @@ def get_between_agents( def get_by_conv_id(self, conv_id: str) -> List[GptsMessage]: """Get all messages in the conversation.""" - result = self.df.query(f"conv_id==@conv_id") # noqa: F541 + result = self.df.query("conv_id==@conv_id") # noqa: F541 messages = [] for row in result.itertuples(index=False, name=None): row_dict = dict(zip(self.df.columns, row)) diff --git a/dbgpt/agent/core/plan/awel/agent_operator_resource.py b/dbgpt/agent/core/plan/awel/agent_operator_resource.py index 9f32b73c9..226274f8c 100644 --- a/dbgpt/agent/core/plan/awel/agent_operator_resource.py +++ b/dbgpt/agent/core/plan/awel/agent_operator_resource.py @@ -1,4 +1,5 @@ """Agent operator define.""" + import json from typing import Any, Dict, List, Optional @@ -146,6 +147,7 @@ class AWELAgentKnowledgeResource(AgentResource): """AWELAgentKnowledgeResource.""" @model_validator(mode="before") + @classmethod def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]: """Pre fill the agent ResourceType.""" value = values.pop("agent_resource_value") @@ -191,6 +193,7 @@ class AgentPrompt(BaseModel): code: str @model_validator(mode="before") + @classmethod def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]: """Pre fill the agent ResourceType.""" code = values.pop("agent_prompt_code") @@ -243,6 +246,7 @@ class AWELAgentConfig(LLMConfig): """AWEL Agent Config.""" @model_validator(mode="before") + @classmethod def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]: """Prefill the agent ResourceType.""" strategy_context = values.pop("strategy_context")