execute method

Future<ToolCallOutput> execute(
  1. ToolContext context,
  2. String name,
  3. ToolInput input
)

Implementation

Future<ToolCallOutput> execute(ToolContext context, String name, ToolInput input) async {
  final tool = getTool(name);
  if (tool is FunctionTool) {
    if (input is! ToolContentInput) {
      throw Exception("tool '$name' does not accept streamed input");
    }
    final arguments = _decodeFunctionToolArguments(toolName: name, input: input.content);
    final response = await tool.execute(context, arguments);
    return ToolContentOutput(response);
  }
  if (tool is ContentTool) {
    return await tool.execute(context, input);
  }
  throw Exception("tool '$name' has unsupported type");
}