getToolsWithPrefix method
Returns getTools with an optional toolNamePrefix applied.
Implementation
Future<List<BaseTool>> getToolsWithPrefix({
ReadonlyContext? readonlyContext,
}) async {
final String? invocationId = readonlyContext?.invocationId;
if (_useInvocationCache &&
_hasCachedInvocationTools &&
_cachedPrefixedTools != null &&
_cachedInvocationId == invocationId) {
return _cachedPrefixedTools!;
}
final List<BaseTool> tools = await getTools(
readonlyContext: readonlyContext,
);
if (toolNamePrefix == null || toolNamePrefix!.isEmpty) {
_hasCachedInvocationTools = true;
_cachedInvocationId = invocationId;
_cachedPrefixedTools = tools;
return tools;
}
final String prefix = toolNamePrefix!;
final List<BaseTool> prefixedTools = tools
.map((BaseTool tool) => _PrefixedTool(delegate: tool, prefix: prefix))
.toList();
_hasCachedInvocationTools = true;
_cachedInvocationId = invocationId;
_cachedPrefixedTools = prefixedTools;
return prefixedTools;
}