Skip to content

Commit 198eb57

Browse files
author
Davidson Gomes
committed
refactor(agent_service): simplify agent configuration validation and remove unnecessary comments
1 parent 9ab001c commit 198eb57

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

src/schemas/schemas.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,7 @@ def validate_config(cls, v, values):
221221
if not isinstance(v["sub_agents"], list):
222222
raise ValueError("sub_agents must be a list")
223223

224-
try:
225-
# Convert the dictionary to CrewAIConfig
226-
v = CrewAIConfig(**v)
227-
except Exception as e:
228-
raise ValueError(f"Invalid Crew AI configuration for agent: {str(e)}")
224+
return v
229225

230226
return v
231227

src/services/agent_service.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ async def create_agent(db: Session, agent: AgentCreate) -> Agent:
204204

205205
elif agent.type == "crew_ai":
206206
if not isinstance(agent.config, dict):
207+
agent.config = {}
207208
raise HTTPException(
208209
status_code=status.HTTP_400_BAD_REQUEST,
209210
detail="Invalid configuration: must be an object with tasks",
@@ -221,7 +222,6 @@ async def create_agent(db: Session, agent: AgentCreate) -> Agent:
221222
detail="Invalid configuration: tasks cannot be empty",
222223
)
223224

224-
# Validar se todos os agent_id nas tasks existem
225225
for task in agent.config["tasks"]:
226226
if "agent_id" not in task:
227227
raise HTTPException(
@@ -237,15 +237,13 @@ async def create_agent(db: Session, agent: AgentCreate) -> Agent:
237237
detail=f"Agent not found for task: {agent_id}",
238238
)
239239

240-
# Validar sub_agents se existir
241240
if "sub_agents" in agent.config and agent.config["sub_agents"]:
242241
if not validate_sub_agents(db, agent.config["sub_agents"]):
243242
raise HTTPException(
244243
status_code=status.HTTP_400_BAD_REQUEST,
245244
detail="One or more sub-agents do not exist",
246245
)
247246

248-
# Gerar API key se não existir
249247
if "api_key" not in agent.config or not agent.config["api_key"]:
250248
agent.config["api_key"] = generate_api_key()
251249

@@ -684,7 +682,6 @@ async def update_agent(
684682
if "config" not in agent_data:
685683
agent_data["config"] = agent_config
686684

687-
# Validar configuração de crew_ai, se aplicável
688685
if ("type" in agent_data and agent_data["type"] == "crew_ai") or (
689686
agent.type == "crew_ai" and "config" in agent_data
690687
):
@@ -701,7 +698,6 @@ async def update_agent(
701698
detail="Invalid configuration: tasks cannot be empty",
702699
)
703700

704-
# Validar se todos os agent_id nas tasks existem
705701
for task in config["tasks"]:
706702
if "agent_id" not in task:
707703
raise HTTPException(

0 commit comments

Comments
 (0)