File size: 1,578 Bytes
595d60e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from ..schemas.agent_spec import AgentSpec
from ..schemas.conversation import ValidationError, ValidationResult

class ToolValidator:
    def validate(self, spec: AgentSpec) -> ValidationResult:
        errors = []
        tool_names = {t.name for t in spec.tools}
        
        for step in spec.steps:
            if step.action in ("tool_call", "call_tool"):
                tool_name = step.input.get("tool_name") or step.input.get("tool")
                if not tool_name:
                    errors.append(ValidationError(
                        code="INVALID_TOOL_CALL",
                        message=f"Step '{step.id}' of action '{step.action}' must specify 'tool_name' or 'tool' in its input config",
                        path=f"steps.{step.id}.input"
                    ))
                elif tool_name not in tool_names:
                    errors.append(ValidationError(
                        code="MISSING_TOOL",
                        message=f"Step '{step.id}' references tool '{tool_name}' which is not defined in the tools list",
                        path=f"steps.{step.id}.input.tool_name"
                    ))
        
        # Check for duplicate tool names
        all_tool_names = [t.name for t in spec.tools]
        if len(all_tool_names) != len(set(all_tool_names)):
            errors.append(ValidationError(
                code="DUPLICATE_TOOL",
                message="Duplicate tool names found in tools list",
                path="tools"
            ))

        return ValidationResult(valid=len(errors) == 0, errors=errors)