From 198eb5703273b8898b250d3d47469ae8825d1a03 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Wed, 14 May 2025 08:58:00 -0300 Subject: [PATCH] refactor(agent_service): simplify agent configuration validation and remove unnecessary comments --- src/schemas/schemas.py | 6 +----- src/services/agent_service.py | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/schemas/schemas.py b/src/schemas/schemas.py index 4710e58c..a955fe63 100644 --- a/src/schemas/schemas.py +++ b/src/schemas/schemas.py @@ -221,11 +221,7 @@ class AgentBase(BaseModel): if not isinstance(v["sub_agents"], list): raise ValueError("sub_agents must be a list") - try: - # Convert the dictionary to CrewAIConfig - v = CrewAIConfig(**v) - except Exception as e: - raise ValueError(f"Invalid Crew AI configuration for agent: {str(e)}") + return v return v diff --git a/src/services/agent_service.py b/src/services/agent_service.py index eb6b6ec4..f271ad26 100644 --- a/src/services/agent_service.py +++ b/src/services/agent_service.py @@ -204,6 +204,7 @@ async def create_agent(db: Session, agent: AgentCreate) -> Agent: elif agent.type == "crew_ai": if not isinstance(agent.config, dict): + agent.config = {} raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid configuration: must be an object with tasks", @@ -221,7 +222,6 @@ async def create_agent(db: Session, agent: AgentCreate) -> Agent: detail="Invalid configuration: tasks cannot be empty", ) - # Validar se todos os agent_id nas tasks existem for task in agent.config["tasks"]: if "agent_id" not in task: raise HTTPException( @@ -237,7 +237,6 @@ async def create_agent(db: Session, agent: AgentCreate) -> Agent: detail=f"Agent not found for task: {agent_id}", ) - # Validar sub_agents se existir if "sub_agents" in agent.config and agent.config["sub_agents"]: if not validate_sub_agents(db, agent.config["sub_agents"]): raise HTTPException( @@ -245,7 +244,6 @@ async def create_agent(db: Session, agent: AgentCreate) -> Agent: detail="One or more sub-agents do not exist", ) - # Gerar API key se não existir if "api_key" not in agent.config or not agent.config["api_key"]: agent.config["api_key"] = generate_api_key() @@ -684,7 +682,6 @@ async def update_agent( if "config" not in agent_data: agent_data["config"] = agent_config - # Validar configuração de crew_ai, se aplicável if ("type" in agent_data and agent_data["type"] == "crew_ai") or ( agent.type == "crew_ai" and "config" in agent_data ): @@ -701,7 +698,6 @@ async def update_agent( detail="Invalid configuration: tasks cannot be empty", ) - # Validar se todos os agent_id nas tasks existem for task in config["tasks"]: if "agent_id" not in task: raise HTTPException(