validateToolChoice static method
Validate tool choice against available tools
toolChoice
- The tool choice to validate
availableTools
- List of available tools
Returns true if valid, throws ToolValidationError if invalid
Implementation
static bool validateToolChoice(
ToolChoice toolChoice, List<Tool> availableTools) {
switch (toolChoice) {
case SpecificToolChoice(toolName: final name):
final toolExists =
availableTools.any((tool) => tool.function.name == name);
if (!toolExists) {
throw ToolValidationError(
'Specified tool "$name" not found in available tools',
toolName: name,
);
}
break;
case AutoToolChoice():
case AnyToolChoice():
case NoneToolChoice():
// These are always valid
break;
}
return true;
}